fix: show header realtime PnL from exchange positions and order metrics

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 02:04:40 +08:00
parent 3b494932c7
commit 659c0969fe
7 changed files with 234 additions and 41 deletions
+9 -2
View File
@@ -6750,6 +6750,9 @@ def api_account_snapshot():
open_guard_enabled = get_trading_day_reset_open_guard_enabled(conn)
opens_today = count_opens_for_trading_day(conn, trading_day)
risk_status = hub_account_risk_status(conn)
active_pnl_rows = conn.execute(
"SELECT exchange_symbol, symbol, direction FROM order_monitors WHERE status='active'"
).fetchall()
conn.close()
open_guard_blocks_now = open_guard_enabled and now.hour < TRADING_DAY_RESET_HOUR
can_trade = can_trade_new_open(
@@ -6763,7 +6766,7 @@ def api_account_snapshot():
available_trading_usdt = get_available_trading_usdt()
unrealized_pnl = None
if exchange_private_api_configured():
from lib.instance.instance_live_pnl_lib import fetch_unrealized_pnl
from lib.instance.instance_live_pnl_lib import resolve_instance_unrealized_pnl
def _okx_positions():
ensure_markets_loaded()
@@ -6772,7 +6775,11 @@ def api_account_snapshot():
except Exception:
return exchange.fetch_positions() or []
unrealized_pnl = fetch_unrealized_pnl(_okx_positions)
unrealized_pnl = resolve_instance_unrealized_pnl(
_okx_positions,
active_pnl_rows,
get_live_position_exchange_metrics,
)
return jsonify({
"funding_usdt": funding_usdt,
"current_capital": current_capital,