-
Notifications
You must be signed in to change notification settings - Fork 142
/
util.py
executable file
·81 lines (69 loc) · 2.28 KB
/
util.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
import requests
maxs =[]
mins =[]
def loadData(f_name):
data = f_name.read().split("\n")
data = data[:len(data)-1]
label = []
for i in range(len(data)):
data[i] = data[i].split(",")
data[i] = [float(x) for x in data[i]]
label.append(data[i][len(data[i])-1])
data[i] = data[i][0:len(data[i])-1]
return data[:-2],label[2:] #Removing first two and last two so each X[i] tries to predict Y[i+2] (i've used i+2 and not to i+1 to force it to predict the future (O) )
def reduceVector(vec,getVal=False):
vect = []
mx,mn = max(vec),min(vec)
mx = mx+mn
mn = mn-((mx-mn)*0.4)
for x in vec:
vect.append((x-mn)/(mx-mn))
if not getVal:return vect
else:return vect,mx,mn
def reduceValue(x,mx,mn):
return (x-mn)/(mx-mn)
def augmentValue(x,mx,mn):
return (mx-mn)*x+mn
def reduceMatRows(data):
l = len(data[0])
for i in range(l):
v = []
for t in range(len(data)):
v.append(data[t][i])
v,mx,mn = reduceVector(v,getVal=True)
maxs.append(mx)
mins.append(mn)
for t in range(len(data)):
data[t][i] = v[t]
return data
def reduceCurrent(data):
for i in range(len(data)):
data[i] = reduceValue(data[i],maxs[i],mins[i])
return data
def getCurrentData(label=False):
keys = ["price_usd","24h_volume_usd","market_cap_usd","available_supply","total_supply","percent_change_1h","percent_change_24h","percent_change_7d"]
vect = []
data = requests.get("https://api.coinmarketcap.com/v1/ticker/bitcoin/").json()[0]
bstamp = requests.get("https://www.bitstamp.net/api/v2/ticker/btcusd/").json()
bkc = requests.get("https://blockchain.info/ticker").json()
'''
for i in data.keys():
if i in keys:
vect.append(float(data[i]))
'''
for k in keys:
for d in data.keys():
if k == d:
vect.append(float(data[d]))
vect.append(float(bstamp["volume"]))
vect.append(float(bstamp["vwap"]))
vect.append(float(bkc["USD"]["sell"]))
vect.append(float(bkc["USD"]["buy"]))
#print("blockchain.info ",float(bkc["USD"]["15m"]))
if label:
return vect,float(bkc["USD"]["15m"])
return vect
def getCEXData():
data = requests.get("https://cex.io/api/ticker/BTC/USD").json()
#print("CEX ",data)
return data