Complete the market data backend per planning docs - #3
Merged
Conversation
…RKET_SIMULATOR.md, MASSIVE_API.md Implements the reviewed design for the market data subsystem, fixing bugs identified in the project's own planning docs rather than leaving them latent: - Massive client: fixed the nanosecond `sip_timestamp` field (was reading a nonexistent `.timestamp` in ms, silently swallowed by the exception handler), set retries=0 (SDK's default backoff is inside the same rate-limit window), classified rate-limit errors distinctly from bad responses, captured `prev_day.close` as the daily-change baseline, and surfaced tickers missing from a poll instead of dropping them silently. - New capabilities.py: probes Massive entitlement once at startup, since a free/Basic-tier key authenticates but can't return any live price. - New anchored.py: AnchoredSimulatorDataSource anchors the GBM simulator to real closing prices (one free-tier API call) for keys that are valid but not live-entitled, so a free key still produces a moving, realistic terminal instead of an empty watchlist. - factory.py: now async and capability-probe-driven instead of routing on key presence alone; every branch returns a working source. - Simulator: unknown-ticker seeds are now deterministic (hashed) instead of random per restart; random events are a decaying overlay instead of a permanent level shift (the old calibration inflated realized volatility ~20x); added a LinAlgError fallback and a 5-minute prefilled history ring buffer per ticker. - models.py: PriceUpdate now carries a fixed session `open_price` baseline (change_today/change_percent_today) alongside the existing tick-to-tick change (renamed direction -> tick_direction); wire format is ISO 8601 UTC. - stream.py: SSE heartbeat so idle connections (closed market, slow Massive poll) don't silently die at a proxy. - MarketDataSource interface: added describe() (for /api/health) and get_history() (so charts aren't empty on first paint). - Refreshed seed_prices.py to real closing prices (NVDA/NFLX were 3-7x off after 2024 splits). Rewrote and substantially expanded the unit test suite across all of the above (models, cache, interface, capabilities, simulator, simulator source, massive client, anchored source, factory, SSE stream), including statistical regression tests for the GBM calibration and the shock-decay fix. All Massive API calls are mocked; no test touches the network. Closes #2 Co-authored-by: cloudnote18-lab <290535093+cloudnote18-lab@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the reviewed design in
planning/MARKET_INTERFACE.md,planning/MARKET_SIMULATOR.mdandplanning/MASSIVE_API.md, fixing bugs documented in those docs: the Massive nanosecond timestamp bug, non-deterministic unknown-ticker seeds, mis-calibrated permanent price shocks, missing daily-change baseline, stale seed prices, no SSE heartbeat, no capability-aware source selection, and no chart-history backfill. Adds a capability-probing factory, an AnchoredSimulatorDataSource for free-tier Massive keys, and a substantially expanded mocked-only unit test suite.Closes #2.
🤖 Generated with Claude Code