mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
Add unlock_at config test, simplify validation
This commit is contained in:
@@ -193,7 +193,12 @@ def _validate_protections(conf: Dict[str, Any]) -> None:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
for prot in conf.get("protections", []):
|
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:
|
if "stop_duration" in prot and "stop_duration_candles" in prot:
|
||||||
raise ConfigurationError(
|
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:
|
def _validate_ask_orderbook(conf: Dict[str, Any]) -> None:
|
||||||
ask_strategy = conf.get("exit_pricing", {})
|
ask_strategy = conf.get("exit_pricing", {})
|
||||||
ob_min = ask_strategy.get("order_book_min")
|
ob_min = ask_strategy.get("order_book_min")
|
||||||
|
|||||||
@@ -840,6 +840,21 @@ def test_validate_whitelist(default_conf):
|
|||||||
],
|
],
|
||||||
r"Protections must specify either `stop_duration`.*",
|
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):
|
def test_validate_protections(default_conf, protconf, expected):
|
||||||
|
|||||||
Reference in New Issue
Block a user