-
Notifications
You must be signed in to change notification settings - Fork 5
/
cryptocoin_experiment_formatter.py
115 lines (98 loc) · 1.86 KB
/
cryptocoin_experiment_formatter.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
from cryptocoin_experiment_xdr import *
import csv
import dateutil.parser as date_parser
import datetime
coin_folder = b'coingecko_snapshot/'
end_date = datetime.datetime(2021, 12, 8, 0, 0, 0, 0)
default_length = 500
# ls coingecko_snapshot/ | grep "\-usd" | grep -o "^[^-]\+" | sed "s/^[^-]*/\tb\"&\","/
coins = [
b"AVAX",
b"ada",
b"algo",
b"atom",
b"axs",
b"bat",
b"bch",
b"bnb",
b"bsv",
b"btc",
b"btt",
b"busd",
b"chz",
b"cro",
b"crv",
b"dai",
b"dash",
b"doge",
b"dot",
b"enj",
b"eos",
b"etc",
b"eth",
b"fil",
b"ftm",
b"gala",
b"hot",
b"icp",
b"link",
b"lrc",
b"luna",
b"mana",
b"matic",
b"mim",
b"near",
b"okb",
b"sand",
b"shib",
b"sol",
b"theta",
b"trx",
b"uni",
b"usdc",
b"usdt",
b"vet",
b"wbtc",
b"xlm",
b"xrp",
b"xtz",
b"zec"
]
def load_coin(coin_name, length):
filename = coin_folder + coin_name +b'-usd-max.csv'
output = {}
with open(filename, 'r') as csvfile:
reader = csv.reader(csvfile)
header_row = True
for row in reader:
if header_row:
print (row)
header_row = False
continue
cur_date = date_parser.parse(row[0], ignoretz = True)
delta = cur_date - end_date
output[delta.days] = (float(row[1]), float(row[3]))
x = Cryptocoin.new()
for i in range(0, len(coin_name)):
x.name.push_back(coin_name[i])
discontinuity = False
(price, volume) = (1, 0)
for i in range(0, length):
idx = i - length
y = DateSnapshot.new()
if not idx in output.keys():
#coingecko seems to have some data issues for SHIB
if (discontinuity):
print(idx, coin)
print("using previous day's volume")
else:
(price, volume) = output[idx]
discontinuity = True
y.volume = volume
y.price = price
x.snapshots.push_back(y)
return x
data = CryptocoinExperiment.new()
for coin in coins:
data.coins.push_back(load_coin(coin, default_length))
data.save_to_file(coin_folder + b'unified_data')