对齐币本位期权:现货缓冲开仓、页头 ETH/BTC 余额与默认 coin 模式。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 15:01:19 +08:00
parent 432adfb602
commit c8688a11ae
26 changed files with 6218 additions and 3758 deletions
+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)