siglab-py 0.5.38__py3-none-any.whl → 0.5.48__py3-none-any.whl

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.

@@ -4,7 +4,7 @@ https://www.futuhk.com/en/support/categories/909?global_content=%7B%22promote_id
4
4
 
5
5
  Fees: https://www.futuhk.com/en/commissionnew#crypto
6
6
 
7
- Subscribe L2 data: https://openapi.futunn.com/futu-api-doc/en/intro/authority.html#5331
7
+ Subscribe L2 data: https://openapi.futunn.com/futu-api-doc/en/intro/authority.html
8
8
 
9
9
  Investor Protection: https://www.futuhk.com/en
10
10
 
@@ -15,8 +15,17 @@ Margin Trading:
15
15
  Download Futu OpenD
16
16
  https://www.futuhk.com/en/support/topic1_464?global_content=%7B%22promote_id%22%3A13765%2C%22sub_promote_id%22%3A10%7D
17
17
 
18
- If you run the installer version "Futu_OpenD-GUI_9.0.5008_Windows.exe", it'd be installed under:
18
+ If you run the installer version "Futu_OpenD-GUI_9.0.5008_Windows.exe", it'd be installed under C-Drive:
19
19
  C:\\Users\\xxx\\AppData\\Roaming\\Futu_OpenD\\Futu_OpenD.exe
20
+ Unfortunately, log folder also under C-drive as a result, and they are big.
21
+
22
+ For command line version: https://openapi.futunn.com/futu-api-doc/opend/opend-cmd.html
23
+ Binary under downloaded package (You can put it under for example D-drive):
24
+ ...\Futu_OpenD_9.4.5408_Windows\Futu_OpenD_9.4.5408_Windows
25
+
26
+ Put a batch file "start_futu_opend.bat", if login_pwd include special characters, enclose pwd with double quotes:
27
+ FutuOpenD -login_account=1234567 -login_pwd="... Your Secret here ..."
28
+ Config file is "FutuOpenD.xml", you can adjust logging verbosity here.
20
29
 
21
30
  Architecture: https://openapi.futunn.com/futu-api-doc/en/intro/intro.html
22
31
 
@@ -17,15 +17,17 @@ from siglab_py.util.analytic_util import compute_candles_stats
17
17
  '''
18
18
  Usage:
19
19
  set PYTHONPATH=%PYTHONPATH%;D:\dev\siglab\siglab_py
20
- python futu_candles_ta_to_csv.py --symbol HK.00700 --end_date "2025-03-11 0:0:0" --start_date "2021-03-11 0:0:0" --market HK --trdmarket HK --security_firm FUTUSECURITIES --security_type STOCK --compute_ta Y --pypy_compatible N
20
+ python futu_candles_ta_to_csv.py --symbol HK.00700 --end_date "2025-03-11 0:0:0" --start_date "2021-03-11 0:0:0" --candle_size 1h --market HK --trdmarket HK --security_firm FUTUSECURITIES --security_type STOCK --compute_ta Y --pypy_compatible N
21
+ python futu_candles_ta_to_csv.py --symbol HK.02840 --end_date "2025-07-30 0:0:0" --start_date "2018-01-01 0:0:0" --candle_size 1h --market HK --trdmarket HK --security_firm FUTUSECURITIES --security_type STOCK --compute_ta Y --pypy_compatible N
22
+ python futu_candles_ta_to_csv.py --symbol AAPL --end_date "2025-03-11 0:0:0" --start_date "2024-03-11 0:0:0" --candle_size 1h --market US --trdmarket US --security_firm FUTUSECURITIES --security_type STOCK --compute_ta Y --pypy_compatible N
21
23
 
22
- python futu_candles_ta_to_csv.py --symbol AAPL --end_date "2025-03-11 0:0:0" --start_date "2024-03-11 0:0:0" --market US --trdmarket US --security_firm FUTUSECURITIES --security_type STOCK --compute_ta Y --pypy_compatible N
23
-
24
- Gold contracts? Note, symbol is case sensitive with Futu.
24
+ Gold contracts? Note, symbol is case sensitive with Futu. So, "GCmain" is correct, "GCMain" is in-correct.
25
25
  python futu_candles_ta_to_csv.py --symbol US.GCmain --end_date "2025-03-11 0:0:0" --start_date "2021-03-11 0:0:0" --market US --trdmarket FUTURES --security_firm FUTUSECURITIES --security_type FUTURE --compute_ta Y --pypy_compatible N
26
26
 
27
27
  (Remember: python -mpip install siglab_py)
28
28
 
29
+ Gold future contract specification: https://www.futunn.com/en/futures/GCMAIN-US/contract-specs
30
+
29
31
  This script is pypy compatible. Set "pypy_compatible" to True, in which case "compute_candles_stats" will skip calculation for TAs which requires: scipy, statsmodels, scikit-learn, sklearn.preprocessing
30
32
  pypy futu_candles_ta_to_csv.py --symbol HK.00700 --end_date "2025-03-11 0:0:0" --start_date "2024-03-11 0:0:0" --market HK --trdmarket HK --security_firm FUTUSECURITIES --security_type STOCK --compute_ta Y --pypy_compatible Y
31
33
 
@@ -1,5 +1,5 @@
1
1
  from typing import Union
2
- from util.aws_util import AwsKmsUtil
2
+ from siglab_py.util.aws_util import AwsKmsUtil
3
3
 
4
4
  '''
