siglab-py 0.3.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of siglab-py might be problematic. Click here for more details.
- {siglab_py-0.3.0 → siglab_py-0.3.1}/PKG-INFO +1 -1
- {siglab_py-0.3.0 → siglab_py-0.3.1}/pyproject.toml +1 -1
- {siglab_py-0.3.0 → siglab_py-0.3.1}/setup.cfg +1 -1
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/ordergateway/gateway.py +11 -10
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/unit/analytic_util_tests.py +1 -1
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/unit/trading_util_tests.py +6 -6
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/analytic_util.py +8 -1
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/trading_util.py +4 -4
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py.egg-info/PKG-INFO +1 -1
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/constants.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/exchanges/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/exchanges/any_exchange.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/exchanges/futubull.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/aggregated_orderbook_provider.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/candles_provider.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/candles_ta_provider.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/ccxt_candles_ta_to_csv.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/deribit_options_expiry_provider.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/futu_candles_ta_to_csv.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/orderbooks_provider.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/test_provider.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/ordergateway/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/ordergateway/client.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/ordergateway/encrypt_keys_util.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/ordergateway/test_ordergateway.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/integration/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/integration/market_data_util_tests.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/unit/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/tests/unit/market_data_util_tests.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/__init__.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/aws_util.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/market_data_util.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/notification_util.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/retry_util.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/util/slack_notification_util.py +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py.egg-info/SOURCES.txt +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py.egg-info/dependency_links.txt +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py.egg-info/requires.txt +0 -0
- {siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "siglab_py"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.1"
|
|
8
8
|
description = "Market data fetches, TA calculations and generic order gateway."
|
|
9
9
|
authors = [{name = "r0bbarh00d", email = "r0bbarh00d@gmail.com"}]
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -502,14 +502,15 @@ async def execute_one_position(
|
|
|
502
502
|
slices : List[Order] = position.to_slices()
|
|
503
503
|
|
|
504
504
|
# Residual handling in last slice
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
505
|
+
if len(slices)>1:
|
|
506
|
+
last_slice = slices[-1]
|
|
507
|
+
last_slice_rounded_amount_in_base_ccy = exchange.amount_to_precision(position.ticker, last_slice.amount/multiplier) # After divided by multiplier, rounded_slice_amount_in_base_ccy in number of contracts actually (Not in base ccy).
|
|
508
|
+
last_slice_rounded_amount_in_base_ccy = float(last_slice_rounded_amount_in_base_ccy) if last_slice_rounded_amount_in_base_ccy else 0
|
|
509
|
+
if last_slice_rounded_amount_in_base_ccy<=min_amount:
|
|
510
|
+
slices.pop()
|
|
511
|
+
slices[-1].amount += last_slice.amount
|
|
511
512
|
|
|
512
|
-
|
|
513
|
+
log(f"{position.ticker} Last slice residual smaller than min_amount. Amount is added to prev slice instead. last_slice_amount: {last_slice.amount/multiplier}, last_slice_rounded_amount: {last_slice_rounded_amount_in_base_ccy}")
|
|
513
514
|
|
|
514
515
|
i = 0
|
|
515
516
|
for slice in slices:
|
|
@@ -796,10 +797,10 @@ async def execute_one_position(
|
|
|
796
797
|
dispatch_notification(title=f"{param['current_filename']} {param['gateway_id']} execute_one_position done. {position.ticker} {position.side} {position.amount}", message=notification_summary, footer=param['notification']['footer'], params=notification_params, log_level=LogLevel.CRITICAL, logger=logger)
|
|
797
798
|
|
|
798
799
|
except Exception as position_execution_err:
|
|
799
|
-
err_msg = f"Execution failed: {position_execution_err} {str(sys.exc_info()[0])} {str(sys.exc_info()[1])} {traceback.format_exc()}"
|
|
800
|
-
log(
|
|
800
|
+
err_msg = f"{position.ticker} Execution failed: {position_execution_err} {str(sys.exc_info()[0])} {str(sys.exc_info()[1])} {traceback.format_exc()}"
|
|
801
|
+
log(err_msg)
|
|
801
802
|
|
|
802
|
-
dispatch_notification(title=f"{param['current_filename']} {param['gateway_id']}
|
|
803
|
+
dispatch_notification(title=f"{param['current_filename']} {param['gateway_id']} {position.ticker} execute_one_position failed!!!", message=err_msg, footer=param['notification']['footer'], params=notification_params, log_level=LogLevel.ERROR, logger=logger) # type: ignore
|
|
803
804
|
|
|
804
805
|
position.done = False
|
|
805
806
|
position.execution_err = err_msg
|
|
@@ -51,7 +51,7 @@ class AnalyticUtilTests(unittest.TestCase):
|
|
|
51
51
|
'sma_short_periods', 'sma_long_periods', 'ema_short_periods', 'ema_long_periods', 'ema_close',
|
|
52
52
|
'std', 'std_percent',
|
|
53
53
|
'candle_height_percent', 'candle_height_percent_rounded',
|
|
54
|
-
'log_return', '
|
|
54
|
+
'log_return', 'interval_hist_vol', 'annualized_hist_vol',
|
|
55
55
|
'chop_against_ema',
|
|
56
56
|
'ema_volume_short_periods', 'ema_volume_long_periods',
|
|
57
57
|
'max_short_periods', 'max_long_periods', 'idmax_short_periods', 'idmax_long_periods', 'min_short_periods', 'min_long_periods', 'idmin_short_periods', 'idmin_long_periods',
|
|
@@ -12,7 +12,7 @@ class TradingUtilTests(unittest.TestCase):
|
|
|
12
12
|
tp_min_percent : float = 1.5
|
|
13
13
|
tp_max_percent : float = 2.5
|
|
14
14
|
sl_percent_trailing : float = 50 # Trailing stop loss in percent
|
|
15
|
-
|
|
15
|
+
default_effective_tp_percent_trailing : float = 50
|
|
16
16
|
|
|
17
17
|
pnl_percent_notional : float = 0.5 # Trade's current pnl in percent.
|
|
18
18
|
|
|
@@ -21,7 +21,7 @@ class TradingUtilTests(unittest.TestCase):
|
|
|
21
21
|
tp_max_percent = tp_max_percent,
|
|
22
22
|
sl_percent_trailing = sl_percent_trailing,
|
|
23
23
|
pnl_percent_notional = pnl_percent_notional,
|
|
24
|
-
|
|
24
|
+
default_effective_tp_percent_trailing = default_effective_tp_percent_trailing
|
|
25
25
|
)
|
|
26
26
|
assert(effective_tp_trailing_percent==50) # Generous trailing SL when trading starting out and pnl small.
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ class TradingUtilTests(unittest.TestCase):
|
|
|
29
29
|
tp_min_percent : float = 1.5
|
|
30
30
|
tp_max_percent : float = 2.5
|
|
31
31
|
sl_percent_trailing : float = 50 # Trailing stop loss in percent
|
|
32
|
-
|
|
32
|
+
default_effective_tp_percent_trailing : float = 50
|
|
33
33
|
|
|
34
34
|
pnl_percent_notional : float = 2 # Trade's current pnl in percent.
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ class TradingUtilTests(unittest.TestCase):
|
|
|
38
38
|
tp_max_percent = tp_max_percent,
|
|
39
39
|
sl_percent_trailing = sl_percent_trailing,
|
|
40
40
|
pnl_percent_notional = pnl_percent_notional,
|
|
41
|
-
|
|
41
|
+
default_effective_tp_percent_trailing = default_effective_tp_percent_trailing
|
|
42
42
|
)
|
|
43
43
|
assert(effective_tp_trailing_percent==25) # Intermediate trailing SL
|
|
44
44
|
|
|
@@ -46,7 +46,7 @@ class TradingUtilTests(unittest.TestCase):
|
|
|
46
46
|
tp_min_percent : float = 1.5
|
|
47
47
|
tp_max_percent : float = 2.5
|
|
48
48
|
sl_percent_trailing : float = 50 # Trailing stop loss in percent
|
|
49
|
-
|
|
49
|
+
default_effective_tp_percent_trailing : float = 50
|
|
50
50
|
|
|
51
51
|
pnl_percent_notional : float = 2.5 # Trade's current pnl in percent.
|
|
52
52
|
|
|
@@ -55,6 +55,6 @@ class TradingUtilTests(unittest.TestCase):
|
|
|
55
55
|
tp_max_percent = tp_max_percent,
|
|
56
56
|
sl_percent_trailing = sl_percent_trailing,
|
|
57
57
|
pnl_percent_notional = pnl_percent_notional,
|
|
58
|
-
|
|
58
|
+
default_effective_tp_percent_trailing = default_effective_tp_percent_trailing
|
|
59
59
|
)
|
|
60
60
|
assert(effective_tp_trailing_percent==0) # Most tight trailing SL
|
|
@@ -118,7 +118,14 @@ def compute_candles_stats(
|
|
|
118
118
|
)
|
|
119
119
|
'''
|
|
120
120
|
pd_candles['log_return'] = np.log(pd_candles['close'] / pd_candles['close'].shift(1))
|
|
121
|
-
pd_candles['
|
|
121
|
+
pd_candles['interval_hist_vol'] = pd_candles['log_return'].rolling(window=sliding_window_how_many_candles).std()
|
|
122
|
+
|
|
123
|
+
time_gap_sec = int(pd_candles['timestamp_ms'].iloc[1] - pd_candles['timestamp_ms'].iloc[0])/1000
|
|
124
|
+
seconds_in_year = 365 * 24 * 60 * 60
|
|
125
|
+
candles_per_year = seconds_in_year / time_gap_sec
|
|
126
|
+
annualization_factor = np.sqrt(candles_per_year)
|
|
127
|
+
pd_candles['annualized_hist_vol'] = pd_candles['interval_hist_vol'] * annualization_factor
|
|
128
|
+
|
|
122
129
|
|
|
123
130
|
pd_candles['chop_against_ema'] = (
|
|
124
131
|
(~pd_candles['is_green'] & (pd_candles['close'] > pd_candles['ema_close'])) | # Case 1: Green candle and close > EMA
|
|
@@ -55,12 +55,12 @@ def calc_eff_trailing_sl(
|
|
|
55
55
|
tp_max_percent : float,
|
|
56
56
|
sl_percent_trailing : float,
|
|
57
57
|
pnl_percent_notional : float,
|
|
58
|
-
|
|
58
|
+
default_effective_tp_trailing_percent : float = 50
|
|
59
59
|
) -> float:
|
|
60
60
|
slope = (0 - sl_percent_trailing) / (tp_max_percent - tp_min_percent)
|
|
61
|
-
|
|
61
|
+
effective_tp_trailing_percent = (
|
|
62
62
|
slope * (pnl_percent_notional - tp_min_percent) + sl_percent_trailing
|
|
63
63
|
if pnl_percent_notional>tp_min_percent
|
|
64
|
-
else
|
|
64
|
+
else default_effective_tp_trailing_percent
|
|
65
65
|
)
|
|
66
|
-
return
|
|
66
|
+
return effective_tp_trailing_percent
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/aggregated_orderbook_provider.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/ccxt_candles_ta_to_csv.py
RENAMED
|
File without changes
|
|
File without changes
|
{siglab_py-0.3.0 → siglab_py-0.3.1}/siglab_py/market_data_providers/futu_candles_ta_to_csv.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|