From 8afaea1ea67e7dcc68d518d6d4c8b9b16ae2cf16 Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 14 Jul 2026 12:59:24 +0800 Subject: [PATCH] Allow entering sheet counts for each options-options hedge leg. Co-authored-by: Cursor --- lib/common/static/hedge_plan.js | 80 +++++++++++++++---- lib/common/static/instance_theme.css | 20 +++++ .../templates/hedge_plan_panel.html | 19 ++++- lib/instance/templates/embed_shell.html | 2 +- lib/instance/templates/index.html | 2 +- 5 files changed, 104 insertions(+), 19 deletions(-) diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index 2f5d8a6..7fc1eac 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -494,26 +494,64 @@ } function renderOoLegs() { - const el = $("hp-oo-legs"); - if (!el) return; - function one(tag, c) { - if (!c) return tag + ": —"; - return ( + function fill(tag, c, infoId, sheetsId) { + const info = $(infoId); + const sheets = $(sheetsId); + if (!info) return; + if (!c) { + info.textContent = tag + ": 尚未选用"; + if (sheets) { + sheets.disabled = true; + sheets.value = "1"; + } + return; + } + info.innerHTML = tag + - ": " + + ": " + c.opt_type + " K" + c.strike + - " " + + " " + (c.moneyness_label || "") + - " ask=" + + " · 卖一 " + fmtPxSz(c.ask, c.ask_sz, c.ask_estimated, c.tick_sz) + - " (" + + " " + c.inst_id + - ")" - ); + ""; + if (sheets) sheets.disabled = false; } - el.innerHTML = one("腿A", state.legA) + "
" + one("腿B", state.legB); + fill("腿A", state.legA, "hp-oo-leg-a-info", "hp-oo-sheets-a"); + fill("腿B", state.legB, "hp-oo-leg-b-info", "hp-oo-sheets-b"); + updateOoPremiumLine(); + } + + function ooSheets(id) { + const n = Number(($(id) && $(id).value) || 1); + return n > 0 ? n : 1; + } + + function updateOoPremiumLine() { + const line = $("hp-oo-prem-line"); + if (!line) return; + if (!state.legA && !state.legB) { + line.textContent = ""; + return; + } + function prem(c, sheets) { + if (!c) return 0; + return Number(c.ask || 0) * sheets * Number(c.ct_mult || 0.01); + } + const a = prem(state.legA, ooSheets("hp-oo-sheets-a")); + const b = prem(state.legB, ooSheets("hp-oo-sheets-b")); + line.textContent = + "预估权利金 A " + + fmt(a, 4) + + " + B " + + fmt(b, 4) + + " ≈ " + + fmt(a + b, 4) + + " USDC"; } function legPayload(c, sheets) { @@ -543,7 +581,15 @@ if ($("hp-target")) $("hp-target").value = ""; if ($("hp-sel-inst")) $("hp-sel-inst").textContent = "—"; if ($("hp-premium-line")) $("hp-premium-line").textContent = ""; - if ($("hp-oo-legs")) $("hp-oo-legs").textContent = "尚未选用两腿"; + if ($("hp-oo-sheets-a")) { + $("hp-oo-sheets-a").value = "1"; + $("hp-oo-sheets-a").disabled = true; + } + if ($("hp-oo-sheets-b")) { + $("hp-oo-sheets-b").value = "1"; + $("hp-oo-sheets-b").disabled = true; + } + renderOoLegs(); void refreshAll(); } @@ -561,8 +607,8 @@ plan_type: "options_options", target_price: target, index_px: (state.chain && state.chain.index_px) || target, - leg_a: legPayload(state.legA, 1), - leg_b: legPayload(state.legB, 1), + leg_a: legPayload(state.legA, ooSheets("hp-oo-sheets-a")), + leg_b: legPayload(state.legB, ooSheets("hp-oo-sheets-b")), }; } else { if (!state.selected) throw new Error("请选用期权腿"); @@ -708,6 +754,10 @@ if ($("hp-exp-select")) $("hp-exp-select").addEventListener("change", renderListStrikes); if ($("hp-oo-exp-select")) $("hp-oo-exp-select").addEventListener("change", renderTStrikes); if ($("hp-sheets")) $("hp-sheets").addEventListener("input", updatePremiumLine); + ["hp-oo-sheets-a", "hp-oo-sheets-b"].forEach(function (id) { + const el = $(id); + if (el) el.addEventListener("input", updateOoPremiumLine); + }); if ($("hp-preview-btn")) $("hp-preview-btn").addEventListener("click", function () { state.mode = "perp_options"; diff --git a/lib/common/static/instance_theme.css b/lib/common/static/instance_theme.css index 41b61ba..58c55dd 100644 --- a/lib/common/static/instance_theme.css +++ b/lib/common/static/instance_theme.css @@ -3234,6 +3234,26 @@ html[data-theme="light"] .opt-be-dist-down { .hedge-plan-page-wrap .hp-pnl-neg { color: #ff8a8a; } +.hedge-plan-page-wrap .hp-oo-legs { + margin-top: 8px; + display: flex; + flex-direction: column; + gap: 8px; +} +.hedge-plan-page-wrap .hp-oo-leg-row { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 8px; + padding: 8px 10px; + border-radius: 8px; + background: rgba(255, 255, 255, 0.03); + border: 1px solid rgba(255, 255, 255, 0.06); +} +.hedge-plan-page-wrap .hp-oo-leg-row input[type="number"] { + width: 72px; +} .hedge-plan-page-wrap .form-row label, .hedge-plan-page-wrap .form-row select, .hedge-plan-page-wrap .form-row input, diff --git a/lib/hedge_plan/templates/hedge_plan_panel.html b/lib/hedge_plan/templates/hedge_plan_panel.html index 732d1b7..01e85c6 100644 --- a/lib/hedge_plan/templates/hedge_plan_panel.html +++ b/lib/hedge_plan/templates/hedge_plan_panel.html @@ -124,7 +124,22 @@
-
尚未选用两腿
+

单位说明:目标价=指数价(USD) · 张数=期权张(整张) · 权利金结算币=USDC

+
+
+
腿A: 尚未选用
+ +
+
+
腿B: 尚未选用
+ +
+

+

期权 T 型报价

@@ -195,4 +210,4 @@
- + diff --git a/lib/instance/templates/embed_shell.html b/lib/instance/templates/embed_shell.html index 60fcc9a..6727e48 100644 --- a/lib/instance/templates/embed_shell.html +++ b/lib/instance/templates/embed_shell.html @@ -7,7 +7,7 @@ - + {{ exchange_display }} · 加密货币 | 交易监控复盘系统 diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index d91d18a..0aa0c43 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -17,7 +17,7 @@ {{ exchange_display }} · 加密货币 | 交易监控复盘系统 - +