Store and read exchange data in test/testdata/<exchange> sub directory.

To help manage a multi-exchange bot
This commit is contained in:
creslin 2018-06-03 20:54:05 +03:00 committed by creslinux
parent fff7ec1dab
commit 343ca8fe19
3 changed files with 33 additions and 6 deletions

View File

@ -4,7 +4,6 @@ This module contains the argument manager class
import argparse import argparse
import logging import logging
import os
import re import re
import arrow import arrow
from typing import List, Tuple, Optional from typing import List, Tuple, Optional
@ -70,12 +69,16 @@ class Arguments(object):
type=str, type=str,
metavar='PATH', 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( self.parser.add_argument(
'-d', '--datadir', '-d', '--datadir',
help='path to backtest data (default: %(default)s', help='path to backtest data (help_hints',
dest='datadir', dest='datadir',
default=os.path.join('freqtrade', 'tests', 'testdata'),
type=str, type=str,
default=None,
metavar='PATH', metavar='PATH',
) )
self.parser.add_argument( self.parser.add_argument(

View File

@ -4,6 +4,7 @@ This module contains the configuration class
import json import json
import logging import logging
import os
from argparse import Namespace from argparse import Namespace
from typing import Optional, Dict, Any from typing import Optional, Dict, Any
from jsonschema import Draft4Validator, validate from jsonschema import Draft4Validator, validate
@ -143,9 +144,24 @@ class Configuration(object):
logger.info('Parameter --timerange detected: %s ...', self.args.timerange) logger.info('Parameter --timerange detected: %s ...', self.args.timerange)
# If --datadir is used we add it to the configuration # 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: if 'datadir' in self.args and self.args.datadir:
config.update({'datadir': 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 -r/--refresh-pairs-cached is used we add it to the configuration
if 'refresh_pairs' in self.args and self.args.refresh_pairs: if 'refresh_pairs' in self.args and self.args.refresh_pairs:

View File

@ -8,18 +8,26 @@ import arrow
from freqtrade import (exchange, arguments, misc) from freqtrade import (exchange, arguments, misc)
DEFAULT_DL_PATH = 'freqtrade/tests/testdata'
arguments = arguments.Arguments(sys.argv[1:], 'download utility') arguments = arguments.Arguments(sys.argv[1:], 'download utility')
arguments.testdata_dl_options() arguments.testdata_dl_options()
args = arguments.parse_args() 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'] TICKER_INTERVALS = ['1m', '5m']
PAIRS = [] PAIRS = []
# Added a check for a default pairs file in per exchange specific dir
if args.pairs_file: if args.pairs_file:
with open(args.pairs_file) as file: with open(args.pairs_file) as file:
PAIRS = json.load(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)) PAIRS = list(set(PAIRS))
dl_path = DEFAULT_DL_PATH dl_path = DEFAULT_DL_PATH