修复比特币期权浮盈把币数量当成 U:看板/中控改为按指数折 USDT。
币本位 BTC/ETH 净盈亏须 × 指数后再标 U;并兜底从合约推断 premium_ccy,避免缺失时漏折算。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -125,11 +125,24 @@ def display_pnl_from_option_row(row: dict[str, Any]) -> float | None:
|
||||
|
||||
|
||||
def display_pnl_usdt_from_option_row(row: dict[str, Any]) -> float | None:
|
||||
"""顶栏「实时盈亏」用:币本位净盈亏按指数折 USDT;USDC 仓原样."""
|
||||
"""顶栏/看板「实时盈亏」用:币本位净盈亏按指数折 USDT;USDC 仓原样.
|
||||
|
||||
BTC/ETH 币本位若不折算,会被界面标成 U 而数值仍是币数量(BTC 尤为离谱).
|
||||
"""
|
||||
pnl = display_pnl_from_option_row(row)
|
||||
if pnl is None:
|
||||
return None
|
||||
ccy = str(row.get("premium_ccy") or "USDC").strip().upper() or "USDC"
|
||||
if not ccy or ccy == "USDC":
|
||||
# 兜底:按合约推断币本位,避免 premium_ccy 缺失时把 BTC 盈亏当 U
|
||||
inst = str(row.get("inst_id") or row.get("instId") or "")
|
||||
mode = str(row.get("margin_mode") or "").strip().lower()
|
||||
if mode == "coin" or (
|
||||
"-USD-" in inst.upper() and "_UM" not in inst.upper()
|
||||
):
|
||||
underly = str(row.get("underlying") or (inst.split("-")[0] if inst else "") or "").upper()
|
||||
if underly in ("ETH", "BTC"):
|
||||
ccy = underly
|
||||
if ccy in ("ETH", "BTC"):
|
||||
idx = _safe_float(row.get("idx_px") or row.get("idxPx") or row.get("index_px"))
|
||||
if idx is None or idx <= 0:
|
||||
|
||||
Reference in New Issue
Block a user