Align instance dashboard with hub snapshot+SSE pattern.

Background poll builds a memory snapshot; the page reads snapshot and refreshes on SSE instead of hitting heavy exchange APIs on each load.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 22:00:30 +08:00
parent aabbbef0a9
commit 173f09300b
13 changed files with 492 additions and 86 deletions
+33
View File
@@ -64,6 +64,7 @@ def _format_order_item(od: dict[str, Any]) -> dict[str, Any]:
"title": title,
"subtitle": subtitle,
"symbol": sym,
"price_symbol": od.get("symbol") or sym,
"direction": direction,
"direction_label": _dir_label(direction),
"entry": entry,
@@ -350,6 +351,38 @@ def collect_options_items(
return out
def enrich_order_items_with_marks(
items: list[dict[str, Any]],
*,
get_price: Optional[Callable[[str], Any]] = None,
) -> list[dict[str, Any]]:
"""后台聚合时补标记价(不打全量 fetch_positions;浮盈仍由实盘页口径负责)."""
if not items or not callable(get_price):
return items
out: list[dict[str, Any]] = []
for it in items:
row = dict(it)
sym = str(row.get("price_symbol") or row.get("symbol") or "").strip()
if not sym:
out.append(row)
continue
try:
px = get_price(sym)
except Exception:
px = None
mark = _safe_float(px)
if mark is None and ":" in sym:
try:
px = get_price(sym.split(":", 1)[0])
except Exception:
px = None
mark = _safe_float(px)
if mark is not None:
row["mark_price"] = mark
out.append(row)
return out
def build_instance_dashboard_payload(
conn,
*,