From eb5c6a658bb5bf9704094ddffab537748fbaca0f Mon Sep 17 00:00:00 2001 From: dekun Date: Fri, 17 Jul 2026 07:29:45 +0800 Subject: [PATCH] Show hedge targets in control center Co-authored-by: Cursor --- lib/common/static/options_position_cards.js | 10 +++++++--- lib/hedge_plan/hedge_plan_db.py | 1 + lib/options/options_hub_lib.py | 4 ++++ manual_trading_hub/static/app.js | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/common/static/options_position_cards.js b/lib/common/static/options_position_cards.js index e4e6d61..943babe 100644 --- a/lib/common/static/options_position_cards.js +++ b/lib/common/static/options_position_cards.js @@ -197,13 +197,17 @@ } const profitTxt = profit == null ? "—" : ((profit > 0 ? "+" : "") + fmtUsdc(profit) + " USDC"); const profitCls = profit > 0 ? " pnl-pos" : profit < 0 ? " pnl-neg" : ""; + const hedgeTarget = p.hedge_plan_target || null; + const managed = hedgeTarget && hedgeTarget.managed_by === "hedge_plan"; return ( - '
' + - '委托' + + '
' + + '' + (managed ? "对冲计划 #" + hedgeTarget.plan_id : "委托") + "" + '目标 ' + fmt(p.target_index, 1) + "" + '价值 ' + (value == null ? "—" : fmtUsdc(value) + " USDC") + "" + '预估盈利 ' + profitTxt + "" + - '监控中 · 到位按买一限价平
' + '' + + (managed ? "进行中 · 由对冲计划监控,到位后仅平盈利腿" : "监控中 · 到位按买一限价平") + + "
" ); })() : "") diff --git a/lib/hedge_plan/hedge_plan_db.py b/lib/hedge_plan/hedge_plan_db.py index b615429..43e24fa 100644 --- a/lib/hedge_plan/hedge_plan_db.py +++ b/lib/hedge_plan/hedge_plan_db.py @@ -236,6 +236,7 @@ def active_options_targets_by_inst(conn: sqlite3.Connection) -> dict[str, dict[s continue out[inst_id] = { "plan_id": int(row["plan_id"]), + "inst_id": inst_id, "underlying": row.get("underlying"), "opt_type": opt_type, "target_index": target_f, diff --git a/lib/options/options_hub_lib.py b/lib/options/options_hub_lib.py index 807f5a4..69d5d36 100644 --- a/lib/options/options_hub_lib.py +++ b/lib/options/options_hub_lib.py @@ -40,6 +40,7 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]: target_monitors = list_active_targets(conn) + list_closing_targets(conn) tgt_map = targets_by_inst(conn) hedge_target_map = active_options_targets_by_inst(conn) + target_monitors.extend(hedge_target_map.values()) for p in positions: mon = tgt_map.get(str(p.get("inst_id") or "")) if mon: @@ -49,6 +50,9 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]: hedge_target = hedge_target_map.get(str(p.get("inst_id") or "")) if hedge_target: p["hedge_plan_target"] = hedge_target + if not mon: + # 中控卡片共用 target_index 只读展示;实际平仓仍由对冲计划监控处理。 + p["target_index"] = hedge_target.get("target_index") finally: conn.close() except Exception: diff --git a/manual_trading_hub/static/app.js b/manual_trading_hub/static/app.js index dfb2a63..7ecce39 100644 --- a/manual_trading_hub/static/app.js +++ b/manual_trading_hub/static/app.js @@ -3757,6 +3757,9 @@ if (!target) return "—"; const side = String(target.opt_type || "").toUpperCase() === "P" ? "Put≤" : "Call≥"; const px = target.target_index != null ? fmt(target.target_index, 1) : "—"; + if (target.managed_by === "hedge_plan") { + return `对冲#${esc(target.plan_id)} ${esc(side)} ${esc(px)}`; + } return `${esc(side)} ${esc(px)}`; }