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
+21
View File
@@ -6892,6 +6892,16 @@ def api_account_snapshot():
active_pnl_rows,
get_live_position_exchange_metrics,
)
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
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
return jsonify({
"funding_usdt": funding_usdt,
"current_capital": current_capital,
@@ -6907,6 +6917,7 @@ def api_account_snapshot():
),
"available_trading_usdt": round(available_trading_usdt, FUNDS_DECIMALS) if available_trading_usdt is not None else None,
"unrealized_pnl": unrealized_pnl,
"options_unrealized_pnl": options_unrealized_pnl,
"recommended_capital": recommended_capital,
"active_count": position_limit_count,
"max_active_positions": MAX_ACTIVE_POSITIONS,
@@ -7282,12 +7293,22 @@ def api_price_snapshot():
format_mark_display=lambda sym, px: format_price_for_symbol(sym, px),
)
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
options_unrealized_pnl = fetch_options_unrealized_pnl_usdc(exchange_options)
except Exception:
options_unrealized_pnl = None
return jsonify({
"updated_at": app_now_str(),
"key_prices": key_prices,
"order_prices": order_prices,
"position_marks": position_marks,
"positions_raw_count": len(all_swap_positions),
"options_unrealized_pnl": options_unrealized_pnl,
**force_close_template_context(
FORCE_CLOSE_ENABLED,
FORCE_CLOSE_BJ_HOUR,