Add unlock_at config test, simplify validation

This commit is contained in:
Matthias 2024-07-16 07:26:41 +02:00
parent a3c52445ee
commit d590ab003f
2 changed files with 21 additions and 9 deletions

View File

@ -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")

View File

@ -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):