Skip to content

Complete the market data backend: session baseline, backfill, heartbeat - #3

Merged
EnigmaticFuel merged 1 commit into
mainfrom
claude/issue-2-20260803-1841
Aug 3, 2026
Merged

Complete the market data backend: session baseline, backfill, heartbeat#3
EnigmaticFuel merged 1 commit into
mainfrom
claude/issue-2-20260803-1841

Conversation

@EnigmaticFuel

Copy link
Copy Markdown
Owner

Implements the one remaining piece of backend/app/market/ called out in PLAN.md and detailed in planning/MARKET_DATA_DESIGN.md: session baseline (open_price/change_from_open_percent), bounded sparkline history with backfill, deterministic parameter synthesis for unknown tickers, a fixed Massive timestamp bug, and an SSE heartbeat. Full test suite updated, including a new conformance suite.

Closes #2.

⚠️ The sandbox this ran in could not execute uv/pytest/ruff, so please run the test suite before merging.

Generated with Claude Code

Implements the one remaining piece of backend/app/market/ called out in
PLAN.md section 6/13 and detailed in planning/MARKET_DATA_DESIGN.md:

- Session baseline: PriceUpdate/PriceCache gain open_price and
  change_from_open_percent, pinned on each ticker's first tick and
  carried forward across later updates.
- Bounded per-ticker history (deque, one point/minute) with
  seed_history()/get_history(), so /api/watchlist can serve populated
  sparklines on first paint. PriceCache.version now only advances on a
  real price change, keeping SSE quiet in an idle market.
- Deterministic parameter synthesis (SHA-256 of the symbol) for unknown
  tickers, replacing random.uniform(), which repriced a held position
  on every restart.
- GBMSimulator.backfill_history() manufactures ~60 points of prior
  history ending at the live price; wired into
  SimulatorDataSource.start()/add_ticker().
- MassiveDataSource: fixed the nanosecond/millisecond timestamp bug
  (prices were landing ~50,000 years in the future), added a
  last_trade -> min -> day quote fallback chain, exponential backoff
  on poll failure, and per-ticker history backfill via get_aggs().
  Pinned massive==2.2.0 to match the documented model shapes.
- SSE stream: 15s heartbeat comment frame so the frontend can tell
  "quiet market" from "backend stalled"; moved APIRouter construction
  inside create_stream_router() to stop double route registration.
- New app/market/tickers.py: single normalize_ticker()/TICKER_PATTERN
  shared by the manual and LLM watchlist paths (not yet built).
- wait_for_price() helper for the just-added-ticker trade race.
- Updated/added unit tests across every changed module, including a
  conformance suite that runs the MarketDataSource lifecycle contract
  against both the simulator and (mocked) Massive implementations.

Co-authored-by: Essam Hasin <123895080+EnigmaticFuel@users.noreply.github.com>
@EnigmaticFuel
EnigmaticFuel merged commit 1b63c9f into main Aug 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build complete Market Data backend

1 participant