From 343ca8fe199197c50a45c16b8df203cfb3700f3a Mon Sep 17 00:00:00 2001 From: creslin <34645187+creslinux@users.noreply.github.com> Date: Sun, 3 Jun 2018 20:54:05 +0300 Subject: [PATCH] Store and read exchange data in test/testdata/ sub directory. To help manage a multi-exchange bot --- freqtrade/arguments.py | 9 ++++++--- freqtrade/configuration.py | 18 +++++++++++++++++- scripts/download_backtest_data.py | 12 ++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/freqtrade/arguments.py b/freqtrade/arguments.py index 97c3d8cb2..2ef5ab38b 100644 --- a/freqtrade/arguments.py +++ b/freqtrade/arguments.py @@ -4,7 +4,6 @@ This module contains the argument manager class import argparse import logging -import os import re import arrow from typing import List, Tuple, Optional @@ -70,12 +69,16 @@ class Arguments(object): type=str, metavar='PATH', ) + # default to none, if none passed we build a default + # which includes exchange as a subdir in config + # has to be this way around as config.json is not read yet to capture + # exchange value self.parser.add_argument( '-d', '--datadir', - help='path to backtest data (default: %(default)s', + help='path to backtest data (help_hints', dest='datadir', - default=os.path.join('freqtrade', 'tests', 'testdata'), type=str, + default=None, metavar='PATH', ) self.parser.add_argument( diff --git a/freqtrade/configuration.py b/freqtrade/configuration.py index a800bde78..181c8ab0b 100644 --- a/freqtrade/configuration.py +++ b/freqtrade/configuration.py @@ -4,6 +4,7 @@ This module contains the configuration class import json import logging +import os from argparse import Namespace from typing import Optional, Dict, Any from jsonschema import Draft4Validator, validate @@ -143,9 +144,24 @@ class Configuration(object): logger.info('Parameter --timerange detected: %s ...', self.args.timerange) # If --datadir is used we add it to the configuration + # If not passed as an arg, we build testdata path including 'exchange' as a sub dir if 'datadir' in self.args and self.args.datadir: config.update({'datadir': self.args.datadir}) - logger.info('Using data folder: %s ...', self.args.datadir) + else: + exchange = config.get('exchange', {}).get('name').lower() + if exchange: + default = os.path.join('freqtrade', 'tests', 'testdata', exchange) + config.update({'datadir': default}) + # What if user has no exchange as arg or in file - set catchall + else: + logger.info("No exchange set") + default = os.path.join('freqtrade', 'tests', 'testdata', 'catchall') + + if not os.path.exists(config['datadir']): + os.makedirs(config['datadir']) + logger.info("Made directory: %s", config['datadir']) + + logger.info('Using data folder: %s ...', config['datadir']) # If -r/--refresh-pairs-cached is used we add it to the configuration if 'refresh_pairs' in self.args and self.args.refresh_pairs: diff --git a/scripts/download_backtest_data.py b/scripts/download_backtest_data.py index 1c73eae03..80a617089 100755 --- a/scripts/download_backtest_data.py +++ b/scripts/download_backtest_data.py @@ -8,18 +8,26 @@ import arrow from freqtrade import (exchange, arguments, misc) -DEFAULT_DL_PATH = 'freqtrade/tests/testdata' - 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" + TICKER_INTERVALS = ['1m', '5m'] PAIRS = [] +# Added a check for a default pairs file in per exchange specific dir 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) + PAIRS = list(set(PAIRS)) dl_path = DEFAULT_DL_PATH