-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathload_update_tickers.py
71 lines (53 loc) · 2.46 KB
/
load_update_tickers.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
#######################
# Author: slurpxbt
#######################
import binance_candle_data as bcd
import datetime
from pathlib import Path
import pickle
import os
import time
def load_and_update_tickers(tickers, candle_intervals):
root = Path(".") # set root for filepath to current directory
# start date
s_day = 21
s_month = 8
s_year = 2017
startDate = datetime.datetime(s_year, s_month, s_day)
yesterday = datetime.datetime.today() - datetime.timedelta(days=1) # 5----1
endDate = datetime.datetime(yesterday.year, yesterday.month, yesterday.day, 22, 0, 0) # 14----22
# load/update tickers|
load_update_tickers = True
# if we want to load or update tickers
if load_update_tickers == True:
# check if directory for data exists -> if not it creates it
if os.path.isdir(f"{root}/data") == False:
os.mkdir(f"{root}/data")
else:
pass
# load or update every ticker in tickers list
for ticker in tickers:
time.sleep(1)
for candle_interval in candle_intervals:
start = time.time()
# data path where we want to have data
data_path = f"{root}/data/{ticker}_{candle_interval}.p"
# checks if file with ticker data already exists
if os.path.exists(data_path) == False:
# get data
daily_data = bcd.get_candle_data(time_interval=candle_interval,symbol=ticker, start_date=startDate, end_date=endDate)
# dumps downloaded data into file
pickle.dump(daily_data, open(data_path,"wb"))
print(f"data load for {ticker} {candle_interval} took", round(time.time() - start, 2), "s")
else:
bcd.update_candle_data(data_path, ticker, update_date=endDate)
print(f"data update for {ticker} {candle_interval} took", round(time.time() - start, 2), "s")
else:
pass
# TODO: Change tickers and intervals
candle_intervals = ["1min", "3min", "5min", "15min", "30min", "1h", "4h", "6h", "12h","1D"]
tickers = ["BTCUSDT", "ETHUSDT"]
candle_intervals_bybitAlts = ["15min", "1h", "4h", "12h"]
tickers_bybitAlts = ["AAVEUSDT", "UNIUSDT","SOLUSDT", "DOTUSDT", "LINKUSDT", "SUSHIUSDT"]
load_and_update_tickers(tickers, candle_intervals)
load_and_update_tickers(tickers_bybitAlts, candle_intervals_bybitAlts)