From 1314349fe57c160a41f6899c166e0098e5424df6 Mon Sep 17 00:00:00 2001 From: dekun Date: Thu, 20 Aug 2026 12:18:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B8=81=E6=9C=AC=E4=BD=8D?= =?UTF-8?q?=E6=9C=9F=E6=9D=83=E6=9D=A0=E6=9D=86=E6=98=BE=E7=A4=BA:?= =?UTF-8?q?=E6=8C=891/=E5=8D=96=E4=B8=80=E8=80=8C=E9=9D=9E=E6=8C=87?= =?UTF-8?q?=E6=95=B0/=E5=8D=96=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- lib/common/static/options_panel.js | 14 +++++++++++++- lib/options/options_pricing_lib.py | 15 ++++++++++++++- lib/options/templates/options_panel.html | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/common/static/options_panel.js b/lib/common/static/options_panel.js index ef6fae8..919b470 100644 --- a/lib/common/static/options_panel.js +++ b/lib/common/static/options_panel.js @@ -946,6 +946,11 @@ return Number(v).toFixed(2); } + function isCoinMarginMode() { + const ch = state.chain || {}; + return ch.margin_mode === "coin" || ch.options_margin_mode === "coin"; + } + function calcContractLeverage(indexPx, ethAmount, totalPremium) { if (indexPx == null || ethAmount == null || totalPremium == null) return null; const idx = Number(indexPx); @@ -954,6 +959,10 @@ if (!Number.isFinite(idx) || !Number.isFinite(amt) || !Number.isFinite(prem) || amt <= 0 || prem <= 0) { return null; } + // USDC: 名义(U)/权利金(U)=指数×币数/权利金; 币本位权利金为币: 名义(U)/(权利金币×指数)=币数/权利金币 + if (isCoinMarginMode()) { + return Math.round((amt / prem) * 10) / 10; + } return Math.round((idx * amt) / prem * 10) / 10; } @@ -962,12 +971,15 @@ return "约 " + Number(v).toFixed(1) + "×"; } - /** 链上展示:指数 ÷ 卖一(每1币). */ + /** 链上展示:USDC=指数÷卖一(美元);币本位卖一为币报价 → 1÷卖一. */ function calcAskLeverage(indexPx, askPx) { if (indexPx == null || askPx == null) return null; const idx = Number(indexPx); const ask = Number(askPx); if (!Number.isFinite(idx) || !Number.isFinite(ask) || ask <= 0) return null; + if (isCoinMarginMode()) { + return Math.round((1 / ask) * 10) / 10; + } return Math.round((idx / ask) * 10) / 10; } diff --git a/lib/options/options_pricing_lib.py b/lib/options/options_pricing_lib.py index d049e2a..82551fe 100644 --- a/lib/options/options_pricing_lib.py +++ b/lib/options/options_pricing_lib.py @@ -512,12 +512,25 @@ def equivalent_contract_leverage( index_px: float | None, eth_amount: float | None, total_premium: float | None, + margin_mode: str | None = None, ) -> float | None: - """名义价值 / 权利金,近似相当于永续合约杠杆倍数(测算用).""" + """名义价值 / 权利金,近似相当于永续合约杠杆倍数(测算用). + + USDC: 权利金为美元 → index×eth/premium. + 币本位: 权利金为币 → eth/premium(=1/ask 当 premium=ask×eth). + """ if index_px is None or eth_amount is None or total_premium is None: return None if eth_amount <= 0 or total_premium <= 0: return None + try: + from lib.options.options_margin_mode_lib import normalize_options_margin_mode + + mode = normalize_options_margin_mode(margin_mode) + except Exception: + mode = (str(margin_mode or "usdc").strip().lower() or "usdc") + if mode == "coin": + return round(float(eth_amount) / float(total_premium), 1) return round(float(index_px) * float(eth_amount) / float(total_premium), 1) diff --git a/lib/options/templates/options_panel.html b/lib/options/templates/options_panel.html index 38b6304..b09883c 100644 --- a/lib/options/templates/options_panel.html +++ b/lib/options/templates/options_panel.html @@ -64,7 +64,7 @@ 类型 合约 卖一/张 - 杠杆 + 杠杆 买一/张 到期平衡 距平衡