Align options realtime PnL with bid-net and show totals in stats.

Header float PnL now uses bid recycle minus premium like position cards. Stats adds realized/open/total net PnL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-15 22:00:45 +08:00
parent 60f3437c73
commit ee7be3e7f3
14 changed files with 198 additions and 19 deletions
+17 -4
View File
@@ -6961,10 +6961,17 @@ def api_account_snapshot():
options_unrealized_pnl = None
if OKX_OPTIONS_ENABLED and exchange_options.apiKey:
try:
from lib.exchange.okx_options_lib import fetch_options_unrealized_pnl_usdc
from lib.instance.instance_live_pnl_lib import merge_unrealized_pnl_components
from lib.options.options_positions_lib import sum_options_net_pnl_usdc
options_unrealized_pnl = fetch_options_unrealized_pnl_usdc(exchange_options)
opt_cfg = app.extensions.get("options_cfg")
if opt_cfg:
# 与持仓卡「净盈亏」同口径(买一回收−权利金),不用交易所标记价 upl
options_unrealized_pnl = sum_options_net_pnl_usdc(opt_cfg, exchange_options)
else:
from lib.exchange.okx_options_lib import fetch_options_unrealized_pnl_usdc
options_unrealized_pnl = fetch_options_unrealized_pnl_usdc(exchange_options)
unrealized_pnl = merge_unrealized_pnl_components(unrealized_pnl, options_unrealized_pnl)
except Exception:
options_unrealized_pnl = None
@@ -7372,9 +7379,15 @@ def api_price_snapshot():
options_unrealized_pnl = None
if OKX_OPTIONS_ENABLED and exchange_options.apiKey:
try:
from lib.exchange.okx_options_lib import fetch_options_unrealized_pnl_usdc
from lib.options.options_positions_lib import sum_options_net_pnl_usdc
options_unrealized_pnl = fetch_options_unrealized_pnl_usdc(exchange_options)
opt_cfg = app.extensions.get("options_cfg")
if opt_cfg:
options_unrealized_pnl = sum_options_net_pnl_usdc(opt_cfg, exchange_options)
else:
from lib.exchange.okx_options_lib import fetch_options_unrealized_pnl_usdc
options_unrealized_pnl = fetch_options_unrealized_pnl_usdc(exchange_options)
except Exception:
options_unrealized_pnl = None