Skip to content

Add market data backend code review - #6

Merged
dobidobi77-bot merged 1 commit into
mainfrom
docs/market-data-review
Sep 10, 2026
Merged

dobidobi77-bot merged 1 commit into
mainfrom
docs/market-data-review

Conversation

@dobidobi77-bot

Copy link
Copy Markdown
Owner

Comprehensive review of backend/app/market/ and its test suite, written to planning/MARKET_DATA_REVIEW.md. Supersedes the round-1 review in planning/archive/.

Test results

All round-1 action items were applied and the suite is green: 73 passed, 91% coverage, ruff check clean.

Two defects the passing suite does not catch

Both verified empirically, not inferred from reading.

1. The Massive (real market data) path is 100% non-functional. massive_client.py:103 reads snap.last_trade.timestamp — a field absent from the SDK's LastTrade model (it's sip_timestamp). The AttributeError is swallowed by the skip-malformed-snapshot handler two lines down, so every well-formed snapshot is dropped and the cache is never written. Set MASSIVE_API_KEY and the whole app has no prices. The same lines also divide by 1000 assuming milliseconds; Polygon timestamps are nanoseconds.

It survived testing because test_massive.py's _make_snapshot builds a MagicMock and assigns the invented field — test and code share one wrong assumption. Coverage on that module is 94%.

2. Shock events swamp the GBM engine by ~317x in variance. With event_probability=0 the math is exact (AAPL/GOOGL correlation 0.598 vs target 0.60; realized sigma 0.221 vs configured 0.22). At the shipped 0.001, correlation collapses to 0.003 and realized volatility runs 8-28x configured and roughly equal across all tickers — so the per-ticker sigma tuning and the entire Cholesky correlation design are inert. Prices wander 9.2%/hour instead of 0.7%.

Also covered

  • Verified SSE wire format documented for the frontend, closing PLAN A5 — unnamed events, one frame keyed by ticker, change_percent included
  • No SSE keepalive: 6s idle yields 520 bytes, all from the initial burst
  • Ticker normalization diverges between the two MarketDataSource implementations
  • Module-level router singleton defeats the cache injection its own docstring promises
  • Findings against PLAN A1/A2/A3, including that TickerSnapshot.prev_day and todays_change_percent would close A1 for free
  • A section on why 73 tests and 91% coverage missed both defects, and what to change structurally

Documentation only — no source changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VGUSZLyF2LLqRMz18yg2Re

Comprehensive review of backend/app/market/ and its test suite.
Test suite is green (73 passed, 91% coverage, ruff clean), but two
defects pass through it undetected:

- The Massive data source never populates the price cache: it reads
  snap.last_trade.timestamp, a field absent from the SDK's LastTrade
  model, and the resulting AttributeError is swallowed by the
  skip-malformed-snapshot handler. Timestamps are also nanoseconds,
  not milliseconds.
- Shock events exceed GBM diffusion variance by ~317x, collapsing
  inter-ticker correlation from 0.60 to 0.003 and inflating realized
  volatility 8-28x above the configured per-ticker sigma.

Also documents the verified SSE wire format (closing PLAN A5), the
missing keepalive, ticker-normalization divergence between the two
MarketDataSource implementations, and the module-level router
singleton that defeats cache injection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKCL7F4QhyBuoDcxXrgipW
@dobidobi77-bot
dobidobi77-bot merged commit 2ab7f42 into main Sep 10, 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.

1 participant