stable/scripts/download_backtest_data.py

67 lines
1.9 KiB
Python
Raw Normal View History

2018-04-22 07:56:49 +00:00
#!/usr/bin/env python3
"""This script generate json data from bittrex"""
import json
import sys
import os
import arrow
from freqtrade import (exchange, arguments, misc)
2018-04-22 07:56:49 +00:00
arguments = arguments.Arguments(sys.argv[1:], 'download utility')
arguments.testdata_dl_options()
args = arguments.parse_args()
# Added exchange as a subdirectory to download into
# as Freqtrad now supports multiple exchanges.
DEFAULT_DL_PATH = 'freqtrade/tests/testdata/' + args.exchange
DEFAULT_PAIR_FILE = DEFAULT_DL_PATH + "/" + "pairs.json"
2018-04-22 07:56:49 +00:00
TICKER_INTERVALS = ['1m', '5m']
PAIRS = []
# Added a check for a default pairs file in per exchange specific dir
2018-04-22 07:56:49 +00:00
if args.pairs_file:
with open(args.pairs_file) as file:
PAIRS = json.load(file)
elif os.path.isfile(DEFAULT_PAIR_FILE) is True:
with open(DEFAULT_PAIR_FILE) as file:
PAIRS = json.load(file)
2018-04-22 07:56:49 +00:00
PAIRS = list(set(PAIRS))
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
2018-04-22 07:56:49 +00:00
print(f'About to download pairs: {PAIRS} to {dl_path}')
# Init exchange
2018-04-22 07:56:49 +00:00
exchange._API = exchange.init_ccxt({'key': '',
'secret': '',
'name': args.exchange})
2018-04-22 07:56:49 +00:00
2018-04-22 07:56:49 +00:00
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_ms=since_time)
if not data:
print('\tNo data was downloaded')
break
2018-04-27 21:30:42 +00:00
print('\tData was downloaded for period %s - %s' % (
arrow.get(data[0][0] / 1000).format(),
arrow.get(data[-1][0] / 1000).format()))
# save data
2018-04-22 07:56:49 +00:00
pair_print = pair.replace('/', '_')
filename = f'{pair_print}-{tick_interval}.json'
misc.file_dump_json(os.path.join(dl_path, filename), data)