From dd83cb1b95fb2a0f3790d7c83a377ed72b659fd3 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 29 Jan 2020 20:27:38 +0100 Subject: [PATCH] Extract selection generation to a seperate method --- freqtrade/commands/deploy_commands.py | 38 ++++++++++++++++--------- freqtrade/templates/base_config.json.j2 | 2 +- tests/commands/test_commands.py | 21 ++++++++++++-- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/freqtrade/commands/deploy_commands.py b/freqtrade/commands/deploy_commands.py index 065703faa..87aea7492 100644 --- a/freqtrade/commands/deploy_commands.py +++ b/freqtrade/commands/deploy_commands.py @@ -112,6 +112,28 @@ def start_new_hyperopt(args: Dict[str, Any]) -> None: raise OperationalException("`new-hyperopt` requires --hyperopt to be set.") +def ask_user_config() -> Dict[str, Any]: + """ + Ask user a few questions to build the configuration. + :returns: Dict with keys to put into template + """ + sample_selections = { + 'max_open_trades': 3, + 'stake_currency': 'USDT', + 'stake_amount': 100, + 'fiat_display_currency': 'EUR', + 'ticker_interval': '15m', + 'dry_run': True, + 'exchange_name': 'binance', + 'exchange_key': 'sampleKey', + 'exchange_secret': 'Samplesecret', + 'telegram': False, + 'telegram_token': 'asdf1244', + 'telegram_chat_id': '1144444', + } + return sample_selections + + def deploy_new_config(config_path: Path, selections: Dict[str, Any]) -> None: """ Applies selections to the template and writes the result to config_path @@ -142,20 +164,8 @@ 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. """ - sample_selections = { - 'stake_currency': 'USDT', - 'stake_amount': 100, - 'fiat_display_currency': 'EUR', - 'ticker_interval': '15m', - 'dry_run': True, - 'exchange_name': 'binance', - 'exchange_key': 'sampleKey', - 'exchange_secret': 'Samplesecret', - 'telegram': False, - 'telegram_token': 'asdf1244', - 'telegram_chat_id': '1144444', - } + selections = ask_user_config() config_path = Path(args['config'][0]) - deploy_new_config(config_path, sample_selections) + deploy_new_config(config_path, selections) diff --git a/freqtrade/templates/base_config.json.j2 b/freqtrade/templates/base_config.json.j2 index f2f919e1f..1370bfa80 100644 --- a/freqtrade/templates/base_config.json.j2 +++ b/freqtrade/templates/base_config.json.j2 @@ -1,5 +1,5 @@ { - "max_open_trades": 3, + "max_open_trades": {{ max_open_trades }}, "stake_currency": "{{ stake_currency }}", "stake_amount": {{ stake_amount }}, "tradable_balance_ratio": 0.99, diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 65d7f6eaf..f8efdfd3c 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -8,8 +8,9 @@ from freqtrade.commands import (start_create_userdir, start_download_data, start_hyperopt_list, start_hyperopt_show, start_list_exchanges, start_list_markets, start_list_strategies, start_list_timeframes, - start_new_hyperopt, start_new_strategy, - start_test_pairlist, start_trading) + start_new_config, start_new_hyperopt, + start_new_strategy, start_test_pairlist, + start_trading) from freqtrade.configuration import setup_utils_configuration from freqtrade.exceptions import OperationalException from freqtrade.state import RunMode @@ -537,6 +538,22 @@ def test_start_new_hyperopt_no_arg(mocker, caplog): start_new_hyperopt(get_args(args)) +def test_start_new_config(mocker, caplog): + wt_mock = mocker.patch.object(Path, "write_text", MagicMock()) + mocker.patch.object(Path, "exists", MagicMock(return_value=False)) + + args = [ + "new-config", + "--config", + "coolconfig.json" + ] + start_new_config(get_args(args)) + + assert wt_mock.call_count == 1 + assert "binance" in wt_mock.call_args_list[0][0][0] + assert log_has_re("Writing config to .*", caplog) + + def test_download_data_keyboardInterrupt(mocker, caplog, markets): dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data', MagicMock(side_effect=KeyboardInterrupt))