From 4a3afdfb481fbd5de9b01ebe85bfc2658715b2fe Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 7 Jul 2026 13:09:39 +0800 Subject: [PATCH] Fix monitor board crash: avoid shadowing options_open_position_count helper. Rename the imported counter function so aggregate_monitor_board_totals no longer overwrites it with an int accumulator. Co-authored-by: Cursor --- lib/hub/hub_monitor_totals_lib.py | 7 +++++-- tests/test_hub_monitor_totals_lib.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/hub/hub_monitor_totals_lib.py b/lib/hub/hub_monitor_totals_lib.py index d3beb68..bc55a32 100644 --- a/lib/hub/hub_monitor_totals_lib.py +++ b/lib/hub/hub_monitor_totals_lib.py @@ -3,7 +3,10 @@ from __future__ import annotations from typing import Any -from lib.hub.hub_options_funds_lib import options_float_pnl_usdt, options_open_position_count +from lib.hub.hub_options_funds_lib import ( + options_float_pnl_usdt, + options_open_position_count as count_options_positions, +) def _coerce_float(value: Any) -> float | None: @@ -83,7 +86,7 @@ def aggregate_monitor_board_totals( 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) + opt_count = count_options_positions(opt_snap) options_open_position_count += opt_count open_position_count += opt_count opt_upl = options_float_pnl_usdt(opt_snap) diff --git a/tests/test_hub_monitor_totals_lib.py b/tests/test_hub_monitor_totals_lib.py index 702eefe..dc7d6e5 100644 --- a/tests/test_hub_monitor_totals_lib.py +++ b/tests/test_hub_monitor_totals_lib.py @@ -43,6 +43,26 @@ def test_aggregate_monitor_board_totals_sums_rows(): assert out["float_pnl_u"] == 1.2 +def test_aggregate_monitor_board_totals_includes_options(): + rows = [ + { + "capabilities": ["options"], + "options": { + "ok": True, + "enabled": True, + "positions": [{"inst_id": "X"}, {"inst_id": "Y"}], + "upl_total_usdc": 1.5, + }, + "agent": {"positions": [], "total_unrealized_pnl": 0}, + } + ] + out = aggregate_monitor_board_totals(rows, trading_day="2026-07-04", reset_hour=8) + assert out["options_open_position_count"] == 2 + assert out["open_position_count"] == 2 + assert out["options_float_pnl_u"] == 1.5 + assert out["float_pnl_u"] == 1.5 + + def test_summarize_trades_win_loss_amounts(): from lib.hub.hub_trades_lib import summarize_trades