diff --git a/freqtrade/configuration/config_validation.py b/freqtrade/configuration/config_validation.py index 4bb260b52..aa9a1757d 100644 --- a/freqtrade/configuration/config_validation.py +++ b/freqtrade/configuration/config_validation.py @@ -193,7 +193,12 @@ def _validate_protections(conf: Dict[str, Any]) -> None: """ for prot in conf.get("protections", []): - parsed_unlock_at = _validate_unlock_at(prot) + parsed_unlock_at = None + if (config_unlock_at := prot.get("unlock_at")) is not None: + try: + parsed_unlock_at = datetime.strptime(config_unlock_at, "%H:%M") + except ValueError: + raise ConfigurationError(f"Invalid date format for unlock_at: {config_unlock_at}.") if "stop_duration" in prot and "stop_duration_candles" in prot: raise ConfigurationError( @@ -217,14 +222,6 @@ def _validate_protections(conf: Dict[str, Any]) -> None: ) -def _validate_unlock_at(config_unlock_at: str) -> datetime: - if config_unlock_at is not None and isinstance(config_unlock_at, str): - try: - return datetime.strptime(config_unlock_at, "%H:%M") - except ValueError: - raise ConfigurationError(f"Invalid date format for unlock_at: {config_unlock_at}.") - - def _validate_ask_orderbook(conf: Dict[str, Any]) -> None: ask_strategy = conf.get("exit_pricing", {}) ob_min = ask_strategy.get("order_book_min") diff --git a/tests/test_configuration.py b/tests/test_configuration.py index f9368246a..af482a965 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -840,6 +840,21 @@ def test_validate_whitelist(default_conf): ], r"Protections must specify either `stop_duration`.*", ), + ( + [ + { + "method": "StoplossGuard", + "lookback_period": 20, + "stop_duration": 10, + "unlock_at": "20:02", + } + ], + r"Protections must specify either `unlock_at`, `stop_duration` or.*", + ), + ( + [{"method": "StoplossGuard", "lookback_period_candles": 20, "unlock_at": "20:02"}], + None, + ), ], ) def test_validate_protections(default_conf, protconf, expected):