Include options unrealized PnL in OKX instance header realtime PnL total.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 11:05:52 +08:00
parent 75a64c5d24
commit f68197b775
6 changed files with 102 additions and 2 deletions
+13
View File
@@ -615,6 +615,19 @@ def fetch_option_positions(ex: ccxt.okx) -> list[dict[str, Any]]:
return []
def fetch_options_unrealized_pnl_usdc(ex: ccxt.okx) -> float | None:
"""期权持仓未实现盈亏合计(USDC,统计口径与 USDT 1:1)。"""
total = 0.0
found = False
for pos in fetch_option_positions(ex):
upl = _safe_float(pos.get("upl"))
if upl is None:
continue
found = True
total += upl
return round(total, 4) if found else None
def estimate_usdt_to_usdc(ex: ccxt.okx, usdt_amount: float) -> dict[str, Any]:
if usdt_amount <= 0:
return {"ok": False, "msg": "兑换数量须大于 0"}