Skip to content

Commit

Permalink
added cex ticker
Browse files Browse the repository at this point in the history
 Changes to be committed:
	modified:   data.db
	modified:   network.py
	modified:   predict.py
	modified:   util.py
  • Loading branch information
teroz committed May 3, 2018
1 parent 6774ce3 commit ba1f809
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Binary file modified data.db
Binary file not shown.
3 changes: 2 additions & 1 deletion network.py
Expand Up @@ -46,13 +46,14 @@ def predictFuture(m1,m2,old_pred,writeToFile=False):
actual = np.array(util.reduceCurrent(actual)).reshape(1,12)
pred = util.augmentValue(net.predict(actual)[0],m1,m2)
pred = float(int(pred[0]*100)/100)
cex = util.getCEXData()
if writeToFile:
f = open("results","a")
f.write("[{}] Actual:{}$ Last Prediction:{}$ Next 9m:{}$\n".format(time.strftime("%H:%M:%S"),latest_p,old_pred,pred))
f.close()

c = conn.cursor()
c.execute("INSERT INTO predict(actual,last,target) VALUES (?,?,?)",(latest_p,old_pred,pred))
c.execute("INSERT INTO predict(actual,last,target,cex_ask) VALUES (?,?,?,?)",(latest_p,old_pred,pred,cex["ask"]))
conn.commit()
print("[{}] Actual:{}$ Last Prediction:{}$ Next 9m:{}$".format(time.strftime("%H:%M:%S"),latest_p,old_pred,pred))
return latest_p,pred
Expand Down
14 changes: 7 additions & 7 deletions predict.py
Expand Up @@ -8,17 +8,17 @@

data = pd.read_sql_query("SELECT * from predict", con, index_col="created")

#print(data.head())
print(data.tail(2))

start = (datetime.datetime.utcnow() - datetime.timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S")
stop = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
print(start)
print(stop)
#print(start)
#print(stop)

selected = data.loc[(start < data.index) & (data.index < stop),'actual']
print(selected)
selected.plot()
plt.show()
#print(selected)
#selected.plot()
#plt.show()



Expand All @@ -32,4 +32,4 @@

plt.plot(selected)
plt.plot([coefficients[0]*x + coefficients[1] for x in range(len(selected))])
plt.show()
plt.show()
7 changes: 7 additions & 0 deletions util.py
Expand Up @@ -49,6 +49,7 @@ def reduceCurrent(data):
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]
Expand All @@ -69,6 +70,12 @@ def getCurrentData(label=False):
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

0 comments on commit ba1f809

Please sign in to comment.