5
5
  From command line, run 'aws configure' with IAM user's Access key ID and Secret access key. (Assume you have awscli installed)
@@ -45,18 +45,20 @@ class AnalyticUtilTests(unittest.TestCase):
45
45
  'exchange', 'symbol', 'timestamp_ms',
46
46
  'open', 'high', 'low', 'close', 'volume',
47
47
  'datetime', 'datetime_utc', 'year', 'month', 'day', 'hour', 'minute', 'dayofweek',
48
- 'pct_chg_on_close', 'candle_height',
48
+ 'pct_chg_on_close', 'candle_height', 'candle_body_height',
49
49
  'week_of_month', 'apac_trading_hr', 'emea_trading_hr', 'amer_trading_hr',
50
50
  'is_green', 'pct_change_close',
51
51
  'sma_short_periods', 'sma_long_periods', 'ema_short_periods', 'ema_long_periods', 'ema_close',
52
52
  'std', 'std_percent',
53
53
  'vwap_short_periods', 'vwap_long_periods',
54
- 'candle_height_percent', 'candle_height_percent_rounded',
54
+ 'candle_height_percent', 'candle_height_percent_rounded', 'candle_body_height_percent', 'candle_body_height_percent_rounded',
55
55
  'log_return', 'interval_hist_vol', 'annualized_hist_vol',
56
56
  'chop_against_ema',
57
57
  'ema_volume_short_periods', 'ema_volume_long_periods',
58
58
  'ema_cross', 'ema_cross_last', 'ema_bullish_cross_last_id', 'ema_bearish_cross_last_id',
59
59
  'max_short_periods', 'max_long_periods', 'idmax_short_periods', 'idmax_long_periods', 'min_short_periods', 'min_long_periods', 'idmin_short_periods', 'idmin_long_periods',
60
+ 'max_candle_body_height_percent_long_periods', 'idmax_candle_body_height_percent_long_periods',
61
+ 'min_candle_body_height_percent_long_periods', 'idmin_candle_body_height_percent_long_periods',
60
62
  'price_swing_short_periods', 'price_swing_long_periods',
61
63
  'trend_from_highs_long_periods', 'trend_from_lows_long_periods', 'trend_from_highs_short_periods', 'trend_from_lows_short_periods',
62
64
  'h_l', 'h_pc', 'l_pc', 'tr', 'atr', 'atr_avg_short_periods', 'atr_avg_long_periods',
