diff --git a/freqtrade/commands/build_config_commands.py b/freqtrade/commands/build_config_commands.py index e0910e5b7..6ba9cf0ac 100644 --- a/freqtrade/commands/build_config_commands.py +++ b/freqtrade/commands/build_config_commands.py @@ -166,7 +166,11 @@ def start_new_config(args: Dict[str, Any]) -> None: Create a new strategy from a template Asking the user questions to fill out the templateaccordingly. """ - selections = ask_user_config() config_path = Path(args['config'][0]) + if config_path.exists(): + raise OperationalException( + f"Configuration `{config_path}` already exists. " + "Please use another configuration name or delete the existing configuration.") + selections = ask_user_config() deploy_new_config(config_path, selections) diff --git a/tests/commands/test_build_config.py b/tests/commands/test_build_config.py index 46e79b357..b0a048c15 100644 --- a/tests/commands/test_build_config.py +++ b/tests/commands/test_build_config.py @@ -6,6 +6,7 @@ import pytest from freqtrade.commands.build_config_commands import (ask_user_config, start_new_config) +from freqtrade.exceptions import OperationalException from tests.conftest import get_args, log_has_re @@ -43,6 +44,17 @@ def test_start_new_config(mocker, caplog, exchange): assert result['ticker_interval'] == '15m' +def test_start_new_config_exists(mocker, caplog): + mocker.patch.object(Path, "exists", MagicMock(return_value=True)) + args = [ + "new-config", + "--config", + "coolconfig.json" + ] + with pytest.raises(OperationalException, match=r"Configuration .* already exists\."): + start_new_config(get_args(args)) + + def test_ask_user_config(): # TODO: Implement me pass