From bc08a5852d1edcb335b23290154a99ec759f2053 Mon Sep 17 00:00:00 2001 From: dekun Date: Sun, 19 Jul 2026 16:44:45 +0800 Subject: [PATCH] Show hedge close reasons in Chinese on options review. Map plan/leg close_reason codes like target_down_win_leg and expiry to Chinese labels in detail, form, and stats. Co-authored-by: Cursor --- lib/common/static/hedge_plan.js | 5 ++ lib/common/static/options_review.js | 57 ++++++++++++++++--- .../templates/options_review_panel.html | 2 +- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index 9e9fef5..9e4f9d8 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -1402,6 +1402,11 @@ target_win_leg: "期期平盈利腿", target_up_win_leg: "期期上破·平盈利腿", target_down_win_leg: "期期下破·平盈利腿", + oo_rest_closing: "期期全平·清残腿中", + oo_rest_closed: "期期全平·两腿已平", + orphaned_after_tp: "止盈后持有至到期", + orphaned_option_expiry: "残腿到期", + hold_to_expiry: "持有至到期", expiry: "到期", manual: "人工结束", partial_fail: "半腿失败", diff --git a/lib/common/static/options_review.js b/lib/common/static/options_review.js index 79b7859..2a58ecd 100644 --- a/lib/common/static/options_review.js +++ b/lib/common/static/options_review.js @@ -67,13 +67,51 @@ return s; } + function closeReasonLabel(r) { + var map = { + perp_tp: "永续止盈", + perp_sl: "永续止损", + oo_expiry_loss: "期期到期亏损", + oo_expiry_win: "期期到期盈利", + target_win_leg: "期期平盈利腿", + target_up_win_leg: "期期上破·平盈利腿", + target_down_win_leg: "期期下破·平盈利腿", + oo_rest_closing: "期期全平·清残腿中", + oo_rest_closed: "期期全平·两腿已平", + orphaned_after_tp: "止盈后持有至到期", + orphaned_option_expiry: "残腿到期", + hold_to_expiry: "持有至到期", + expiry: "到期", + manual: "人工结束", + partial_fail: "半腿失败", + cancelled: "已取消", + tp: "止盈", + sl: "止损", + }; + var key = String(r || "").trim(); + if (!key) return "—"; + return map[key] || key; + } + + function legRoleLabel(role) { + var map = { + perp: "永续腿", + option_hedge: "保险期权", + option_a: "期期腿A", + option_b: "期期腿B", + }; + var key = String(role || "").trim(); + if (!key) return "—"; + return map[key] || key; + } + function tradeTitle(t) { if (!t) return "—"; if (t.source_type === "option_spot") return t.inst_id || "—"; return ( (t.underlying || "") + (t.direction ? " " + t.direction : "") + - (t.plan_close_reason ? " · " + t.plan_close_reason : "") + (t.plan_close_reason ? " · " + closeReasonLabel(t.plan_close_reason) : "") ); } @@ -671,13 +709,13 @@ .map(function (leg) { return ( "" + - escapeHtml(leg.leg_role || "") + + escapeHtml(legRoleLabel(leg.leg_role)) + "" + escapeHtml(leg.inst_id || leg.symbol || "") + "" + fmtPnl(leg.realized_pnl) + "" + - escapeHtml(leg.close_reason || "") + + escapeHtml(closeReasonLabel(leg.close_reason)) + "" ); }) @@ -699,10 +737,12 @@ var lines = items .slice(0, 8) .map(function (g) { + var keyLabel = + title === "对冲结束原因" ? closeReasonLabel(g.key) : String(g.key || ""); return ( '
' + '' + - escapeHtml(g.key) + + escapeHtml(keyLabel) + " · " + g.count + "笔" + @@ -947,12 +987,13 @@ ($("or-f-inst") || {}).value = t.source_type === "option_spot" ? t.inst_id || "" - : (t.source_label || "") + (t.plan_close_reason ? " · " + t.plan_close_reason : ""); + : (t.source_label || "") + + (t.plan_close_reason ? " · " + closeReasonLabel(t.plan_close_reason) : ""); ($("or-f-pnl") || {}).value = fmtPnl(t.realized_pnl_total); ($("or-f-hold") || {}).value = fmtHold(t.hold_seconds); setSelectValue($("or-f-strategy"), e.strategy_tag || ""); setSelectValue($("or-f-direction"), e.direction_view || autoDirection(t)); - ($("or-f-exit") || {}).value = e.exit_reason || t.plan_close_reason || ""; + ($("or-f-exit") || {}).value = e.exit_reason || closeReasonLabel(t.plan_close_reason) || ""; ($("or-f-followed") || {}).value = e.followed_plan || ""; setSelectValue($("or-f-result"), e.result_tag || autoResultTag(t.realized_pnl_total)); setSelectValue($("or-f-entry"), e.entry_logic || ""); @@ -1008,13 +1049,13 @@ .map(function (leg) { return ( "" + - escapeHtml(leg.leg_role || "") + + escapeHtml(legRoleLabel(leg.leg_role)) + "" + escapeHtml(leg.inst_id || leg.symbol || "") + "" + fmtPnl(leg.realized_pnl) + "" + - escapeHtml(leg.close_reason || "") + + escapeHtml(closeReasonLabel(leg.close_reason)) + "" ); }) diff --git a/lib/options/templates/options_review_panel.html b/lib/options/templates/options_review_panel.html index 138a109..7b3f52e 100644 --- a/lib/options/templates/options_review_panel.html +++ b/lib/options/templates/options_review_panel.html @@ -394,4 +394,4 @@
- +