@@ -0,0 +1,87 @@
1
+ import unittest
2
+ from typing import List
3
+
4
+ from util.simple_math import generate_rand_nums
5
+
6
+ class SimpleMathTests(unittest.TestCase):
7
+
8
+ def test_generate_rand_nums(self):
9
+ range_min : float = 0
10
+ range_max : float = 1
11
+ size : int = 100
12
+ percentage_in_range : float = 91
13
+ abs_min : float = -0.5
14
+ abs_max : float = 1.1
15
+
16
+ rand_nums : List[float] = generate_rand_nums(
17
+ range_min = range_min,
18
+ range_max = range_max,
19
+ size = size,
20
+ percent_in_range = percentage_in_range,
21
+ abs_min = abs_min,
22
+ abs_max = abs_max
23
+ )
24
+
25
+ assert(len(rand_nums)==size)
26
+ assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
27
+ assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
28
+
29
+
30
+ range_min = -1
31
+ range_max = 1
32
+ percentage_in_range = 91
33
+ abs_min = -1.5
34
+ abs_max = 1.5
35
+
36
+ rand_nums : List[float] = generate_rand_nums(
37
+ range_min = range_min,
38
+ range_max = range_max,
39
+ size = size,
40
+ percent_in_range = percentage_in_range,
41
+ abs_min = abs_min,
42
+ abs_max = abs_max
43
+ )
44
+
45
+ assert(len(rand_nums)==size)
46
+ assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
47
+ assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
48
+
49
+
50
+ range_min = 0
51
+ range_max = 100
52
+ percentage_in_range = 91
53
+ abs_min = -150
54
+ abs_max = 150
55
+
56
+ rand_nums : List[float] = generate_rand_nums(
57
+ range_min = range_min,
58
+ range_max = range_max,
59
+ size = size,
60
+ percent_in_range = percentage_in_range,
61
+ abs_min = abs_min,
62
+ abs_max = abs_max
63
+ )
64
+
65
+ assert(len(rand_nums)==size)
66
+ assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
67
+ assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
68
+
69
+
70
+ range_min = -100
71
+ range_max = 100
72
+ percentage_in_range = 91
73
+ abs_min = -150
74
+ abs_max = 150
75
+
76
+ rand_nums : List[float] = generate_rand_nums(
77
+ range_min = range_min,
78
+ range_max = range_max,
79
+ size = size,
80
+ percent_in_range = percentage_in_range,
81
+ abs_min = abs_min,
82
+ abs_max = abs_max
83
+ )
84
+
85
+ assert(len(rand_nums)==size)
86
+ assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
87
+ assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
@@ -121,6 +121,7 @@ def compute_candles_stats(
121
121
  pypy_compat : bool = True
122
122
  ):
123
123
  pd_candles['candle_height'] = pd_candles['high'] - pd_candles['low']
124
+ pd_candles['candle_body_height'] = pd_candles['close'] - pd_candles['open']
124
125
 
125
126
  '''
126
127
  market_data_gizmo inserted dummy lines --> Need exclude those or "TypeError: unorderable types for comparison": pd_btc_candles = pd_btc_candles[pd_btc_candles.close.notnull()]
@@ -157,6 +158,9 @@ def compute_candles_stats(
157
158
  pd_candles['candle_height_percent'] = pd_candles['candle_height'] / pd_candles['ema_close'] * 100
158
159
  pd_candles['candle_height_percent_rounded'] = pd_candles['candle_height_percent'].round().astype('Int64')
159
160
 
161
+ pd_candles['candle_body_height_percent'] = pd_candles['candle_body_height'] / pd_candles['ema_close'] * 100
162
+ pd_candles['candle_body_height_percent_rounded'] = pd_candles['candle_body_height_percent'].round().astype('Int64')
163
+
160
164
  '''
161
165
  To annualize volatility:
162
166
  if candle_interval == '1m':
