@@ -136,9 +136,26 @@ def display_pnl_usdt_from_option_row(row: dict[str, Any]) -> float | None:
|
||||
pnl = display_pnl_from_option_row(row)
|
||||
if pnl is None:
|
||||
return None
|
||||
return _coin_amount_to_usdt(pnl, row)
|
||||
|
||||
|
||||
def premium_paid_usdt_from_option_row(row: dict[str, Any]) -> float | None:
|
||||
"""开仓权利金折 USDT:币本位 × 指数;USDC 原样."""
|
||||
paid = _safe_float(row.get("premium_paid"))
|
||||
if paid is None:
|
||||
return None
|
||||
return _coin_amount_to_usdt(paid, row)
|
||||
|
||||
|
||||
def _coin_amount_to_usdt(amount: float, row: dict[str, Any]) -> float | None:
|
||||
"""币本位金额按指数折 U;USDC 原样."""
|
||||
try:
|
||||
n = float(amount)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
ccy = str(row.get("premium_ccy") or "USDC").strip().upper() or "USDC"
|
||||
if not ccy or ccy == "USDC":
|
||||
# 兜底:按合约推断币本位,避免 premium_ccy 缺失时把 BTC 盈亏当 U
|
||||
# 兜底:按合约推断币本位,避免 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 (
|
||||
@@ -150,10 +167,9 @@ def display_pnl_usdt_from_option_row(row: dict[str, Any]) -> float | None:
|
||||
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:
|
||||
# 无指数时无法折算,跳过该仓以免把「币数量」当成 U
|
||||
return None
|
||||
return float(pnl) * float(idx)
|
||||
return float(pnl)
|
||||
return float(n) * float(idx)
|
||||
return float(n)
|
||||
|
||||
|
||||
def sum_options_net_pnl_usdc(
|
||||
|
||||
Reference in New Issue
Block a user