feat(CORE-001B): migrate overview and hedge math to unit types

This commit is contained in:
Bu5hm4nn
2026-03-24 21:57:40 +01:00
parent a69fdf6762
commit 7c2729485c
6 changed files with 262 additions and 91 deletions

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from typing import Mapping
from app.domain.portfolio_math import build_alert_context
from app.models.alerts import AlertEvent, AlertHistoryRepository, AlertStatus
from app.models.portfolio import PortfolioConfig
@@ -15,22 +16,12 @@ def build_portfolio_alert_context(
source: str,
updated_at: str,
) -> dict[str, float | str]:
gold_units = float(config.gold_ounces or 0.0)
live_gold_value = gold_units * spot_price
loan_amount = float(config.loan_amount)
margin_call_ltv = float(config.margin_threshold)
return {
"spot_price": float(spot_price),
"gold_units": gold_units,
"gold_value": live_gold_value,
"loan_amount": loan_amount,
"ltv_ratio": loan_amount / live_gold_value if live_gold_value > 0 else 0.0,
"net_equity": live_gold_value - loan_amount,
"margin_call_ltv": margin_call_ltv,
"margin_call_price": loan_amount / (margin_call_ltv * gold_units) if gold_units > 0 else 0.0,
"quote_source": source,
"quote_updated_at": updated_at,
}
return build_alert_context(
config,
spot_price=spot_price,
source=source,
updated_at=updated_at,
)
class AlertService: