顶栏实时盈亏:币本位按 ETH/BTC 指数折算为 USDT。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1617,9 +1617,9 @@ def resolve_option_close_from_history(
|
||||
|
||||
def fetch_options_unrealized_pnl_usdc(ex: ccxt.okx) -> float | None:
|
||||
"""
|
||||
期权浮盈合计(USDC≈U).
|
||||
优先返回交易所标记价 upl;实例顶栏应改用
|
||||
`options_positions_lib.sum_options_net_pnl_usdc`(买一净盈亏)以与持仓卡一致.
|
||||
期权浮盈合计(USDT/USDC≈U).
|
||||
优先返回交易所标记价 upl;币本位 upl 按 idxPx 折 U.
|
||||
实例顶栏应改用 `options_positions_lib.sum_options_net_pnl_usdc`(买一净盈亏)以与持仓卡一致.
|
||||
"""
|
||||
positions = fetch_option_positions(ex)
|
||||
if positions is None:
|
||||
@@ -1630,8 +1630,20 @@ def fetch_options_unrealized_pnl_usdc(ex: ccxt.okx) -> float | None:
|
||||
upl = _safe_float(pos.get("upl"))
|
||||
if upl is None:
|
||||
continue
|
||||
inst = str(pos.get("instId") or "")
|
||||
# 币本位合约:upl 为币;折指数为 U
|
||||
try:
|
||||
from lib.options.options_margin_mode_lib import MODE_COIN, margin_mode_from_inst_id
|
||||
|
||||
if margin_mode_from_inst_id(inst) == MODE_COIN:
|
||||
idx = _safe_float(pos.get("idxPx"))
|
||||
if idx is None or idx <= 0:
|
||||
continue
|
||||
upl = float(upl) * float(idx)
|
||||
except Exception:
|
||||
pass
|
||||
found = True
|
||||
total += upl
|
||||
total += float(upl)
|
||||
return round(total, 4) if found else None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user