Add user_data_dir to configuration
This commit is contained in:
parent
56c8bdbaa2
commit
1b2581f0cb
@ -9,7 +9,7 @@ import arrow
|
|||||||
from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS
|
from freqtrade.configuration.cli_options import AVAILABLE_CLI_OPTIONS
|
||||||
from freqtrade import constants
|
from freqtrade import constants
|
||||||
|
|
||||||
ARGS_COMMON = ["verbosity", "logfile", "version", "config", "datadir"]
|
ARGS_COMMON = ["verbosity", "logfile", "version", "config", "datadir", "user_data_dir"]
|
||||||
|
|
||||||
ARGS_STRATEGY = ["strategy", "strategy_path"]
|
ARGS_STRATEGY = ["strategy", "strategy_path"]
|
||||||
|
|
||||||
|
@ -176,9 +176,13 @@ class Configuration(object):
|
|||||||
"""
|
"""
|
||||||
if 'user_data_dir' in self.args and self.args.user_data_dir:
|
if 'user_data_dir' in self.args and self.args.user_data_dir:
|
||||||
config.update({'user_data_dir': self.args.user_data_dir})
|
config.update({'user_data_dir': self.args.user_data_dir})
|
||||||
create_userdata_dir(config['user_data_dir'])
|
|
||||||
elif 'user_data_dir' not in config:
|
elif 'user_data_dir' not in config:
|
||||||
|
# Default to cwd/user_data (legacy option ...)
|
||||||
config.update({'user_data_dir': str(Path.cwd() / "user_data")})
|
config.update({'user_data_dir': str(Path.cwd() / "user_data")})
|
||||||
|
# reset to user_data_dir so this contains the absolute path.
|
||||||
|
config['user_data_dir'] = create_userdata_dir(config['user_data_dir'])
|
||||||
|
|
||||||
|
logger.info('Using user-data directory: %s ...', config['user_data_dir'])
|
||||||
|
|
||||||
if 'datadir' in self.args and self.args.datadir:
|
if 'datadir' in self.args and self.args.datadir:
|
||||||
config.update({'datadir': create_datadir(config, self.args.datadir)})
|
config.update({'datadir': create_datadir(config, self.args.datadir)})
|
||||||
|
@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str:
|
def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str:
|
||||||
|
|
||||||
folder = Path(datadir) if datadir else Path('user_data/data')
|
folder = Path(datadir) if datadir else Path(f"{config['user_data_dir']}/data")
|
||||||
if not datadir:
|
if not datadir:
|
||||||
# set datadir
|
# set datadir
|
||||||
exchange_name = config.get('exchange', {}).get('name').lower()
|
exchange_name = config.get('exchange', {}).get('name').lower()
|
||||||
@ -20,7 +20,7 @@ def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str
|
|||||||
return str(folder)
|
return str(folder)
|
||||||
|
|
||||||
|
|
||||||
def create_userdata_dir(directory: str):
|
def create_userdata_dir(directory: str) -> str:
|
||||||
sub_dirs = ["backtest_results", "data", "hyperopts", "plots", "strategies", ]
|
sub_dirs = ["backtest_results", "data", "hyperopts", "plots", "strategies", ]
|
||||||
folder = Path(directory)
|
folder = Path(directory)
|
||||||
if not folder.is_dir():
|
if not folder.is_dir():
|
||||||
@ -32,3 +32,5 @@ def create_userdata_dir(directory: str):
|
|||||||
subfolder = folder / f
|
subfolder = folder / f
|
||||||
if not subfolder.is_dir():
|
if not subfolder.is_dir():
|
||||||
subfolder.mkdir(parents=False)
|
subfolder.mkdir(parents=False)
|
||||||
|
# TODO: convert this to return Path
|
||||||
|
return str(folder.resolve())
|
||||||
|
@ -331,11 +331,15 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
'freqtrade.configuration.configuration.create_datadir',
|
'freqtrade.configuration.configuration.create_datadir',
|
||||||
lambda c, x: x
|
lambda c, x: x
|
||||||
)
|
)
|
||||||
|
mocker.patch(
|
||||||
|
'freqtrade.configuration.configuration.create_userdata_dir',
|
||||||
|
lambda x: x
|
||||||
|
)
|
||||||
arglist = [
|
arglist = [
|
||||||
'--config', 'config.json',
|
'--config', 'config.json',
|
||||||
'--strategy', 'DefaultStrategy',
|
'--strategy', 'DefaultStrategy',
|
||||||
'--datadir', '/foo/bar',
|
'--datadir', '/foo/bar',
|
||||||
|
'--userdir', "/tmp/freqtrade",
|
||||||
'backtesting',
|
'backtesting',
|
||||||
'--ticker-interval', '1m',
|
'--ticker-interval', '1m',
|
||||||
'--live',
|
'--live',
|
||||||
@ -357,7 +361,11 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
assert 'pair_whitelist' in config['exchange']
|
assert 'pair_whitelist' in config['exchange']
|
||||||
assert 'datadir' in config
|
assert 'datadir' in config
|
||||||
assert log_has(
|
assert log_has(
|
||||||
'Using data directory: {} ...'.format(config['datadir']),
|
'Using data directory: {} ...'.format("/foo/bar"),
|
||||||
|
caplog.record_tuples
|
||||||
|
)
|
||||||
|
assert log_has(
|
||||||
|
'Using user-data directory: {} ...'.format("/tmp/freqtrade"),
|
||||||
caplog.record_tuples
|
caplog.record_tuples
|
||||||
)
|
)
|
||||||
assert 'ticker_interval' in config
|
assert 'ticker_interval' in config
|
||||||
@ -613,10 +621,12 @@ def test_create_userdata_dir(mocker, default_conf, caplog) -> None:
|
|||||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=False))
|
mocker.patch.object(Path, "is_dir", MagicMock(return_value=False))
|
||||||
md = mocker.patch.object(Path, 'mkdir', MagicMock())
|
md = mocker.patch.object(Path, 'mkdir', MagicMock())
|
||||||
|
|
||||||
create_userdata_dir('/tmp/bar')
|
x = create_userdata_dir('/tmp/bar')
|
||||||
assert md.call_count == 6
|
assert md.call_count == 6
|
||||||
assert md.call_args[1]['parents'] is False
|
assert md.call_args[1]['parents'] is False
|
||||||
assert log_has('Created user-data directory: /tmp/bar', caplog.record_tuples)
|
assert log_has('Created user-data directory: /tmp/bar', caplog.record_tuples)
|
||||||
|
assert isinstance(x, str)
|
||||||
|
assert x == "/tmp/bar"
|
||||||
|
|
||||||
|
|
||||||
def test_create_userdata_dir_exists(mocker, default_conf, caplog) -> None:
|
def test_create_userdata_dir_exists(mocker, default_conf, caplog) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user