Add time range support to download_backtest_data
This commit is contained in:
parent
9f1544978d
commit
6675120324
@ -265,3 +265,17 @@ class Arguments(object):
|
||||
help='Export files to given dir',
|
||||
dest='export',
|
||||
default=None)
|
||||
|
||||
self.parser.add_argument(
|
||||
'--days',
|
||||
help='Download data for number of days',
|
||||
dest='days',
|
||||
type=int,
|
||||
default=None)
|
||||
|
||||
self.parser.add_argument(
|
||||
'--exchange',
|
||||
help='Exchange name',
|
||||
dest='exchange',
|
||||
type=str,
|
||||
default='bittrex')
|
@ -45,7 +45,7 @@ def retrier(f):
|
||||
return wrapper
|
||||
|
||||
|
||||
def init_ccxt(exchange_config: dict) -> ccxt:
|
||||
def init_ccxt(exchange_config: dict) -> ccxt.Exchange:
|
||||
"""
|
||||
Initialize ccxt with given config and return valid
|
||||
ccxt instance.
|
||||
@ -62,7 +62,7 @@ def init_ccxt(exchange_config: dict) -> ccxt:
|
||||
'apiKey': exchange_config.get('key'),
|
||||
'secret': exchange_config.get('secret'),
|
||||
'password': exchange_config.get('password'),
|
||||
'uid': exchange_config.get('uid' ''),
|
||||
'uid': exchange_config.get('uid', ''),
|
||||
'enableRateLimit': True,
|
||||
})
|
||||
except (KeyError, AttributeError):
|
||||
@ -269,9 +269,9 @@ def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
|
||||
|
||||
|
||||
@retrier
|
||||
def get_ticker_history(pair: str, tick_interval: str) -> List[Dict]:
|
||||
def get_ticker_history(pair: str, tick_interval: str, since: Optional[int] = None) -> List[Dict]:
|
||||
try:
|
||||
return _API.fetch_ohlcv(pair, timeframe=tick_interval)
|
||||
return _API.fetch_ohlcv(pair, timeframe=tick_interval, since=since)
|
||||
except ccxt.NetworkError as e:
|
||||
raise NetworkException(
|
||||
'Could not load ticker history due to networking error. Message: {}'.format(e)
|
||||
|
@ -4,8 +4,8 @@
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
|
||||
from freqtrade import (exchange, arguments, misc)
|
||||
import time
|
||||
import datetime
|
||||
|
||||
DEFAULT_DL_PATH = 'freqtrade/tests/testdata'
|
||||
|
||||
@ -15,6 +15,9 @@ 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:
|
||||
@ -27,15 +30,36 @@ if args.export and os.path.exists(args.export):
|
||||
|
||||
print(f'About to download pairs: {PAIRS} to {dl_path}')
|
||||
|
||||
# Init Bittrex exchange
|
||||
# Init exchange
|
||||
exchange._API = exchange.init_ccxt({'key': '',
|
||||
'secret': '',
|
||||
'name': 'bittrex'})
|
||||
'name': args.exchange})
|
||||
|
||||
for pair in PAIRS:
|
||||
for tick_interval in TICKER_INTERVALS:
|
||||
print(f'downloading pair {pair}, interval {tick_interval}')
|
||||
data = exchange.get_ticker_history(pair, 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
|
||||
|
||||
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
|
||||
|
||||
# save data
|
||||
pair_print = pair.replace('/', '_')
|
||||
filename = f'{pair_print}-{tick_interval}.json'
|
||||
misc.file_dump_json(os.path.join(dl_path, filename), data)
|
||||
|
Loading…
Reference in New Issue
Block a user