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
|
2018-04-27 21:16:34 +00:00
|
|
|
|
import arrow
|
|
|
|
|
|
2018-06-18 20:28:51 +00:00
|
|
|
|
from freqtrade import (arguments, misc)
|
|
|
|
|
from freqtrade.exchange import Exchange
|
2018-04-22 07:56:49 +00:00
|
|
|
|
|
2018-06-04 09:20:17 +00:00
|
|
|
|
DEFAULT_DL_PATH = 'user_data/data'
|
2018-04-22 07:56:49 +00:00
|
|
|
|
|
|
|
|
|
arguments = arguments.Arguments(sys.argv[1:], 'download utility')
|
|
|
|
|
arguments.testdata_dl_options()
|
|
|
|
|
args = arguments.parse_args()
|
|
|
|
|
|
2018-06-04 10:31:52 +00:00
|
|
|
|
timeframes = args.timeframes
|
2018-04-22 07:56:49 +00:00
|
|
|
|
|
2018-06-04 09:58:35 +00:00
|
|
|
|
dl_path = os.path.join(DEFAULT_DL_PATH, args.exchange)
|
|
|
|
|
if args.export:
|
|
|
|
|
dl_path = args.export
|
|
|
|
|
|
2018-06-04 09:20:17 +00:00
|
|
|
|
if not os.path.isdir(dl_path):
|
|
|
|
|
sys.exit(f'Directory {dl_path} does not exist.')
|
|
|
|
|
|
|
|
|
|
pairs_file = args.pairs_file if args.pairs_file else os.path.join(dl_path, 'pairs.json')
|
|
|
|
|
if not os.path.isfile(pairs_file):
|
|
|
|
|
sys.exit(f'No pairs file found with path {pairs_file}.')
|
2018-04-22 07:56:49 +00:00
|
|
|
|
|
2018-06-04 09:20:17 +00:00
|
|
|
|
with open(pairs_file) as file:
|
|
|
|
|
PAIRS = list(set(json.load(file)))
|
2018-04-22 07:56:49 +00:00
|
|
|
|
|
2018-06-11 19:10:57 +00:00
|
|
|
|
PAIRS.sort()
|
|
|
|
|
|
2018-04-27 21:16:34 +00:00
|
|
|
|
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}')
|
|
|
|
|
|
2018-06-18 20:28:51 +00:00
|
|
|
|
|
2018-04-24 23:11:07 +00:00
|
|
|
|
# Init exchange
|
2018-06-18 20:28:51 +00:00
|
|
|
|
exchange = Exchange({'key': '',
|
|
|
|
|
'secret': '',
|
|
|
|
|
'stake_currency': '',
|
|
|
|
|
'dry_run': True,
|
|
|
|
|
'exchange': {
|
|
|
|
|
'name': args.exchange,
|
|
|
|
|
'pair_whitelist': []
|
|
|
|
|
}
|
|
|
|
|
})
|
2018-06-11 19:10:57 +00:00
|
|
|
|
pairs_not_available = []
|
2018-04-27 21:16:34 +00:00
|
|
|
|
|
2018-04-22 07:56:49 +00:00
|
|
|
|
for pair in PAIRS:
|
2018-06-18 20:28:51 +00:00
|
|
|
|
if pair not in exchange._api.markets:
|
2018-06-11 19:10:57 +00:00
|
|
|
|
pairs_not_available.append(pair)
|
|
|
|
|
print(f"skipping pair {pair}")
|
|
|
|
|
continue
|
2018-06-04 10:31:52 +00:00
|
|
|
|
for tick_interval in timeframes:
|
2018-04-22 07:56:49 +00:00
|
|
|
|
print(f'downloading pair {pair}, interval {tick_interval}')
|
2018-04-24 23:11:07 +00:00
|
|
|
|
|
2018-04-30 21:27:05 +00:00
|
|
|
|
data = exchange.get_ticker_history(pair, tick_interval, since_ms=since_time)
|
2018-04-27 21:16:34 +00:00
|
|
|
|
if not data:
|
|
|
|
|
print('\tNo data was downloaded')
|
|
|
|
|
break
|
2018-04-27 21:30:42 +00:00
|
|
|
|
|
2018-04-27 21:16:34 +00:00
|
|
|
|
print('\tData was downloaded for period %s - %s' % (
|
|
|
|
|
arrow.get(data[0][0] / 1000).format(),
|
|
|
|
|
arrow.get(data[-1][0] / 1000).format()))
|
2018-04-24 23:11:07 +00:00
|
|
|
|
|
|
|
|
|
# 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)
|
2018-06-11 19:10:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pairs_not_available:
|
|
|
|
|
print(f"Pairs [{','.join(pairs_not_available)}] not availble.")
|