stable/freqtrade/commands/data_commands.py

71 lines
2.6 KiB
Python
Raw Normal View History

2020-01-26 12:17:26 +00:00
import logging
import sys
2020-02-03 20:08:35 +00:00
from typing import Any, Dict, List
2020-01-26 12:17:26 +00:00
import arrow
from freqtrade.configuration import TimeRange, setup_utils_configuration
2020-01-26 12:17:26 +00:00
from freqtrade.data.history import (convert_trades_to_ohlcv,
refresh_backtest_ohlcv_data,
refresh_backtest_trades_data)
from freqtrade.exceptions import OperationalException
from freqtrade.resolvers import ExchangeResolver
from freqtrade.state import RunMode
logger = logging.getLogger(__name__)
def start_download_data(args: Dict[str, Any]) -> None:
"""
Download data (former download_backtest_data.py script)
"""
config = setup_utils_configuration(args, RunMode.UTIL_EXCHANGE)
timerange = TimeRange()
if 'days' in config:
time_since = arrow.utcnow().shift(days=-config['days']).strftime("%Y%m%d")
timerange = TimeRange.parse_timerange(f'{time_since}-')
if 'pairs' not in config:
raise OperationalException(
"Downloading data requires a list of pairs. "
"Please check the documentation on how to configure this.")
logger.info(f'About to download pairs: {config["pairs"]}, '
f'intervals: {config["timeframes"]} to {config["datadir"]}')
pairs_not_available: List[str] = []
# Init exchange
exchange = ExchangeResolver.load_exchange(config['exchange']['name'], config, validate=False)
# Manual validations of relevant settings
exchange.validate_pairs(config['pairs'])
for timeframe in config['timeframes']:
exchange.validate_timeframes(timeframe)
2020-01-26 12:17:26 +00:00
try:
if config.get('download_trades'):
pairs_not_available = refresh_backtest_trades_data(
exchange, pairs=config["pairs"], datadir=config['datadir'],
2020-02-03 20:08:35 +00:00
timerange=timerange, erase=bool(config.get("erase")))
2020-01-26 12:17:26 +00:00
# Convert downloaded trade data to different timeframes
convert_trades_to_ohlcv(
pairs=config["pairs"], timeframes=config["timeframes"],
2020-02-02 04:00:40 +00:00
datadir=config['datadir'], timerange=timerange,
2020-02-03 20:08:35 +00:00
erase=bool(config.get("erase")))
2020-01-26 12:17:26 +00:00
else:
pairs_not_available = refresh_backtest_ohlcv_data(
exchange, pairs=config["pairs"], timeframes=config["timeframes"],
2020-02-02 04:00:40 +00:00
datadir=config['datadir'], timerange=timerange,
2020-02-03 20:08:35 +00:00
erase=bool(config.get("erase")))
2020-01-26 12:17:26 +00:00
except KeyboardInterrupt:
sys.exit("SIGINT received, aborting ...")
finally:
if pairs_not_available:
logger.info(f"Pairs [{','.join(pairs_not_available)}] not available "
f"on exchange {exchange.name}.")