Align instance dashboard with snapshot+SSE and options net PnL.

Only dashboard path changes: background snapshot, SSE refresh, smaller header type, options net PnL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 22:10:58 +08:00
parent 4fe0df6c6d
commit 1d2bdc3aa1
14 changed files with 510 additions and 99 deletions
+37 -5
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,
@@ -135,15 +136,14 @@ def _format_options_item(p: dict[str, Any], *, conn=None) -> dict[str, Any]:
inst = str(p.get("inst_id") or p.get("instId") or "-").strip() or "-"
opt_type = str(p.get("opt_type") or p.get("optType") or "").upper()
label = "Call" if opt_type == "C" else "Put" if opt_type == "P" else (opt_type or "OPT")
upl = _safe_float(p.get("upl"))
net = None
# 看板期权列固定用净盈亏(买一回收−权利金);残档买一则空.
pnl = None
try:
from lib.options.options_positions_lib import net_pnl_from_display_row
net = net_pnl_from_display_row(p)
pnl = net_pnl_from_display_row(p)
except Exception:
net = None
pnl = net if net is not None else upl
pnl = None
pos = _safe_float(p.get("pos"))
exp_ms = p.get("exp_time_ms")
if exp_ms is None:
@@ -350,6 +350,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,
*,