@@ -235,6 +239,11 @@ def compute_candles_stats(
235
239
  pd_candles['idmin_short_periods'] = close_short_periods_rolling.apply(lambda x : x.idxmin())
236
240
  pd_candles['idmin_long_periods'] = close_long_periods_rolling.apply(lambda x : x.idxmin())
237
241
 
242
+ pd_candles['max_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).max()
243
+ pd_candles['idmax_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).apply(lambda x : x.idxmax())
244
+ pd_candles['min_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).min()
245
+ pd_candles['idmin_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).apply(lambda x : x.idxmin())
246
+
238
247
  pd_candles['price_swing_short_periods'] = np.where(
239
248
  pd_candles['idmax_short_periods'] > pd_candles['idmin_short_periods'],
240
249
  pd_candles['max_short_periods'] - pd_candles['min_short_periods'], # Up swing
@@ -580,7 +589,7 @@ def compute_candles_stats(
580
589
  pd_data=pd_candles,
581
590
  src_col_name='ema_rsi',
582
591
  slope_col_name='ema_rsi_slope',
583
- sliding_window_how_many_candles=int(sliding_window_how_many_candles)
592
+ sliding_window_how_many_candles=int(rsi_trend_sliding_window_how_many_candles)
584
593
  )
585
594
 
586
595
  pd_candles['regular_divergence'] = (
@@ -0,0 +1,30 @@
1
+ import random
2
+ from typing import List
3
+
4
+ def generate_rand_nums(
5
+ range_min : float = 0,
6
+ range_max : float = 1,
7
+ size=100, # list size
8
+ percent_in_range : float = 100,
9
+ abs_min : float = 0,
10
+ abs_max : float = 1
11
+ ):
12
+ assert(range_min<range_max)
13
+
14
+ if abs_min>range_min:
15
+ abs_min = range_min
16
+ if abs_max<range_max:
17
+ abs_max = range_max
18
+
19
+ result = []
20
+ for _ in range(int(size * percent_in_range/100)):
21
+ result.append(random.uniform(range_min, range_max))
22
+ for _ in range(size - len(result)):
23
+ if random.uniform(0, 1)>0.5:
24
+ result.append(random.uniform(abs_min, range_min))
25
+ else:
26
+ result.append(random.uniform(range_max, abs_max))
27
+
28
+ random.shuffle(result)
29
+
30
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: siglab_py
3
- Version: 0.5.38
3
+ Version: 0.5.48
4
4
  Summary: Market data fetches, TA calculations and generic order gateway.
5
5
  Author: r0bbarh00d
6
6
  Author-email: r0bbarh00d <r0bbarh00d@gmail.com>
@@ -2,38 +2,40 @@ siglab_py/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  siglab_py/constants.py,sha256=atSjvM0wv_f1wrzWHE0DcbUn6fqLmg-51BpfMJR1QB4,547
3
3
  siglab_py/exchanges/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  siglab_py/exchanges/any_exchange.py,sha256=Y-zue75ZSmu9Ga1fONbjBGLNH5pDHQI01hCSjuLBkAk,889
5
- siglab_py/exchanges/futubull.py,sha256=f-_trzvuH5NaiG-PzyiNqZ12w7J-ARi_-xcr78rFU4E,20510
5
+ siglab_py/exchanges/futubull.py,sha256=i0jNgl9BGJvgEIDeOkTfD52FaK77vX8axCKNYwJHwSI,21144
6
6
  siglab_py/market_data_providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  siglab_py/market_data_providers/aggregated_orderbook_provider.py,sha256=FZRobEBNRzcNGlOG3u38OVhmOZYlkNm8dVvR-S7Ii2g,23342
8
8
  siglab_py/market_data_providers/candles_provider.py,sha256=fqHJjlECsBiBlpgyywrc4gTgxiROPNzZM8KxQBB5cOg,14139
9
9
  siglab_py/market_data_providers/candles_ta_provider.py,sha256=uiAhbEZZdTF-YulBHpSLwabos5LHCKU91NTiTmpUc0w,12001
10
10
  siglab_py/market_data_providers/ccxt_candles_ta_to_csv.py,sha256=DHj51QTbkCmEd9RFNVhWWpsSPz1aLd6zTLqkUUbEkK0,11158
11
11
  siglab_py/market_data_providers/deribit_options_expiry_provider.py,sha256=e9Ee8TmC8pXaid8-jouSLKIpuW6_JBBgwRTieI665yQ,8684
12
- siglab_py/market_data_providers/futu_candles_ta_to_csv.py,sha256=PZRpVL80CG6518uUg38Wb9aoWzidunyBAFFFGvrDnaI,10531
12
+ siglab_py/market_data_providers/futu_candles_ta_to_csv.py,sha256=SCWlI_mOuErpGP8Kxh5WKEoff9cqqxO19oLFLd04bTs,10964
13
13
  siglab_py/market_data_providers/orderbooks_provider.py,sha256=olt-3LIkoyzQWfNNQRhJtKibLbkTutt_q_rCCTM7i1g,16216
14
14
  siglab_py/market_data_providers/test_provider.py,sha256=wBLCgcWjs7FGZJXWsNyn30lkOLa_cgpuvqRakMC0wbA,2221
15
15
  siglab_py/market_data_providers/tg_monitor.py,sha256=lRqONP0JAP223gyX37R-wCkhyGFKTvKkgmeDNoO3ay4,21813
16
16
  siglab_py/ordergateway/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  siglab_py/ordergateway/client.py,sha256=LvtrYirrdFOcKgTkvuqwdEN7r3nurjX320ESnk7tHE0,15095
18
- siglab_py/ordergateway/encrypt_keys_util.py,sha256=-qi87db8To8Yf1WS1Q_Cp2Ya7ZqgWlRqSHfNXCM7wE4,1339
18
+ siglab_py/ordergateway/encrypt_keys_util.py,sha256=U_M-jPrPYOTO_sU0bMVkO5ruNXge5vek8yUGa8jaE-g,1349
19
19
  siglab_py/ordergateway/gateway.py,sha256=Z-BQ-Z9gXoNrKQHzRIy9R1mnCybf9QwWhHpqkSI7bBM,43901
20
20
  siglab_py/ordergateway/test_ordergateway.py,sha256=4PE2flp_soGcD3DrI7zJOzZndjkb6I5XaDrFNNq4Huo,4009
21
21
  siglab_py/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  siglab_py/tests/integration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  siglab_py/tests/integration/market_data_util_tests.py,sha256=p-RWIJZLyj0lAdfi4QTIeAttCm_e8mEVWFKh4OWuogU,7189
24
24
  siglab_py/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- siglab_py/tests/unit/analytic_util_tests.py,sha256=Tffqy6ngMDj71NkwWvswRln8uhLUJ-RckhbTMN-jVX4,5474
25
+ siglab_py/tests/unit/analytic_util_tests.py,sha256=K7jtuKJLynW8EFyNgjOVHA2e2d6Gl2f0ONggFy9tD7g,5780
26
26
  siglab_py/tests/unit/market_data_util_tests.py,sha256=A1y83itISmMJdn6wLpfwcr4tGola8wTf1D1xbelMvgw,2026
27
+ siglab_py/tests/unit/simple_math_tests.py,sha256=nM7RZyFGNpMpAXattrO-K5gnlhYXF1trWRbETWRQiqU,3643
27
28
  siglab_py/tests/unit/trading_util_tests.py,sha256=9DZmTZlW55lPtNfTCukgDdiyBiMYv9R4mEFWJIJiTNg,3870
28
29
  siglab_py/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- siglab_py/util/analytic_util.py,sha256=vZ8G8Kpb2dYoeV5ruIaoVz4lUcVFAILsQVF-zuFb9yk,60287
30
+ siglab_py/util/analytic_util.py,sha256=dlmaf4QZ95JPGNN0LgOG8njpYE9nek4g9QVA51KvM6s,61306
30
31
  siglab_py/util/aws_util.py,sha256=KGmjHrr1rpnnxr33nXHNzTul4tvyyxl9p6gpwNv0Ygc,2557
31
32
  siglab_py/util/market_data_util.py,sha256=mUXg4uaiX3b6_klgJWIEgnUQU4IUd6CwTOqKLiQWRlU,31307
32
33
  siglab_py/util/notification_util.py,sha256=tNZMUkkjz4q1CKqcQq62oEmZgHgNIwz2Iw9J22V22Zw,2668
33
34
  siglab_py/util/retry_util.py,sha256=g-UU6pkPouWZZRZEqP99R2Z0lX5xzckYkzjwqqSDpVQ,922
35
+ siglab_py/util/simple_math.py,sha256=LUZVMEl-EA_jMgIYcqOFPgMEDRDJxFU4n_KCN1qznyw,827
34
36
  siglab_py/util/slack_notification_util.py,sha256=G27n-adbT3Q6oaHSMvu_Nom794rrda5PprSF-zvmzkM,1912
35
37
  siglab_py/util/trading_util.py,sha256=-TGNgJdy4HMDPgq31KQn_lRawFxuXnFU5NnLRb1XM5o,5757
36
- siglab_py-0.5.38.dist-info/METADATA,sha256=GfE11A07HWATi24pVPfOLFZxxMPd1aKae-97cmeuOqo,829
37
- siglab_py-0.5.38.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
38
- siglab_py-0.5.38.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
39
- siglab_py-0.5.38.dist-info/RECORD,,
38
+ siglab_py-0.5.48.dist-info/METADATA,sha256=kg-ba09DtS7X-RWGzHjRRhz6xmmjWy-PhS4ZYhdZzoU,829
39
+ siglab_py-0.5.48.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
40
+ siglab_py-0.5.48.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
41
+ siglab_py-0.5.48.dist-info/RECORD,,