siglab-py 0.3.9__py3-none-any.whl → 0.3.10__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.
- siglab_py/util/market_data_util.py +45 -44
- {siglab_py-0.3.9.dist-info → siglab_py-0.3.10.dist-info}/METADATA +1 -1
- {siglab_py-0.3.9.dist-info → siglab_py-0.3.10.dist-info}/RECORD +5 -5
- {siglab_py-0.3.9.dist-info → siglab_py-0.3.10.dist-info}/WHEEL +0 -0
- {siglab_py-0.3.9.dist-info → siglab_py-0.3.10.dist-info}/top_level.txt +0 -0
|
@@ -516,55 +516,56 @@ def _fetch_candles_ccxt(
|
|
|
516
516
|
candle_size : str,
|
|
517
517
|
num_candles_limit : int = 100
|
|
518
518
|
) -> Dict[str, Union[pd.DataFrame, None]]:
|
|
519
|
-
|
|
519
|
+
rsp = {}
|
|
520
520
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
candles
|
|
521
|
+
for ticker in normalized_symbols:
|
|
522
|
+
def _fetch_ohlcv(exchange, symbol, timeframe, since, limit, params) -> Union[List, NoReturn]:
|
|
523
|
+
one_timeframe = f"1{timeframe[-1]}"
|
|
524
|
+
candles = exchange.fetch_ohlcv(symbol=symbol, timeframe=one_timeframe, since=since, limit=limit, params=params)
|
|
525
|
+
if candles and len(candles)>0:
|
|
526
|
+
candles.sort(key=lambda x : x[0], reverse=False)
|
|
526
527
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
def _calc_increment(candle_size):
|
|
530
|
-
increment = 1
|
|
531
|
-
num_intervals = int(candle_size[0])
|
|
532
|
-
interval_type = candle_size[-1]
|
|
533
|
-
if interval_type == "m":
|
|
534
|
-
increment = 60
|
|
535
|
-
elif interval_type == "h":
|
|
536
|
-
increment = 60*60
|
|
537
|
-
elif interval_type == "d":
|
|
538
|
-
increment = 60*60*24
|
|
539
|
-
else:
|
|
540
|
-
raise ValueError(f"Invalid candle_size {candle_size}")
|
|
541
|
-
return num_intervals * increment
|
|
542
|
-
|
|
543
|
-
all_candles = []
|
|
544
|
-
params = {}
|
|
545
|
-
this_cutoff = start_ts
|
|
546
|
-
while this_cutoff<end_ts:
|
|
547
|
-
candles = _fetch_ohlcv(exchange=exchange, symbol=ticker, timeframe=candle_size, since=int(this_cutoff * 1000), limit=num_candles_limit, params=params)
|
|
548
|
-
if candles and len(candles)>0:
|
|
549
|
-
all_candles = all_candles + [[ int(x[0]), float(x[1]), float(x[2]), float(x[3]), float(x[4]), float(x[5]) ] for x in candles if x[1] and x[2] and x[3] and x[4] and x[5] ]
|
|
550
|
-
|
|
551
|
-
record_ts = max([int(record[0]) for record in candles])
|
|
552
|
-
record_ts_str : str = str(record_ts)
|
|
553
|
-
if len(record_ts_str)==13:
|
|
554
|
-
record_ts = int(int(record_ts_str)/1000) # Convert from milli-seconds to seconds
|
|
528
|
+
return candles
|
|
555
529
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
530
|
+
def _calc_increment(candle_size):
|
|
531
|
+
increment = 1
|
|
532
|
+
num_intervals = int(candle_size[0])
|
|
533
|
+
interval_type = candle_size[-1]
|
|
534
|
+
if interval_type == "m":
|
|
535
|
+
increment = 60
|
|
536
|
+
elif interval_type == "h":
|
|
537
|
+
increment = 60*60
|
|
538
|
+
elif interval_type == "d":
|
|
539
|
+
increment = 60*60*24
|
|
540
|
+
else:
|
|
541
|
+
raise ValueError(f"Invalid candle_size {candle_size}")
|
|
542
|
+
return num_intervals * increment
|
|
543
|
+
|
|
544
|
+
all_candles = []
|
|
545
|
+
params = {}
|
|
546
|
+
this_cutoff = start_ts
|
|
547
|
+
while this_cutoff<end_ts:
|
|
548
|
+
candles = _fetch_ohlcv(exchange=exchange, symbol=ticker, timeframe=candle_size, since=int(this_cutoff * 1000), limit=num_candles_limit, params=params)
|
|
549
|
+
if candles and len(candles)>0:
|
|
550
|
+
all_candles = all_candles + [[ int(x[0]), float(x[1]), float(x[2]), float(x[3]), float(x[4]), float(x[5]) ] for x in candles if x[1] and x[2] and x[3] and x[4] and x[5] ]
|
|
551
|
+
|
|
552
|
+
record_ts = max([int(record[0]) for record in candles])
|
|
553
|
+
record_ts_str : str = str(record_ts)
|
|
554
|
+
if len(record_ts_str)==13:
|
|
555
|
+
record_ts = int(int(record_ts_str)/1000) # Convert from milli-seconds to seconds
|
|
556
|
+
|
|
557
|
+
this_cutoff = record_ts + _calc_increment(candle_size)
|
|
558
|
+
else:
|
|
559
|
+
this_cutoff += _calc_increment(candle_size)
|
|
559
560
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
561
|
+
columns = ['exchange', 'symbol', 'timestamp_ms', 'open', 'high', 'low', 'close', 'volume']
|
|
562
|
+
pd_all_candles = pd.DataFrame([ [ exchange.name, ticker, x[0], x[1], x[2], x[3], x[4], x[5] ] for x in all_candles], columns=columns)
|
|
563
|
+
fix_column_types(pd_all_candles)
|
|
564
|
+
pd_all_candles['pct_chg_on_close'] = pd_all_candles['close'].pct_change()
|
|
564
565
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
566
|
+
rsp[ticker] = pd_all_candles
|
|
567
|
+
|
|
568
|
+
return rsp
|
|
568
569
|
|
|
569
570
|
def fetch_deribit_btc_option_expiries(
|
|
570
571
|
market: str = 'BTC'
|
|
@@ -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=
|
|
30
|
+
siglab_py/util/market_data_util.py,sha256=ND2uBpfsYkzDEf8i2jf6ZFYyBGDDdYDqCI6NJrW9DqY,29279
|
|
31
31
|
siglab_py/util/notification_util.py,sha256=vySgHjpHgwFDLW0tHSi_AGh9JBbPc25IUgvWxmjAeT8,2658
|
|
32
32
|
siglab_py/util/retry_util.py,sha256=mxYuRFZRZoaQQjENcwPmxhxixtd1TFvbxIdPx4RwfRc,743
|
|
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.
|
|
36
|
-
siglab_py-0.3.
|
|
37
|
-
siglab_py-0.3.
|
|
38
|
-
siglab_py-0.3.
|
|
35
|
+
siglab_py-0.3.10.dist-info/METADATA,sha256=FzjfNoVztgaAR3Wmw9Jlamc49HEPBF99Az01i3yJtig,980
|
|
36
|
+
siglab_py-0.3.10.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
37
|
+
siglab_py-0.3.10.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
|
|
38
|
+
siglab_py-0.3.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|