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 @@