2018-04-22 07:56:49 +00:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2018-08-10 09:08:28 +00:00
|
|
|
|
"""This script generate json data"""
|
2018-04-22 07:56:49 +00:00
|
|
|
|
import json
|
|
|
|
|
import sys
|
2018-06-24 17:52:12 +00:00
|
|
|
|
from pathlib import Path
|
2018-04-27 21:16:34 +00:00
|
|
|
|
import arrow
|
2019-02-20 14:00:35 +00:00
|
|
|
|
from typing import Any, Dict
|
2018-04-27 21:16:34 +00:00
|
|
|
|
|
2019-02-20 14:00:35 +00:00
|
|
|
|
from freqtrade.arguments import Arguments
|
2018-06-24 17:52:12 +00:00
|
|
|
|
from freqtrade.arguments import TimeRange
|
2018-06-18 20:28:51 +00:00
|
|
|
|
from freqtrade.exchange import Exchange
|
2018-12-16 09:33:08 +00:00
|
|
|
|
from freqtrade.data.history import download_pair_history
|
2018-12-25 12:14:28 +00:00
|
|
|
|
from freqtrade.configuration import Configuration, set_loggers
|
2019-02-20 14:00:35 +00:00
|
|
|
|
from freqtrade.misc import deep_merge_dicts
|
2018-06-24 17:52:12 +00:00
|
|
|
|
|
2018-10-04 18:38:30 +00:00
|
|
|
|
import logging
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.INFO,
|
|
|
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
|
|
)
|
|
|
|
|
set_loggers(0)
|
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
|
|
|
|
|
2019-02-20 14:00:35 +00:00
|
|
|
|
arguments = Arguments(sys.argv[1:], 'download utility')
|
2018-04-22 07:56:49 +00:00
|
|
|
|
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-12-25 12:14:28 +00:00
|
|
|
|
if args.config:
|
|
|
|
|
configuration = Configuration(args)
|
2019-02-20 14:00:35 +00:00
|
|
|
|
|
|
|
|
|
config: Dict[str, Any] = {}
|
|
|
|
|
# Now expecting a list of config filenames here, not a string
|
|
|
|
|
for path in args.config:
|
|
|
|
|
print('Using config: %s ...', path)
|
|
|
|
|
# Merge config options, overwriting old values
|
|
|
|
|
config = deep_merge_dicts(configuration._load_config_file(path), config)
|
|
|
|
|
|
2018-12-27 13:29:26 +00:00
|
|
|
|
config['stake_currency'] = ''
|
2018-12-25 12:14:28 +00:00
|
|
|
|
# Ensure we do not use Exchange credentials
|
|
|
|
|
config['exchange']['key'] = ''
|
|
|
|
|
config['exchange']['secret'] = ''
|
|
|
|
|
else:
|
|
|
|
|
config = {'stake_currency': '',
|
|
|
|
|
'dry_run': True,
|
|
|
|
|
'exchange': {
|
|
|
|
|
'name': args.exchange,
|
|
|
|
|
'key': '',
|
|
|
|
|
'secret': '',
|
|
|
|
|
'pair_whitelist': [],
|
|
|
|
|
'ccxt_async_config': {
|
|
|
|
|
"enableRateLimit": False
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dl_path = Path(DEFAULT_DL_PATH).joinpath(config['exchange']['name'])
|
2018-06-04 09:58:35 +00:00
|
|
|
|
if args.export:
|
2018-06-24 17:52:12 +00:00
|
|
|
|
dl_path = Path(args.export)
|
2018-06-04 09:58:35 +00:00
|
|
|
|
|
2018-06-24 17:52:12 +00:00
|
|
|
|
if not dl_path.is_dir():
|
2018-06-04 09:20:17 +00:00
|
|
|
|
sys.exit(f'Directory {dl_path} does not exist.')
|
|
|
|
|
|
2018-06-24 17:52:12 +00:00
|
|
|
|
pairs_file = Path(args.pairs_file) if args.pairs_file else dl_path.joinpath('pairs.json')
|
|
|
|
|
if not pairs_file.exists():
|
2018-06-04 09:20:17 +00:00
|
|
|
|
sys.exit(f'No pairs file found with path {pairs_file}.')
|
2018-04-22 07:56:49 +00:00
|
|
|
|
|
2018-06-24 17:52:12 +00:00
|
|
|
|
with pairs_file.open() as file:
|
2018-06-04 09:20:17 +00:00
|
|
|
|
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-06-24 17:52:12 +00:00
|
|
|
|
|
|
|
|
|
timerange = TimeRange()
|
2018-04-27 21:16:34 +00:00
|
|
|
|
if args.days:
|
2018-06-24 17:52:12 +00:00
|
|
|
|
time_since = arrow.utcnow().shift(days=-args.days).strftime("%Y%m%d")
|
|
|
|
|
timerange = arguments.parse_timerange(f'{time_since}-')
|
2018-04-27 21:16:34 +00:00
|
|
|
|
|
|
|
|
|
|
2018-04-22 07:56:49 +00:00
|
|
|
|
print(f'About to download pairs: {PAIRS} to {dl_path}')
|
|
|
|
|
|
2018-04-24 23:11:07 +00:00
|
|
|
|
# Init exchange
|
2018-12-25 12:14:28 +00:00
|
|
|
|
exchange = Exchange(config)
|
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
|
2019-04-07 13:14:40 +00:00
|
|
|
|
for ticker_interval in timeframes:
|
2018-04-22 07:56:49 +00:00
|
|
|
|
pair_print = pair.replace('/', '_')
|
2019-04-07 13:14:40 +00:00
|
|
|
|
filename = f'{pair_print}-{ticker_interval}.json'
|
2018-06-24 17:52:12 +00:00
|
|
|
|
dl_file = dl_path.joinpath(filename)
|
|
|
|
|
if args.erase and dl_file.exists():
|
2019-04-07 13:14:40 +00:00
|
|
|
|
print(f'Deleting existing data for pair {pair}, interval {ticker_interval}')
|
2018-06-24 17:52:12 +00:00
|
|
|
|
dl_file.unlink()
|
|
|
|
|
|
2019-04-07 13:14:40 +00:00
|
|
|
|
print(f'downloading pair {pair}, interval {ticker_interval}')
|
2018-12-16 09:33:08 +00:00
|
|
|
|
download_pair_history(datadir=dl_path, exchange=exchange,
|
|
|
|
|
pair=pair,
|
2019-04-07 13:14:40 +00:00
|
|
|
|
ticker_interval=ticker_interval,
|
2018-12-16 09:33:08 +00:00
|
|
|
|
timerange=timerange)
|
2018-06-11 19:10:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pairs_not_available:
|
|
|
|
|
print(f"Pairs [{','.join(pairs_not_available)}] not availble.")
|