Dashboard: don't window the small day-scoped reads for live

The 45-min live window I added to fills_feed + session_pnl's closed-trades query
hid the day's earlier fills/closures (and broke two projection tests whose
fixtures use a fixed past date). Those event types (order_filled/submitted,
position_closed) are tiny, so live now reads them UNBOUNDED via _hist_window;
only a historical YYYY-MM-DD bounds to that day. watch_states keeps its 45-min
window (criteria_evaluated is the big one, ~99k/day, and it's live-only).

tests/unit/storage/test_interactive_projections.py: 6 passed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
momentum devandClaude Opus 4.8 committed 2026-06-18 22:03:49 -04:00
1 parent 9392e0d4d3
commit 66889bbb15
1 file changed
+17 -2
+17 -2
View File
@@ -46,6 +46,21 @@ def _state_until(for_date: str | None = None) -> str | None:
return None
def _hist_window(for_date: str | None = None) -> tuple[str | None, str | None]:
"""(since, until) for DAY-SCOPED reads (fills, closed trades). Live = UNBOUNDED
(these event types are tiny — fills/closed are rare), so an idle loop or a
test's fixed-date fixtures still show. A 'YYYY-MM-DD' = that whole day."""
from datetime import datetime, timedelta
if for_date and str(for_date).lower() not in ("live", "today", ""):
try:
d = datetime.fromisoformat(str(for_date)).date()
start = datetime(d.year, d.month, d.day)
return (start.isoformat(), (start + timedelta(days=1)).isoformat())
except (TypeError, ValueError):
pass
return (None, None)
def _latest_event_payload(store, event_type: str, until: str | None = None):
"""The single most-recent event payload of a type (optionally before
`until`) via a DESC-LIMIT-1 index seek — O(1) vs loading the whole history.
@@ -447,7 +462,7 @@ def query_symbol_criteria(store, symbol: str, session_id: str | None = None) ->
def query_fills_feed(store, limit: int = 50, for_date: str | None = None) -> list[dict]:
"""Chronological fills + submissions for the activity feed (newest first)."""
since, until = _evt_window(for_date)
since, until = _hist_window(for_date)
rows: list[dict] = []
for event_type in ("order_filled", "order_submitted"):
for event in store.query_events(event_type=event_type, since=since,
@@ -488,7 +503,7 @@ def query_session_pnl(store, session_id: str | None = None,
"""Day P&L + trade stats. Realized comes from the broker equity delta (the
closed-event reconstruction reads $0); unrealized from the latest positions
snapshot. ``for_date`` scopes it to a past session for the date picker."""
since, until = _evt_window(for_date)
since, until = _hist_window(for_date)
closed = store.query_events(event_type="position_closed",
since=since, until=until, limit=None)