-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_data.py
39 lines (26 loc) · 1.06 KB
/
get_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
33
34
35
36
37
38
39
#from requests.models import CaseInsensitivDict
from sample_config import API_SECRET, API_KEY
import config, csv
from binance import Client
client = Client(config.API_KEY, config.API_SECRET)
print("API key secured")
#btc_price = client.get_symbol_ticker(symbol="BTCUSDT")
#prices = client.get_all_tickers()
#for price in prices:
# print(price)
#candles = client.get_klines(symbol='BTCUSDT', interval=Client.KLINE_INTERVAL_5MINUTE)
candles = client.get_historical_klines("BTCUSDT", Client.KLINE_INTERVAL_15MINUTE, "1 Jan, 2021", "25 Mar, 2021")
print("opening csv files")
csvfile = open('BTC_BIN_HIS_5min.csv', 'w', newline='')
#csvfile = open('BTC_BIN_HIST_5min.csv', 'w', newline='')
candlestick_writer = csv.writer(csvfile, delimiter=',')
#kline_writer = csv.writer(csvfile, delimiter=',')
for candlestick in candles:
candlestick[0] = candlestick[0] / 1000
candlestick_writer.writerow(candlestick)
#csvfile.close()
#for kline in klines:
# kline_writer.writerow(kline)
csvfile.close()
#print(len(klines))
print("done")