Label dashboard positions from monitor sources with priority.

Match hedge/roll/trend/order/key monitors for source badges, show option target monitors in green, and refresh the dashboard with the board 5s cycle.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 14:25:36 +08:00
parent 0bda44248f
commit c4c8ad172a
11 changed files with 290 additions and 28 deletions
+1
View File
@@ -240,6 +240,7 @@ def active_options_targets_by_inst(conn: sqlite3.Connection) -> dict[str, dict[s
"underlying": row.get("underlying"),
"opt_type": opt_type,
"target_index": target_f,
"plan_type": "options_options",
"managed_by": "hedge_plan",
}
return out
+18
View File
@@ -175,6 +175,7 @@ def build_hub_monitor_payload(
orders,
trends,
rolls,
hedges=None,
enrich=None,
risk_status=None,
) -> dict:
@@ -185,6 +186,7 @@ def build_hub_monitor_payload(
"orders": orders,
"trends": trends,
"rolls": rolls,
"hedges": hedges if isinstance(hedges, list) else [],
"key_prices": [],
}
if isinstance(risk_status, dict):
@@ -193,6 +195,9 @@ def build_hub_monitor_payload(
extra = enrich(keys=keys, orders=orders, trends=trends, rolls=rolls)
if isinstance(extra, dict):
payload.update(extra)
# enrich 可能不返回 hedges,保留本地组装的对冲列表.
if "hedges" not in extra:
payload["hedges"] = hedges if isinstance(hedges, list) else []
return payload
@@ -572,6 +577,17 @@ def register_hub_routes(app):
rolls.append(_row_to_dict(row))
except Exception:
pass
hedges = []
try:
from lib.hedge_plan.hedge_plan_db import attach_legs_to_plans, list_plans
hedge_rows: list = []
for st in ("opening", "active", "partial"):
hedge_rows.extend(list_plans(conn, status=st, limit=80))
hedge_rows.sort(key=lambda row: int(row.get("id") or 0), reverse=True)
hedges = attach_legs_to_plans(conn, hedge_rows)
except Exception:
hedges = []
risk_status = None
risk_fn = c.get("risk_status_fn")
if callable(risk_fn):
@@ -589,6 +605,7 @@ def register_hub_routes(app):
orders=orders,
trends=trends,
rolls=rolls,
hedges=hedges,
enrich=enrich,
risk_status=risk_status,
)
@@ -601,6 +618,7 @@ def register_hub_routes(app):
orders=orders,
trends=trends,
rolls=rolls,
hedges=hedges,
risk_status=risk_status,
)
)
+14
View File
@@ -53,6 +53,20 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
if not mon:
# 中控卡片共用 target_index 只读展示;实际平仓仍由对冲计划监控处理。
p["target_index"] = hedge_target.get("target_index")
try:
from lib.instance.instance_dashboard_lib import (
_format_options_target,
_resolve_options_source,
)
inst = str(p.get("inst_id") or "")
source_key, source_label = _resolve_options_source(conn, inst)
p["source"] = source_key
p["source_label"] = source_label
p["target_monitor_text"] = _format_options_target(p)
except Exception:
p.setdefault("source_label", "")
p.setdefault("target_monitor_text", "")
finally:
conn.close()
except Exception: