Coverage for src/finbot/strategy/signal.py: 100%
22 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 17:12 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-21 17:12 +0000
1import math
2from dataclasses import dataclass, field
3from enum import StrEnum
4from typing import Any
7class SignalDirection(StrEnum):
8 LONG = "long"
9 SHORT = "short"
10 FLAT = "flat"
13@dataclass(frozen=True)
14class Signal:
15 symbol: str
16 direction: SignalDirection
17 strength: float | None = None
18 metadata: dict[str, Any] = field(default_factory=dict)
20 def __post_init__(self) -> None:
21 if not isinstance(self.symbol, str) or not self.symbol.strip():
22 raise ValueError("Symbol must be a non-empty string.")
24 if self.strength is not None:
25 if not math.isfinite(self.strength):
26 raise ValueError("Signal strength must be finite.")
28 if not 0.0 <= self.strength <= 1.0:
29 raise ValueError("Signal strength must be between 0 and 1.")