2019-06-12 09:33:20 +00:00
|
|
|
import logging
|
2019-07-21 12:13:38 +00:00
|
|
|
import sys
|
2019-06-12 09:33:20 +00:00
|
|
|
from argparse import Namespace
|
2019-08-16 12:42:44 +00:00
|
|
|
from pathlib import Path
|
2019-06-12 09:33:20 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
2019-08-16 12:42:44 +00:00
|
|
|
import arrow
|
|
|
|
|
|
|
|
from freqtrade.configuration import Configuration, TimeRange
|
2019-07-29 04:15:49 +00:00
|
|
|
from freqtrade.configuration.directory_operations import create_userdata_dir
|
2019-08-16 12:42:44 +00:00
|
|
|
from freqtrade.data.history import download_pair_history
|
2019-06-16 08:39:43 +00:00
|
|
|
from freqtrade.exchange import available_exchanges
|
2019-08-16 12:42:44 +00:00
|
|
|
from freqtrade.resolvers import ExchangeResolver
|
2019-06-12 09:33:20 +00:00
|
|
|
from freqtrade.state import RunMode
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-06-16 18:37:43 +00:00
|
|
|
def setup_utils_configuration(args: Namespace, method: RunMode) -> Dict[str, Any]:
|
2019-06-12 09:33:20 +00:00
|
|
|
"""
|
2019-06-16 18:37:43 +00:00
|
|
|
Prepare the configuration for utils subcommands
|
2019-06-12 09:33:20 +00:00
|
|
|
:param args: Cli args from Arguments()
|
|
|
|
:return: Configuration
|
|
|
|
"""
|
|
|
|
configuration = Configuration(args, method)
|
2019-08-16 12:42:44 +00:00
|
|
|
config = configuration.get_config()
|
2019-06-12 09:33:20 +00:00
|
|
|
|
2019-06-16 18:37:43 +00:00
|
|
|
config['exchange']['dry_run'] = True
|
2019-06-12 09:33:20 +00:00
|
|
|
# Ensure we do not use Exchange credentials
|
|
|
|
config['exchange']['key'] = ''
|
|
|
|
config['exchange']['secret'] = ''
|
|
|
|
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def start_list_exchanges(args: Namespace) -> None:
|
|
|
|
"""
|
2019-06-14 18:54:38 +00:00
|
|
|
Print available exchanges
|
2019-06-12 09:33:20 +00:00
|
|
|
:param args: Cli args from Arguments()
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
if args.print_one_column:
|
2019-06-16 08:39:43 +00:00
|
|
|
print('\n'.join(available_exchanges()))
|
2019-06-12 09:33:20 +00:00
|
|
|
else:
|
2019-06-14 18:54:38 +00:00
|
|
|
print(f"Exchanges supported by ccxt and available for Freqtrade: "
|
2019-06-16 08:39:43 +00:00
|
|
|
f"{', '.join(available_exchanges())}")
|
2019-07-21 12:13:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def start_create_userdir(args: Namespace) -> None:
|
|
|
|
"""
|
|
|
|
Create "user_data" directory to contain user data strategies, hyperopts, ...)
|
|
|
|
:param args: Cli args from Arguments()
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
if "user_data_dir" in args and args.user_data_dir:
|
2019-07-31 17:39:54 +00:00
|
|
|
create_userdata_dir(args.user_data_dir, create_dir=True)
|
2019-07-21 12:13:38 +00:00
|
|
|
else:
|
|
|
|
logger.warning("`create-userdir` requires --userdir to be set.")
|
|
|
|
sys.exit(1)
|
2019-08-21 17:35:27 +00:00
|
|
|
|
|
|
|
|
2019-08-16 12:42:44 +00:00
|
|
|
def start_download_data(args: Namespace) -> None:
|
|
|
|
"""
|
2019-08-16 13:27:33 +00:00
|
|
|
Download data (former download_backtest_data.py script)
|
2019-08-16 12:42:44 +00:00
|
|
|
"""
|
|
|
|
config = setup_utils_configuration(args, RunMode.OTHER)
|
|
|
|
|
|
|
|
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}-')
|
|
|
|
|
|
|
|
dl_path = Path(config['datadir'])
|
|
|
|
logger.info(f'About to download pairs: {config["pairs"]}, '
|
|
|
|
f'intervals: {config["timeframes"]} to {dl_path}')
|
|
|
|
|
|
|
|
pairs_not_available = []
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Init exchange
|
|
|
|
exchange = ExchangeResolver(config['exchange']['name'], config).exchange
|
|
|
|
|
|
|
|
for pair in config["pairs"]:
|
2019-08-16 13:27:59 +00:00
|
|
|
if pair not in exchange.markets:
|
2019-08-16 12:42:44 +00:00
|
|
|
pairs_not_available.append(pair)
|
|
|
|
logger.info(f"Skipping pair {pair}...")
|
|
|
|
continue
|
|
|
|
for ticker_interval in config["timeframes"]:
|
|
|
|
pair_print = pair.replace('/', '_')
|
|
|
|
filename = f'{pair_print}-{ticker_interval}.json'
|
|
|
|
dl_file = dl_path.joinpath(filename)
|
2019-08-16 13:27:33 +00:00
|
|
|
if config.get("erase") and dl_file.exists():
|
2019-08-16 12:42:44 +00:00
|
|
|
logger.info(
|
|
|
|
f'Deleting existing data for pair {pair}, interval {ticker_interval}.')
|
|
|
|
dl_file.unlink()
|
|
|
|
|
|
|
|
logger.info(f'Downloading pair {pair}, interval {ticker_interval}.')
|
|
|
|
download_pair_history(datadir=dl_path, exchange=exchange,
|
|
|
|
pair=pair, ticker_interval=str(ticker_interval),
|
|
|
|
timerange=timerange)
|
|
|
|
|
|
|
|
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 {config['exchange']['name']}.")
|
|
|
|
|
|
|
|
# configuration.resolve_pairs_list()
|
|
|
|
print(config)
|