From a8d56b28503f62cae1f729cf27955fc98b7b6f39 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 3 Jan 2020 07:07:59 +0100 Subject: [PATCH] IMplement check for unlimited settings verifying that either max_open_trades or stake_amount is set for operations without edge --- freqtrade/configuration/config_validation.py | 12 ++++++++++++ tests/test_configuration.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/freqtrade/configuration/config_validation.py b/freqtrade/configuration/config_validation.py index 43eead46a..02dee2afe 100644 --- a/freqtrade/configuration/config_validation.py +++ b/freqtrade/configuration/config_validation.py @@ -67,12 +67,24 @@ def validate_config_consistency(conf: Dict[str, Any]) -> None: _validate_trailing_stoploss(conf) _validate_edge(conf) _validate_whitelist(conf) + _validate_unlimited_amount(conf) # validate configuration before returning logger.info('Validating configuration ...') validate_config_schema(conf) +def _validate_unlimited_amount(conf: Dict[str, Any]) -> None: + """ + If edge is disabled, either max_open_trades or stake_amount need to be set. + :raise: OperationalException if config validation failed + """ + if (not conf.get('edge', {}).get('enabled') + and conf.get('max_open_trades') == float('inf') + and conf.get('stake_amount') == constants.UNLIMITED_STAKE_AMOUNT): + raise OperationalException("`max_open_trades` and `stake_amount` cannot both be unlimited.") + + def _validate_trailing_stoploss(conf: Dict[str, Any]) -> None: if conf.get('stoploss') == 0.0: diff --git a/tests/test_configuration.py b/tests/test_configuration.py index ee3d23131..6c0035395 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -722,6 +722,14 @@ def test_validate_default_conf(default_conf) -> None: validate_config_schema(default_conf) +def test_validate_max_open_trades(default_conf): + default_conf['max_open_trades'] = float('inf') + default_conf['stake_amount'] = 'unlimited' + with pytest.raises(OperationalException, match='`max_open_trades` and `stake_amount` ' + 'cannot both be unlimited.'): + validate_config_consistency(default_conf) + + def test_validate_tsl(default_conf): default_conf['stoploss'] = 0.0 with pytest.raises(OperationalException, match='The config stoploss needs to be different '