fix: restore workspace nav and correct overview spot fallback
This commit is contained in:
@@ -15,6 +15,22 @@ from app.services.runtime import get_data_service
|
||||
_DEFAULT_CASH_BUFFER = 18_500.0
|
||||
|
||||
|
||||
def _resolve_overview_spot(config, quote: dict[str, object]) -> tuple[float, str, str]:
|
||||
configured_price = float(config.entry_price or 0.0)
|
||||
quote_price = float(quote.get("price", configured_price or 0.0) or 0.0)
|
||||
quote_source = str(quote.get("source", "unknown"))
|
||||
quote_updated_at = str(quote.get("updated_at", ""))
|
||||
|
||||
if configured_price > 0 and quote_price > 0:
|
||||
ratio = max(configured_price / quote_price, quote_price / configured_price)
|
||||
if ratio > 1.5:
|
||||
return configured_price, "configured_entry_price", ""
|
||||
|
||||
if quote_price > 0:
|
||||
return quote_price, quote_source, quote_updated_at
|
||||
return configured_price, "configured_entry_price", ""
|
||||
|
||||
|
||||
def _format_timestamp(value: str | None) -> str:
|
||||
if not value:
|
||||
return "Unavailable"
|
||||
@@ -96,20 +112,24 @@ async def overview_page(workspace_id: str) -> None:
|
||||
data_service = get_data_service()
|
||||
symbol = data_service.default_symbol
|
||||
quote = await data_service.get_quote(symbol)
|
||||
overview_spot_price, overview_source, overview_updated_at = _resolve_overview_spot(config, quote)
|
||||
portfolio = build_portfolio_alert_context(
|
||||
config,
|
||||
spot_price=float(quote.get("price", float(config.entry_price or 0.0))),
|
||||
source=str(quote.get("source", "unknown")),
|
||||
updated_at=str(quote.get("updated_at", "")),
|
||||
spot_price=overview_spot_price,
|
||||
source=overview_source,
|
||||
updated_at=overview_updated_at,
|
||||
)
|
||||
configured_gold_value = float(config.gold_value or 0.0)
|
||||
portfolio["cash_buffer"] = max(float(portfolio["gold_value"]) - configured_gold_value, 0.0) + _DEFAULT_CASH_BUFFER
|
||||
portfolio["hedge_budget"] = float(config.monthly_budget)
|
||||
alert_status = AlertService().evaluate(config, portfolio)
|
||||
quote_status = (
|
||||
f"Live quote source: {portfolio['quote_source']} · "
|
||||
f"Last updated {_format_timestamp(str(portfolio['quote_updated_at']))}"
|
||||
)
|
||||
if portfolio["quote_source"] == "configured_entry_price":
|
||||
quote_status = "Live quote source: configured entry price fallback · Last updated Unavailable"
|
||||
else:
|
||||
quote_status = (
|
||||
f"Live quote source: {portfolio['quote_source']} · "
|
||||
f"Last updated {_format_timestamp(str(portfolio['quote_updated_at']))}"
|
||||
)
|
||||
|
||||
with dashboard_page(
|
||||
"Overview",
|
||||
|
||||
Reference in New Issue
Block a user