forked from llSourcell/bitcoin_prediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Continuous_Stream_Data.py
33 lines (25 loc) · 983 Bytes
/
Continuous_Stream_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
# coding: utf-8
# In[1]:
import requests
import time
import datetime
f_name = input("dataset name:")
f = open(f_name,"a")
keys = ["price_usd","24h_volume_usd","market_cap_usd","available_supply","total_supply","percent_change_1h","percent_change_24h","percent_change_7d"]
vals = [0]*len(keys)
while True:
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 d in data.keys():
if d in keys:
indx = keys.index(d)
vals[indx] = data[d]
for val in vals:
f.write(val+",")
#f.write("{},{},".format(bstamp["volume"],bstamp["vwap"]))
f.write("{},{},{}".format(bkc["USD"]["sell"],bkc["USD"]["buy"],bkc["USD"]["15m"]))
f.write(","+datetime.datetime.now().strftime("%y-%m-%d-%H-%M"))
f.write("\n")
f.flush()
time.sleep(60)