-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_assets_data.py
130 lines (104 loc) · 3.19 KB
/
get_assets_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from typing import List
from trading_gym.envs.data_loader import CryptoData
import numpy as np
from datetime import datetime
from tqdm import tqdm
def get_assets_data(start: datetime, end: datetime) -> List[List[str]]:
"""
Get assets data.
Parameters
----------
n_symbols: int
Number of symbols in each universe.
n_universes: int
Number of universes to generate.
start: datetime
Start date.
end: datetime
End date.
Returns
-------
random_universes: List[List[str]]
List of random universes.
"""
cd = CryptoData()
supported_symbols = cd.supported_symbols
symbols_filtered = [
symbol
for symbol in supported_symbols
if (symbol.endswith("USDT") or symbol.endswith("BUSD"))
and not symbol.startswith("USDT")
and not symbol.startswith("SUSD")
and not symbol.startswith("USDS")
and not symbol.startswith("BUSD")
and not symbol.startswith("USDC")
and not symbol.startswith("TUSD")
and not symbol.startswith("DAI")
and not symbol.startswith("PAX")
and not symbol.startswith("EUR")
and not symbol.startswith("MDX")
and not symbol.startswith("AUD")
and not symbol.startswith("GBP")
and symbol
not in [
"UNIDOWNUSDT",
"LTCDOWNUSDT",
"SUSHIDOWNUSDT",
"ETHDOWNUSDT",
"BNBDOWNUSDT",
"XLMDOWNUSDT",
"SXPDOWNUSDT",
"TRXDOWNUSDT",
"YFIDOWNUSDT",
"XTZDOWNUSDT",
"AAVEDOWNUSDT",
"DOTDOWNUSDT",
"LINKDOWNUSDT",
"ADADOWNUSDT",
"XRPDOWNUSDT",
"COCOSUSDT",
]
]
symbols = {}
for symbol in symbols_filtered:
if "USDT" in symbol:
quote = "USDT"
elif "BUSD" in symbol:
quote = "BUSD"
elif "USDC" in symbol:
quote = "USDC"
else:
continue
s = symbol.replace(quote, "")
if s in symbols:
continue
else:
symbols[s] = symbol
symbols = list(symbols.values())
print("Downloading data")
assets_data = cd.get_data(start=start, end=end, universe=symbols)
return assets_data
if __name__ == "__main__":
import pickle
from datetime import datetime
import pandas as pd
# TRAINING V1
# start = datetime(2019, 5, 1)
# end = datetime(2021, 9, 30)
# TRAINING V2
# start = datetime(2018, 5, 1)
# end = datetime(2021, 1, 1)
# TESTING V1
start = datetime(2020, 5, 1)
end = datetime(2022, 1, 21)
assets_data = get_assets_data(start, end)
pickle.dump(assets_data, open("./assets_data_testing.pickle", "wb"))
# UPDATE EXISTING TESTING DATA
# start = datetime(2022, 1, 12)
# end = datetime(2022, 1, 17)
# assets_data = pickle.load(open("./assets_data_testing.pickle", "rb"))
# tmp = get_assets_data(start, end)
# assets_data_updated = {}
# for k in assets_data:
# assets_data_updated[k] = pd.concat([assets_data[k], tmp[k]])
# pickle.dump(assets_data_updated, open("./assets_data_testing.pickle", "wb"))