Fix review comments. Add support of datetime timeganges
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import datetime
|
||||
import arrow
|
||||
|
||||
from freqtrade import (exchange, arguments, misc)
|
||||
|
||||
DEFAULT_DL_PATH = 'freqtrade/tests/testdata'
|
||||
|
||||
@@ -15,9 +16,6 @@ args = arguments.parse_args()
|
||||
|
||||
TICKER_INTERVALS = ['1m', '5m']
|
||||
PAIRS = []
|
||||
MIN_SECCONDS = 60
|
||||
HOUR_SECCONDS = 60 * MIN_SECCONDS
|
||||
DAY_SECCONDS = 24 * HOUR_SECCONDS
|
||||
|
||||
if args.pairs_file:
|
||||
with open(args.pairs_file) as file:
|
||||
@@ -28,6 +26,11 @@ dl_path = DEFAULT_DL_PATH
|
||||
if args.export and os.path.exists(args.export):
|
||||
dl_path = args.export
|
||||
|
||||
since_time = None
|
||||
if args.days:
|
||||
since_time = arrow.utcnow().shift(days=-args.days).timestamp * 1000
|
||||
|
||||
|
||||
print(f'About to download pairs: {PAIRS} to {dl_path}')
|
||||
|
||||
# Init exchange
|
||||
@@ -35,29 +38,19 @@ exchange._API = exchange.init_ccxt({'key': '',
|
||||
'secret': '',
|
||||
'name': args.exchange})
|
||||
|
||||
|
||||
for pair in PAIRS:
|
||||
for tick_interval in TICKER_INTERVALS:
|
||||
print(f'downloading pair {pair}, interval {tick_interval}')
|
||||
|
||||
since_time = None
|
||||
if args.days:
|
||||
since_time = int((time.time() - args.days * DAY_SECCONDS) * 1000)
|
||||
|
||||
# download data until it reaches today now time
|
||||
data = []
|
||||
while not since_time or since_time < (time.time() - 10 * MIN_SECCONDS) * 1000:
|
||||
data_part = exchange.get_ticker_history(pair, tick_interval, since=since_time)
|
||||
|
||||
if not data_part:
|
||||
print('\tNo data since %s' % datetime.datetime.utcfromtimestamp(since_time / 1000).strftime('%Y-%m-%dT%H:%M:%S'))
|
||||
break
|
||||
data = exchange.get_ticker_history(pair, tick_interval, since=since_time)
|
||||
if not data:
|
||||
print('\tNo data was downloaded')
|
||||
break
|
||||
|
||||
print('\tData received for period %s - %s' %
|
||||
(datetime.datetime.utcfromtimestamp(data_part[0][0] / 1000).strftime('%Y-%m-%dT%H:%M:%S'),
|
||||
datetime.datetime.utcfromtimestamp(data_part[-1][0] / 1000).strftime('%Y-%m-%dT%H:%M:%S')))
|
||||
|
||||
data.extend(data_part)
|
||||
since_time = data[-1][0] + 1
|
||||
print('\tData was downloaded for period %s - %s' % (
|
||||
arrow.get(data[0][0] / 1000).format(),
|
||||
arrow.get(data[-1][0] / 1000).format()))
|
||||
|
||||
# save data
|
||||
pair_print = pair.replace('/', '_')
|
||||
|
Reference in New Issue
Block a user