修复币本位期权杠杆显示:按1/卖一而非指数/卖一

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 12:18:15 +08:00
parent 72c84bb993
commit 1314349fe5
3 changed files with 28 additions and 3 deletions
+13 -1
View File
@@ -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;
}
+14 -1
View File
@@ -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)
+1 -1
View File
@@ -64,7 +64,7 @@
<th>类型</th>
<th>合约</th>
<th>卖一/张</th>
<th title="指数÷卖一(每1币)">杠杆</th>
<th title="USDC:指数÷卖一;币本位:1÷卖一(卖一为币报价)">杠杆</th>
<th>买一/张</th>
<th>到期平衡</th>
<th>距平衡</th>