Complete the market data backend: session baseline, backfill, heartbeat - #3
Merged
Merged
Conversation
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>
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 one remaining piece of
backend/app/market/called out inPLAN.mdand detailed inplanning/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.
uv/pytest/ruff, so please run the test suite before merging.Generated with Claude Code