Hub funds and dashboard: include OKX options balances in USDT totals.
Merge options USDC/USDT at 1:1 into fund overview snapshots, dashboard aggregation, and monitor board totals while keeping a separate options breakdown in the UI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,6 +3,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from lib.hub.hub_options_funds_lib import options_float_pnl_usdt, options_open_position_count
|
||||
|
||||
|
||||
def _coerce_float(value: Any) -> float | None:
|
||||
if value is None or value == "":
|
||||
@@ -54,7 +56,9 @@ def aggregate_monitor_board_totals(
|
||||
win_pnl_u = 0.0
|
||||
loss_pnl_u = 0.0
|
||||
open_position_count = 0
|
||||
options_open_position_count = 0
|
||||
float_pnl_u = 0.0
|
||||
options_float_pnl_u = 0.0
|
||||
|
||||
for row in rows or []:
|
||||
if not isinstance(row, dict):
|
||||
@@ -78,6 +82,15 @@ def aggregate_monitor_board_totals(
|
||||
else:
|
||||
float_pnl_u += sum(position_unrealized_pnl(p) for p in open_pos)
|
||||
|
||||
opt_snap = row.get("options") if "options" in (row.get("capabilities") or []) else None
|
||||
opt_count = options_open_position_count(opt_snap)
|
||||
options_open_position_count += opt_count
|
||||
open_position_count += opt_count
|
||||
opt_upl = options_float_pnl_usdt(opt_snap)
|
||||
if opt_upl is not None:
|
||||
options_float_pnl_u += opt_upl
|
||||
float_pnl_u += opt_upl
|
||||
|
||||
return {
|
||||
"trading_day": trading_day,
|
||||
"reset_hour": int(reset_hour),
|
||||
@@ -89,5 +102,7 @@ def aggregate_monitor_board_totals(
|
||||
"loss_pnl_u": round(loss_pnl_u, 4),
|
||||
"realized_pnl_u": round(win_pnl_u + loss_pnl_u, 4),
|
||||
"open_position_count": open_position_count,
|
||||
"options_open_position_count": options_open_position_count,
|
||||
"float_pnl_u": round(float_pnl_u, 4),
|
||||
"options_float_pnl_u": round(options_float_pnl_u, 4),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user