feat(DATA-004): add underlying instrument selector
This commit is contained in:
@@ -109,6 +109,9 @@ class PortfolioConfig:
|
||||
fallback_source: str = "yfinance"
|
||||
refresh_interval: int = 5
|
||||
|
||||
# Underlying instrument selection
|
||||
underlying: str = "GLD"
|
||||
|
||||
# Alert settings
|
||||
volatility_spike: float = 0.25
|
||||
spot_drawdown: float = 7.5
|
||||
@@ -223,6 +226,7 @@ class PortfolioConfig:
|
||||
"primary_source": self.primary_source,
|
||||
"fallback_source": self.fallback_source,
|
||||
"refresh_interval": self.refresh_interval,
|
||||
"underlying": self.underlying,
|
||||
"volatility_spike": self.volatility_spike,
|
||||
"spot_drawdown": self.spot_drawdown,
|
||||
"email_alerts": self.email_alerts,
|
||||
@@ -285,6 +289,7 @@ class PortfolioRepository:
|
||||
"primary_source",
|
||||
"fallback_source",
|
||||
"refresh_interval",
|
||||
"underlying", # optional with default "GLD"
|
||||
"volatility_spike",
|
||||
"spot_drawdown",
|
||||
"email_alerts",
|
||||
@@ -344,10 +349,14 @@ class PortfolioRepository:
|
||||
upgraded = cls._upgrade_legacy_default_workspace(deserialized)
|
||||
return PortfolioConfig.from_dict(upgraded)
|
||||
|
||||
# Fields that must be present in persisted payloads
|
||||
# (underlying is optional with default "GLD")
|
||||
_REQUIRED_FIELDS = _PERSISTED_FIELDS - {"underlying"}
|
||||
|
||||
@classmethod
|
||||
def _validate_portfolio_fields(cls, payload: dict[str, Any]) -> None:
|
||||
keys = set(payload.keys())
|
||||
missing = sorted(cls._PERSISTED_FIELDS - keys)
|
||||
missing = sorted(cls._REQUIRED_FIELDS - keys)
|
||||
unknown = sorted(keys - cls._PERSISTED_FIELDS)
|
||||
if missing or unknown:
|
||||
details: list[str] = []
|
||||
|
||||
Reference in New Issue
Block a user