From 37428c0bf9e1fcf14f34c5f20678ed71aef97d45 Mon Sep 17 00:00:00 2001 From: dekun Date: Wed, 14 Oct 2026 21:59:17 +0800 Subject: [PATCH] Show OKX option Delta on hedge plan strike picker. Surface ticker delta (gamma in tooltip) in the chain table and selected premium line for easier ITM selection. Co-authored-by: Cursor --- lib/common/static/hedge_plan.js | 28 ++++++++++++++++--- lib/exchange/okx_options_lib.py | 7 +++++ .../templates/hedge_plan_panel.html | 5 ++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index 99d9fec..27a5847 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -894,6 +894,14 @@ } /** CoinOX 币本位:卖一为币报价 → 杠杆≈1÷卖一(与期权页一致). */ + function fmtDelta(v) { + const n = Number(v); + if (v == null || Number.isNaN(n)) return "—"; + // Call 多为正,Put 多为负;保留两位便于对比实虚值 + const s = fmt(n, 2); + return n > 0 ? "+" + s : s; + } + function calcIndexAskLeverage(ask) { const a = Number(ask); if (!(a > 0)) return "—"; @@ -2262,7 +2270,7 @@ const want = optTypeForDirection(getDirection()); const exp = currentExp("hp-exp-select"); const prevInst = state.selected && state.selected.inst_id; - const cols = isOptionPrimary() ? 7 : 6; + const cols = isOptionPrimary() ? 8 : 7; tbody.innerHTML = ""; if (!exp) { tbody.innerHTML = '请选择到期日'; @@ -2302,13 +2310,21 @@ tr.className = "opt-strike-row" + (c.moneyness ? " opt-row-" + c.moneyness : ""); if (prevInst && c.inst_id === prevInst) tr.classList.add("opt-row-selected"); tr.setAttribute("data-inst", c.inst_id); + const deltaCell = + '' + + fmtDelta(c.delta) + + ""; if (isOptionPrimary()) { tr.innerHTML = "" + c.strike + "" + moneynessBadge(c) + - "" + + "" + + deltaCell + + '' + (c.inst_id || "") + '' + fmtPxSz(c.ask, c.ask_sz, c.ask_estimated, c.tick_sz) + @@ -2327,7 +2343,9 @@ c.strike + "" + moneynessBadge(c) + - '' + + "" + + deltaCell + + '' + calcIndexAskLeverage(c.ask) + '' + fmtPxSz(c.ask, c.ask_sz, c.ask_estimated, c.tick_sz) + @@ -2366,6 +2384,7 @@ // U 以期权标的指数为准(买 BTC/ETH 开期权);跨币不可用永续 ETH 价 const buyPx = Number(optionIndexPx() || 0); const premU = buyPx > 0 ? prem * buyPx : null; + const dlt = state.selected.delta; line.textContent = "权利金 ≈ " + fmt(prem, 4) + @@ -2374,7 +2393,8 @@ (premU != null ? " / " + fmt(premU, 2) + " U" : "") + " · 卖一 " + fmt(ask, 4) + - (buyPx > 0 ? " · 买" + optionCoin() + "参考 " + fmt(buyPx, 2) : ""); + (buyPx > 0 ? " · 买" + optionCoin() + "参考 " + fmt(buyPx, 2) : "") + + (dlt != null && !Number.isNaN(Number(dlt)) ? " · Δ " + fmtDelta(dlt) : ""); } function buildStraddleRows(contracts) { diff --git a/lib/exchange/okx_options_lib.py b/lib/exchange/okx_options_lib.py index 6dd1186..8c38878 100644 --- a/lib/exchange/okx_options_lib.py +++ b/lib/exchange/okx_options_lib.py @@ -285,6 +285,9 @@ def _resolve_chain_quote( if ask_estimated: ask_sz = None + # OKX 期权 ticker 自带希腊字母(选约用);缺省时前端显示 — + delta = _safe_float(ticker.get("delta") or ticker.get("deltaBS")) + gamma = _safe_float(ticker.get("gamma") or ticker.get("gammaBS")) return { "ask": ask, "bid": bid, @@ -292,6 +295,8 @@ def _resolve_chain_quote( "bid_sz": bid_sz, "mark_px": mark, "ask_estimated": ask_estimated, + "delta": delta, + "gamma": gamma, } @@ -945,6 +950,8 @@ def build_option_chain( "bid_sz": bid_sz, "mark_px": mark, "ask_estimated": q["ask_estimated"], + "delta": q.get("delta"), + "gamma": q.get("gamma"), "expiry_be_px": expiry_be, "dist_expiry_be": strike_distance_to_be(strike, expiry_be, opt_type=opt_type), "moneyness": mny, diff --git a/lib/hedge_plan/templates/hedge_plan_panel.html b/lib/hedge_plan/templates/hedge_plan_panel.html index 47d771c..d83d035 100644 --- a/lib/hedge_plan/templates/hedge_plan_panel.html +++ b/lib/hedge_plan/templates/hedge_plan_panel.html @@ -102,6 +102,7 @@ 行权价 类型 + Delta 合约 卖一/张 杠杆 @@ -110,7 +111,7 @@ - 请刷新期权链 + 请刷新期权链 @@ -508,4 +509,4 @@ - +