cryptodatapy 0.2.6__py3-none-any.whl → 0.2.7__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.
- cryptodatapy/conf/fields.csv +1 -1
- cryptodatapy/extract/datarequest.py +142 -27
- cryptodatapy/extract/libraries/Untitled.ipynb +33 -0
- cryptodatapy/extract/libraries/ccxt.ipynb +747 -0
- cryptodatapy/extract/libraries/ccxt_api.py +629 -356
- cryptodatapy/extract/libraries/pandasdr_api.py +13 -12
- cryptodatapy/extract/libraries/yfinance_api.py +511 -0
- cryptodatapy/transform/clean_perp_futures_ohlcv.ipynb +226 -30
- cryptodatapy/transform/cmdty_data.ipynb +402 -0
- cryptodatapy/transform/convertparams.py +114 -166
- cryptodatapy/transform/eqty_data.ipynb +126 -99
- cryptodatapy/transform/wrangle.py +109 -20
- {cryptodatapy-0.2.6.dist-info → cryptodatapy-0.2.7.dist-info}/METADATA +9 -6
- {cryptodatapy-0.2.6.dist-info → cryptodatapy-0.2.7.dist-info}/RECORD +16 -12
- {cryptodatapy-0.2.6.dist-info → cryptodatapy-0.2.7.dist-info}/WHEEL +1 -1
- {cryptodatapy-0.2.6.dist-info → cryptodatapy-0.2.7.dist-info}/LICENSE +0 -0
@@ -13,10 +13,7 @@ class ConvertParams:
|
|
13
13
|
Converts data request parameters from CryptoDataPy to data source format.
|
14
14
|
"""
|
15
15
|
|
16
|
-
def __init__(
|
17
|
-
self,
|
18
|
-
data_req: DataRequest = None,
|
19
|
-
):
|
16
|
+
def __init__(self, data_req: DataRequest):
|
20
17
|
"""
|
21
18
|
Constructor
|
22
19
|
|
@@ -24,7 +21,6 @@ class ConvertParams:
|
|
24
21
|
----------
|
25
22
|
data_req: DataRequest
|
26
23
|
Parameters of data request in CryptoDataPy format.
|
27
|
-
|
28
24
|
"""
|
29
25
|
self.data_req = data_req
|
30
26
|
|
@@ -69,7 +65,7 @@ class ConvertParams:
|
|
69
65
|
start_date = round(pd.Timestamp(self.data_req.start_date).timestamp())
|
70
66
|
# convert end date
|
71
67
|
if self.data_req.end_date is None:
|
72
|
-
end_date = round(pd.Timestamp
|
68
|
+
end_date = round(pd.Timestamp.utcnow()).timestamp()
|
73
69
|
else:
|
74
70
|
end_date = round(pd.Timestamp(self.data_req.end_date).timestamp())
|
75
71
|
# fields
|
@@ -401,7 +397,7 @@ class ConvertParams:
|
|
401
397
|
start_date = self.data_req.start_date
|
402
398
|
# convert end date
|
403
399
|
if self.data_req.end_date is None:
|
404
|
-
end_date =
|
400
|
+
end_date = pd.Timestamp.utcnow()
|
405
401
|
else:
|
406
402
|
end_date = self.data_req.end_date
|
407
403
|
# convert fields
|
@@ -437,149 +433,109 @@ class ConvertParams:
|
|
437
433
|
"source_fields": self.data_req.source_fields,
|
438
434
|
}
|
439
435
|
|
440
|
-
def to_ccxt(self) ->
|
436
|
+
def to_ccxt(self) -> DataRequest:
|
441
437
|
"""
|
442
438
|
Convert tickers from CryptoDataPy to CCXT format.
|
443
439
|
"""
|
444
|
-
#
|
445
|
-
if self.data_req.source_tickers is
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
# convert freq
|
451
|
-
if self.data_req.source_freq is not None:
|
452
|
-
freq = self.data_req.source_freq
|
453
|
-
self.data_req.freq = self.data_req.source_freq
|
454
|
-
else:
|
440
|
+
# tickers
|
441
|
+
if self.data_req.source_tickers is None:
|
442
|
+
self.data_req.source_tickers = [ticker.upper() for ticker in self.data_req.tickers]
|
443
|
+
|
444
|
+
# freq
|
445
|
+
if self.data_req.source_freq is None:
|
455
446
|
if self.data_req.freq is None:
|
456
|
-
|
447
|
+
self.data_req.source_freq = "1d"
|
457
448
|
elif self.data_req.freq == "tick":
|
458
|
-
|
449
|
+
self.data_req.source_freq = "tick"
|
459
450
|
elif self.data_req.freq[-3:] == "min":
|
460
|
-
|
451
|
+
self.data_req.source_freq = self.data_req.freq.replace("min", "m")
|
452
|
+
elif self.data_req.freq[-1] == "h":
|
453
|
+
self.data_req.source_freq = self.data_req.freq
|
461
454
|
elif self.data_req.freq == "w":
|
462
|
-
|
455
|
+
self.data_req.source_freq = "1w"
|
463
456
|
elif self.data_req.freq == "m":
|
464
|
-
|
457
|
+
self.data_req.source_freq = "1M"
|
465
458
|
elif self.data_req.freq[-1] == "m":
|
466
|
-
|
459
|
+
self.data_req.source_freq = self.data_req.freq.replace("m", "M")
|
467
460
|
elif self.data_req.freq == "q":
|
468
|
-
|
461
|
+
self.data_req.source_freq = "1q"
|
469
462
|
elif self.data_req.freq == "y":
|
470
|
-
|
463
|
+
self.data_req.source_freq = "1y"
|
471
464
|
else:
|
472
|
-
|
473
|
-
|
465
|
+
self.data_req.source_freq = "1d"
|
466
|
+
|
467
|
+
# quote ccy
|
474
468
|
if self.data_req.quote_ccy is None:
|
475
|
-
quote_ccy = "USDT"
|
469
|
+
self.data_req.quote_ccy = "USDT"
|
476
470
|
else:
|
477
|
-
quote_ccy = self.data_req.quote_ccy.upper()
|
478
|
-
|
471
|
+
self.data_req.quote_ccy = self.data_req.quote_ccy.upper()
|
472
|
+
|
473
|
+
# exch
|
479
474
|
if self.data_req.mkt_type == "perpetual_future" and (
|
480
475
|
self.data_req.exch is None or self.data_req.exch == "binance"
|
481
476
|
):
|
482
|
-
exch = "binanceusdm"
|
477
|
+
self.data_req.exch = "binanceusdm"
|
483
478
|
elif self.data_req.exch is None:
|
484
|
-
exch = "binance"
|
479
|
+
self.data_req.exch = "binance"
|
485
480
|
elif (
|
486
481
|
self.data_req.exch == "kucoin"
|
487
482
|
and self.data_req.mkt_type == "perpetual_future"
|
488
483
|
):
|
489
|
-
exch = "kucoinfutures"
|
484
|
+
self.data_req.exch = "kucoinfutures"
|
490
485
|
elif (
|
491
486
|
self.data_req.exch == "huobi"
|
492
487
|
and self.data_req.mkt_type == "perpetual_future"
|
493
488
|
):
|
494
|
-
exch = "huobipro"
|
489
|
+
self.data_req.exch = "huobipro"
|
495
490
|
elif (
|
496
491
|
self.data_req.exch == "bitfinex"
|
497
492
|
and self.data_req.mkt_type == "perpetual_future"
|
498
493
|
):
|
499
|
-
exch = "bitfinex2"
|
494
|
+
self.data_req.exch = "bitfinex2"
|
500
495
|
elif (
|
501
496
|
self.data_req.exch == "mexc"
|
502
497
|
and self.data_req.mkt_type == "perpetual_future"
|
503
498
|
):
|
504
|
-
exch = "mexc3"
|
499
|
+
self.data_req.exch = "mexc3"
|
505
500
|
else:
|
506
|
-
exch = self.data_req.exch.lower()
|
507
|
-
|
508
|
-
|
509
|
-
if self.data_req.
|
510
|
-
|
501
|
+
self.data_req.exch = self.data_req.exch.lower()
|
502
|
+
|
503
|
+
# markets
|
504
|
+
if self.data_req.source_markets is None:
|
505
|
+
if self.data_req.mkt_type == "spot":
|
506
|
+
self.data_req.source_markets = [ticker + "/" + self.data_req.quote_ccy
|
507
|
+
for ticker in self.data_req.source_tickers]
|
508
|
+
elif self.data_req.mkt_type == "perpetual_future":
|
509
|
+
self.data_req.source_markets = [ticker + "/" + self.data_req.quote_ccy + ":" + self.data_req.quote_ccy
|
510
|
+
for ticker in self.data_req.source_tickers]
|
511
511
|
else:
|
512
|
-
for
|
513
|
-
|
514
|
-
|
515
|
-
elif self.data_req.mkt_type == "perpetual_future":
|
516
|
-
if exch == "binanceusdm":
|
517
|
-
mkts_list.append(ticker.upper() + "/" + quote_ccy.upper() + ':' + quote_ccy.upper())
|
518
|
-
elif (
|
519
|
-
exch == "ftx"
|
520
|
-
or exch == "okx"
|
521
|
-
or exch == "kucoinfutures"
|
522
|
-
or exch == "huobipro"
|
523
|
-
or exch == "cryptocom"
|
524
|
-
or exch == "bitfinex2"
|
525
|
-
or exch == "bybit"
|
526
|
-
or exch == "mexc3"
|
527
|
-
or exch == "aax"
|
528
|
-
or exch == "bitmex"
|
529
|
-
):
|
530
|
-
mkts_list.append(
|
531
|
-
ticker.upper()
|
532
|
-
+ "/"
|
533
|
-
+ quote_ccy.upper()
|
534
|
-
+ ":"
|
535
|
-
+ quote_ccy.upper()
|
536
|
-
)
|
537
|
-
# convert start date
|
512
|
+
self.data_req.source_tickers = [market.split("/")[0] for market in self.data_req.source_markets]
|
513
|
+
|
514
|
+
# start date
|
538
515
|
if self.data_req.start_date is None:
|
539
|
-
|
516
|
+
self.data_req.source_start_date = round(
|
540
517
|
pd.Timestamp("2010-01-01 00:00:00").timestamp() * 1e3
|
541
518
|
)
|
542
519
|
else:
|
543
|
-
|
520
|
+
self.data_req.source_start_date = round(
|
544
521
|
pd.Timestamp(self.data_req.start_date).timestamp() * 1e3
|
545
522
|
)
|
546
|
-
|
523
|
+
|
524
|
+
# end date
|
547
525
|
if self.data_req.end_date is None:
|
548
|
-
|
549
|
-
else:
|
550
|
-
end_date = round(pd.Timestamp(self.data_req.end_date).timestamp() * 1e3)
|
551
|
-
# convert fields
|
552
|
-
if self.data_req.source_fields is not None:
|
553
|
-
fields = self.data_req.source_fields
|
554
|
-
self.data_req.fields = self.data_req.source_fields
|
526
|
+
self.data_req.source_end_date = round(pd.Timestamp.utcnow().timestamp() * 1e3)
|
555
527
|
else:
|
556
|
-
|
528
|
+
self.data_req.source_end_date = round(pd.Timestamp(self.data_req.end_date).timestamp() * 1e3)
|
529
|
+
|
530
|
+
# fields
|
531
|
+
if self.data_req.source_fields is None:
|
532
|
+
self.data_req.source_fields = self.convert_fields(data_source='ccxt')
|
533
|
+
|
557
534
|
# tz
|
558
535
|
if self.data_req.tz is None:
|
559
|
-
tz = "UTC"
|
560
|
-
else:
|
561
|
-
tz = self.data_req.tz
|
536
|
+
self.data_req.tz = "UTC"
|
562
537
|
|
563
|
-
return
|
564
|
-
"tickers": tickers,
|
565
|
-
"freq": freq,
|
566
|
-
"quote_ccy": quote_ccy,
|
567
|
-
"exch": exch,
|
568
|
-
"ctys": None,
|
569
|
-
"mkt_type": self.data_req.mkt_type,
|
570
|
-
"mkts": mkts_list,
|
571
|
-
"start_date": start_date,
|
572
|
-
"end_date": end_date,
|
573
|
-
"fields": fields,
|
574
|
-
"tz": tz,
|
575
|
-
"inst": None,
|
576
|
-
"cat": 'crypto',
|
577
|
-
"trials": self.data_req.trials,
|
578
|
-
"pause": self.data_req.pause,
|
579
|
-
"source_tickers": self.data_req.source_tickers,
|
580
|
-
"source_freq": self.data_req.source_freq,
|
581
|
-
"source_fields": self.data_req.source_fields,
|
582
|
-
}
|
538
|
+
return self.data_req
|
583
539
|
|
584
540
|
def to_dbnomics(self) -> Dict[str, Union[list, str, int, float, None]]:
|
585
541
|
"""
|
@@ -694,7 +650,7 @@ class ConvertParams:
|
|
694
650
|
start_date = pd.Timestamp(self.data_req.start_date).strftime("%d/%m/%Y")
|
695
651
|
# convert end date
|
696
652
|
if self.data_req.end_date is None:
|
697
|
-
end_date =
|
653
|
+
end_date = pd.Timestamp.utcnow().strftime("%d/%m/%Y")
|
698
654
|
else:
|
699
655
|
end_date = pd.Timestamp(self.data_req.end_date).strftime("%d/%m/%Y")
|
700
656
|
# convert fields
|
@@ -762,7 +718,7 @@ class ConvertParams:
|
|
762
718
|
start_date = self.data_req.start_date
|
763
719
|
# end date
|
764
720
|
if self.data_req.end_date is None:
|
765
|
-
end_date =
|
721
|
+
end_date = pd.Timestamp.utcnow()
|
766
722
|
else:
|
767
723
|
end_date = self.data_req.end_date
|
768
724
|
# fields
|
@@ -852,7 +808,7 @@ class ConvertParams:
|
|
852
808
|
start_date = int(self.data_req.start_date.year)
|
853
809
|
# end date
|
854
810
|
if self.data_req.end_date is None:
|
855
|
-
end_date =
|
811
|
+
end_date = pd.Timestamp.utcnow().year
|
856
812
|
else:
|
857
813
|
end_date = int(self.data_req.end_date.year)
|
858
814
|
# fields
|
@@ -886,80 +842,72 @@ class ConvertParams:
|
|
886
842
|
def to_yahoo(self) -> Dict[str, Union[list, str, int, float, datetime, None]]:
|
887
843
|
"""
|
888
844
|
Convert tickers from CryptoDataPy to Yahoo Finance format.
|
889
|
-
|
890
845
|
"""
|
891
|
-
#
|
846
|
+
# tickers
|
892
847
|
with resources.path("cryptodatapy.conf", "tickers.csv") as f:
|
893
848
|
tickers_path = f
|
894
849
|
tickers_df, tickers = pd.read_csv(tickers_path, index_col=0, encoding="latin1"), []
|
895
850
|
|
896
|
-
if self.data_req.source_tickers is
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
self.data_req.freq = self.data_req.source_freq
|
917
|
-
else:
|
918
|
-
freq = self.data_req.freq
|
919
|
-
# convert quote ccy
|
920
|
-
quote_ccy = self.data_req.quote_ccy
|
851
|
+
if self.data_req.source_tickers is None:
|
852
|
+
if self.data_req.cat == 'eqty':
|
853
|
+
self.data_req.source_tickers = [ticker.upper() for ticker in self.data_req.tickers]
|
854
|
+
else:
|
855
|
+
self.data_req.source_tickers = []
|
856
|
+
for ticker in self.data_req.tickers:
|
857
|
+
if self.data_req.cat == 'fx':
|
858
|
+
ticker = ticker.upper()
|
859
|
+
try:
|
860
|
+
self.data_req.source_tickers.append(tickers_df.loc[ticker, "yahoo_id"])
|
861
|
+
except KeyError:
|
862
|
+
logging.warning(
|
863
|
+
f"{ticker} not found for Yahoo Finance data source. Check tickers in"
|
864
|
+
f" data catalog and try again."
|
865
|
+
)
|
866
|
+
|
867
|
+
# freq
|
868
|
+
if self.data_req.source_freq is None:
|
869
|
+
self.data_req.source_freq = self.data_req.freq
|
870
|
+
|
921
871
|
# start date
|
922
872
|
if self.data_req.start_date is None:
|
923
|
-
|
873
|
+
self.data_req.source_start_date = '1920-01-01'
|
924
874
|
else:
|
925
|
-
|
875
|
+
self.data_req.source_start_date = self.data_req.start_date
|
876
|
+
|
926
877
|
# end date
|
927
878
|
if self.data_req.end_date is None:
|
928
|
-
|
879
|
+
self.data_req.source_end_date = pd.Timestamp.utcnow().strftime('%Y-%m-%d')
|
929
880
|
else:
|
930
|
-
|
881
|
+
self.data_req.source_end_date = self.data_req.end_date
|
882
|
+
|
931
883
|
# fields
|
932
|
-
if self.data_req.source_fields is
|
933
|
-
|
934
|
-
|
935
|
-
else:
|
936
|
-
fields = self.convert_fields(data_source='yahoo')
|
884
|
+
if self.data_req.source_fields is None:
|
885
|
+
self.data_req.source_fields = self.convert_fields(data_source='yahoo')
|
886
|
+
|
937
887
|
# tz
|
938
888
|
if self.data_req.tz is None:
|
939
|
-
tz = "America/New_York"
|
940
|
-
else:
|
941
|
-
tz = self.data_req.tz
|
889
|
+
self.data_req.tz = "America/New_York"
|
942
890
|
|
943
|
-
return {
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
}
|
891
|
+
# return {
|
892
|
+
# "tickers": tickers,
|
893
|
+
# "freq": freq,
|
894
|
+
# "quote_ccy": quote_ccy,
|
895
|
+
# "exch": self.data_req.exch,
|
896
|
+
# "ctys": None,
|
897
|
+
# "mkt_type": self.data_req.mkt_type,
|
898
|
+
# "mkts": None,
|
899
|
+
# "start_date": start_date,
|
900
|
+
# "end_date": end_date,
|
901
|
+
# "fields": fields,
|
902
|
+
# "tz": tz,
|
903
|
+
# "inst": None,
|
904
|
+
# "cat": self.data_req.cat,
|
905
|
+
# "trials": self.data_req.trials,
|
906
|
+
# "pause": self.data_req.pause,
|
907
|
+
# "source_tickers": self.data_req.source_tickers,
|
908
|
+
# "source_freq": self.data_req.source_freq,
|
909
|
+
# "source_fields": self.data_req.source_fields,
|
910
|
+
# }
|
963
911
|
|
964
912
|
def to_famafrench(self) -> Dict[str, Union[list, str, int, float, datetime, None]]:
|
965
913
|
"""
|
@@ -998,7 +946,7 @@ class ConvertParams:
|
|
998
946
|
start_date = self.data_req.start_date
|
999
947
|
# end date
|
1000
948
|
if self.data_req.end_date is None:
|
1001
|
-
end_date =
|
949
|
+
end_date = pd.Timestamp.utcnow().date()
|
1002
950
|
else:
|
1003
951
|
end_date = self.data_req.end_date
|
1004
952
|
|