diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 17ad37d6a..d96a291e2 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -10,7 +10,7 @@ from typing import Any, Callable, Dict, Optional from freqtrade import OperationalException, constants from freqtrade.configuration.check_exchange import check_exchange -from freqtrade.configuration.create_datadir import create_datadir +from freqtrade.configuration.folder_operations import create_datadir from freqtrade.configuration.json_schema import validate_config_schema from freqtrade.loggers import setup_logging from freqtrade.misc import deep_merge_dicts diff --git a/freqtrade/configuration/create_datadir.py b/freqtrade/configuration/folder_operations.py similarity index 56% rename from freqtrade/configuration/create_datadir.py rename to freqtrade/configuration/folder_operations.py index acc3a29ca..f402f91e0 100644 --- a/freqtrade/configuration/create_datadir.py +++ b/freqtrade/configuration/folder_operations.py @@ -18,3 +18,17 @@ def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str folder.mkdir(parents=True) logger.info(f'Created data directory: {datadir}') return str(folder) + + +def create_userdata_dir(directory: str): + sub_dirs = ["backtest_results", "data", "hyperopts", "plots", "strategies", ] + folder = Path(directory) + if not folder.is_dir(): + folder.mkdir(parents=True) + logger.info(f'Created user-data directory: {folder}') + + # Create required subdirectories + for f in sub_dirs: + subfolder = folder / f + if not subfolder.is_dir(): + subfolder.mkdir(parents=False) diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index 56ff79625..21df8d4e5 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -13,7 +13,7 @@ from jsonschema import Draft4Validator, ValidationError, validate from freqtrade import OperationalException, constants from freqtrade.configuration import Arguments, Configuration from freqtrade.configuration.check_exchange import check_exchange -from freqtrade.configuration.create_datadir import create_datadir +from freqtrade.configuration.folder_operations import create_datadir, create_userdata_dir from freqtrade.configuration.json_schema import validate_config_schema from freqtrade.constants import DEFAULT_DB_DRYRUN_URL, DEFAULT_DB_PROD_URL from freqtrade.loggers import _set_loggers @@ -609,6 +609,24 @@ def test_create_datadir(mocker, default_conf, caplog) -> None: assert log_has('Created data directory: /foo/bar', caplog.record_tuples) +def test_create_userdata_dir(mocker, default_conf, caplog) -> None: + mocker.patch.object(Path, "is_dir", MagicMock(return_value=False)) + md = mocker.patch.object(Path, 'mkdir', MagicMock()) + + create_userdata_dir('/tmp/bar') + assert md.call_count == 6 + assert md.call_args[1]['parents'] is False + assert log_has('Created user-data directory: /tmp/bar', caplog.record_tuples) + + +def test_create_userdata_dir_exists(mocker, default_conf, caplog) -> None: + mocker.patch.object(Path, "is_dir", MagicMock(return_value=True)) + md = mocker.patch.object(Path, 'mkdir', MagicMock()) + + create_userdata_dir('/tmp/bar') + assert md.call_count == 0 + + def test_validate_tsl(default_conf): default_conf['trailing_stop'] = True default_conf['trailing_stop_positive'] = 0