Extract selection generation to a seperate method
This commit is contained in:
parent
c80d8f432a
commit
dd83cb1b95
@ -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)
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user