siglab-py 0.3.11__py3-none-any.whl → 0.3.13__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.

@@ -34,17 +34,21 @@ current_filename = os.path.basename(__file__)
34
34
  '''
35
35
  Usage:
36
36
  set PYTHONPATH=%PYTHONPATH%;D:\dev\siglab\siglab_py
37
- python gateway.py --gateway_id hyperliquid_01 --default_type linear --rate_limit_ms 100
37
+ python gateway.py --gateway_id hyperliquid_01 --default_type linear --rate_limit_ms 100 --encrypt_decrypt_with_aws_kms Y --aws_kms_key_id xxx --apikey xxx --secret xxxx --slack_info_url=https://hooks.slack.com/services/xxx --slack_critial_url=https://hooks.slack.com/services/xxx --slack_alert_url=https://hooks.slack.com/services/xxx
38
38
 
39
39
  --default_type defaults to linear
40
40
  --rate_limit_ms defaults to 100
41
-
41
+ --encrypt_decrypt_with_aws_kms If you encrypt apikey and secret using AMS KMS, then set to Y. If apikey and secret in unencrypted plain text, set to N.
42
+ --passphrase is optional, this depends on the exchange.
43
+ --gateway_id contains two parts separated by underscore. Gateway.py will parse 'hyperliquid_01' into two parts: 'hyperliquid' (Exchange name) and '01' (Use this for your sub account ID). Exchange name need be spelt exactly. Please have a look at market_data_util async_instantiate_exchange.
42
44
  --slack_info_url, --slack_critical_url and --slack_alert_url are if you want gateway to dispatch Slack notification on events.
43
45
  How to get Slack webhook urls? https://medium.com/@natalia_assad/how-send-a-table-to-slack-using-python-d1a20b08abe0
44
46
 
45
47
  Another example:
46
48
  python gateway.py --gateway_id hyperliquid_01 --default_type linear --rate_limit_ms 100 --slack_info_url=https://hooks.slack.com/services/xxx --slack_critial_url=https://hooks.slack.com/services/yyy --slack_alert_url=https://hooks.slack.com/services/zzz
47
49
 
50
+ gateway.py takes outgoing orders from redis and publish executions back to redis when done. Redis configuration in param['mds']['redis']. Start redis before starting gateway.py.
51
+
48
52
  This script is pypy compatible:
49
53
  pypy gateway.py --gateway_id bybit_01 --default_type linear --rate_limit_ms 100
50
54
 
@@ -453,7 +457,7 @@ async def execute_one_position(
453
457
  }
454
458
  if position.order_type=='limit':
455
459
  order_params['postOnly'] = True
456
-
460
+
457
461
  if not param['dry_run']:
458
462
  executed_order = await exchange.create_order( # type: ignore
459
463
  symbol = position.ticker,
@@ -1,6 +1,8 @@
1
+ import logging
1
2
  import incremental
2
3
  import tzlocal
3
4
  from datetime import datetime, timezone
5
+ import time
4
6
  from typing import List, Dict, Union, NoReturn, Any, Tuple
5
7
  from pathlib import Path
6
8
  import math
@@ -116,6 +118,8 @@ async def async_instantiate_exchange(
116
118
  # spot, swap, future
117
119
  # https://github.com/ccxt/ccxt/blob/master/python/ccxt/deribit.py#L360
118
120
  exchange = ccxtpro.deribit(exchange_params) # type: ignore
121
+ elif exchange_name=='kraken':
122
+ exchange = ccxtpro.kraken(exchange_params) # type: ignore
119
123
  elif exchange_name=='hyperliquid':
120
124
  '''
121
125
  https://app.hyperliquid.xyz/API
@@ -509,6 +513,28 @@ def fetch_candles(
509
513
  )
510
514
  return { '' : None }
511
515
 
