-
Notifications
You must be signed in to change notification settings - Fork 0
/
btc_logger.py
27 lines (22 loc) · 997 Bytes
/
btc_logger.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
import bitstamp.client
import csv, os
base_path = r"D:\Bitcoin"
# Get data from bitstamp
public_client = bitstamp.client.Public()
currencies_list = ['btc', 'eur', 'xrp', 'ltc', 'eth', 'bch']
for currency in currencies_list:
# Log data to file
row = [public_client.ticker(base=currency, quote="usd")['timestamp'], \
public_client.ticker(base=currency, quote="usd")['volume'], \
public_client.ticker(base=currency, quote="usd")['last'], \
public_client.ticker(base=currency, quote="usd")['high'], \
public_client.ticker(base=currency, quote="usd")['low'], \
public_client.ticker(base=currency, quote="usd")['bid'], \
public_client.ticker(base=currency, quote="usd")['ask'], \
public_client.ticker(base=currency, quote="usd")['vwap'], \
public_client.ticker(base=currency, quote="usd")['open']]
print row
path_data = os.path.join(base_path, "bitstamp_"+currency+"_usd.csv")
with open(path_data, 'ab') as f:
w = csv.writer(f)
w.writerow(row)