From 76f934f95d3b5cbb96765e7158976e4a4c879fa9 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Wed, 1 Apr 2026 17:11:10 +0900 Subject: feat(strategy): add parameter validation to all strategies --- services/strategy-engine/strategies/macd_strategy.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'services/strategy-engine/strategies/macd_strategy.py') diff --git a/services/strategy-engine/strategies/macd_strategy.py b/services/strategy-engine/strategies/macd_strategy.py index 049574e..e3bb35c 100644 --- a/services/strategy-engine/strategies/macd_strategy.py +++ b/services/strategy-engine/strategies/macd_strategy.py @@ -28,6 +28,20 @@ class MacdStrategy(BaseStrategy): self._signal_period = int(params.get("signal_period", 9)) self._quantity = Decimal(str(params.get("quantity", "0.01"))) + if self._fast_period >= self._slow_period: + raise ValueError( + f"MACD fast_period must be < slow_period, " + f"got fast={self._fast_period}, slow={self._slow_period}" + ) + if self._fast_period < 2: + raise ValueError(f"MACD fast_period must be >= 2, got {self._fast_period}") + if self._slow_period < 2: + raise ValueError(f"MACD slow_period must be >= 2, got {self._slow_period}") + if self._signal_period < 2: + raise ValueError(f"MACD signal_period must be >= 2, got {self._signal_period}") + if self._quantity <= 0: + raise ValueError(f"Quantity must be positive, got {self._quantity}") + def reset(self) -> None: self._closes.clear() self._prev_histogram = None -- cgit v1.2.3