516
+ '''
517
+ Find listing date https://gist.github.com/mr-easy/5185b1dcdd5f9f908ff196446f092e9b
518
+
519
+ Usage:
520
+ listing_ts = find_start_time(exchange, 'HYPE/USDT:USDT', int(datetime(2024,1,1).timestamp()*1000), int(datetime(2025,5,1).timestamp()*1000), '1h')
521
+
522
+ Caveats:
523
+ 1) If listing date lies outside [start_time, end_time], this function will stackoverflow,
524
+ 2) Even if not, it's still very time consuming.
525
+
526
+ Alternative: market['created']
527
+ '''
528
+ def search_listing_ts(exchange, symbol, start_time, end_time, timeframe):
529
+ mid_time = (start_time + end_time)//2
530
+ if(mid_time == start_time): return mid_time+1
531
+ ohlcv = exchange.fetch_ohlcv(symbol, timeframe, mid_time, limit=1)
532
+ time.sleep(1)
533
+ if(len(ohlcv) == 0):
534
+ return search_listing_ts(exchange, symbol, mid_time, end_time, timeframe)
535
+ else:
536
+ return search_listing_ts(exchange, symbol, start_time, mid_time, timeframe)
537
+
512
538
  def _fetch_candles_ccxt(
513
539
  start_ts : int,
514
540
  end_ts : int,
@@ -517,8 +543,14 @@ def _fetch_candles_ccxt(
517
543
  candle_size : str,
518
544
  num_candles_limit : int = 100
519
545
  ) -> Dict[str, Union[pd.DataFrame, None]]:
546
+ logger = logging.getLogger()
547
+
520
548
  rsp = {}
521
549
 
550
+ exchange.load_markets()
551
+
552
+ num_tickers = len(normalized_symbols)
553
+ i = 0
522
554
  for ticker in normalized_symbols:
523
555
  @retry(num_attempts=3, pause_between_retries_ms=1000)
524
556
  def _fetch_ohlcv(exchange, symbol, timeframe, since, limit, params) -> Union[List, NoReturn]:
@@ -543,6 +575,18 @@ def _fetch_candles_ccxt(
543
575
  raise ValueError(f"Invalid candle_size {candle_size}")
544
576
  return num_intervals * increment
545
577
 
578
+ logger.info(f"{i}/{num_tickers} Fetching {candle_size} candles for {ticker}.")
579
+
580
+ '''
581
+ It uses a while loop to implement a sliding window to download candles between start_ts and end_ts.
582
+ However, start_ts for example can be 1 Jan 2021 for a given ticker.
583
+ But if that ticker listing date is 1 Jan 2025, this while loop would waste a lot of time loop between 1 Jan 2021 thru 31 Dec 2024, slowly incrementing this_cutoff += _calc_increment(candle_size).
584
+ A more efficient way is to find listing date. Start looping from there.
585
+ '''
586
+ market = exchange.markets[ticker]
587
+ if market['created']:
588
+ start_ts = max(start_ts, int(market['created']/1000))
589
+
546
590
  all_candles = []
547
591
  params = {}
548
592
  this_cutoff = start_ts
@@ -567,6 +611,8 @@ def _fetch_candles_ccxt(
567
611
 
568
612
  rsp[ticker] = pd_all_candles
569
613
 
614
+ i+=1
615
+
570
616
  return rsp
571
617
 
572
618
  def fetch_deribit_btc_option_expiries(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: siglab-py
3
- Version: 0.3.11
3
+ Version: 0.3.13
4
4
  Summary: Market data fetches, TA calculations and generic order gateway.
5
5
  Author: r0bbarh00d
6
6
  Author-email: r0bbarh00d <r0bbarh00d@gmail.com>
@@ -15,7 +15,7 @@ siglab_py/market_data_providers/test_provider.py,sha256=wBLCgcWjs7FGZJXWsNyn30lk
15
15
  siglab_py/ordergateway/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  siglab_py/ordergateway/client.py,sha256=LvtrYirrdFOcKgTkvuqwdEN7r3nurjX320ESnk7tHE0,15095
17
17
  siglab_py/ordergateway/encrypt_keys_util.py,sha256=-qi87db8To8Yf1WS1Q_Cp2Ya7ZqgWlRqSHfNXCM7wE4,1339
18
- siglab_py/ordergateway/gateway.py,sha256=uMJRDGoYrqHZCfkv5ye-tmsJ8nYawIzy9_ehXa3Kk8M,42166
18
+ siglab_py/ordergateway/gateway.py,sha256=5whFTlBLiIMPZ2YyedEIuLclPIdUzC67AZqw56C9o-Y,43087
19
19
  siglab_py/ordergateway/test_ordergateway.py,sha256=4PE2flp_soGcD3DrI7zJOzZndjkb6I5XaDrFNNq4Huo,4009
20
20
  siglab_py/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  siglab_py/tests/integration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -27,12 +27,12 @@ siglab_py/tests/unit/trading_util_tests.py,sha256=tyefqOTQOoXSlemSDonqmdHp61-1nu
27
27
  siglab_py/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  siglab_py/util/analytic_util.py,sha256=blFJ1kY_aSJeuzzk28vdB4nhLgmosz0L8IJaJCZy9OM,47272
29
29
  siglab_py/util/aws_util.py,sha256=KGmjHrr1rpnnxr33nXHNzTul4tvyyxl9p6gpwNv0Ygc,2557
30
- siglab_py/util/market_data_util.py,sha256=ogkuj8grE2sVI_-K2wPeyE7pdY04UpsVsoePQXjub7k,29387
30
+ siglab_py/util/market_data_util.py,sha256=mUXg4uaiX3b6_klgJWIEgnUQU4IUd6CwTOqKLiQWRlU,31307
31
31
  siglab_py/util/notification_util.py,sha256=vySgHjpHgwFDLW0tHSi_AGh9JBbPc25IUgvWxmjAeT8,2658
32
32
  siglab_py/util/retry_util.py,sha256=g-UU6pkPouWZZRZEqP99R2Z0lX5xzckYkzjwqqSDpVQ,922
33
33
  siglab_py/util/slack_notification_util.py,sha256=G27n-adbT3Q6oaHSMvu_Nom794rrda5PprSF-zvmzkM,1912
34
34
  siglab_py/util/trading_util.py,sha256=FmqsamuPhMjZUkz4lCyuE8MHFapXn6yNl8Isy7peQEs,3047
35
- siglab_py-0.3.11.dist-info/METADATA,sha256=HkAJasuTZTqIP16RrphAhj4Yyvqu4u4GOq6h5wD_lsc,980
36
- siglab_py-0.3.11.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
37
- siglab_py-0.3.11.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
38
- siglab_py-0.3.11.dist-info/RECORD,,
35
+ siglab_py-0.3.13.dist-info/METADATA,sha256=Iya9J0Qa1UtxXwEe6-0hWRkoy2Xr5zisxfOkIxZDMV8,980
36
+ siglab_py-0.3.13.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
37
+ siglab_py-0.3.13.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
38
+ siglab_py-0.3.13.dist-info/RECORD,,