Skip to content

Instructor redo: consolidated market data design doc, rebuilt from clean main - #8

Merged
hengky888 merged 17 commits into
office-developmentfrom
instructor-redo
Aug 12, 2026
Merged

Instructor redo: consolidated market data design doc, rebuilt from clean main#8
hengky888 merged 17 commits into
office-developmentfrom
instructor-redo

Conversation

@hengky888

Copy link
Copy Markdown
Owner

Instructor exercise redone from the clean, finished main version of the project. Branched from main at 5013245, all work on instructor-redo.

Please review — do not merge automatically.

Heads up: this PR is larger than the one commit of new work

office-development is 16 commits behind main. Because this branch was cut from clean main (as intended for the redo), the PR carries those 16 commits plus 1 new one — 17 total, 33 files.

Commits Files
Catch-up from main 16 27
New work in this PR 1 6

office-development is a direct ancestor of this branch, so there are no conflicts — merging brings office-development up to clean main and adds the new document. If you only want the new document, say so and I'll rebase it onto office-development alone.

The new work

planning/MARKET_DATA_DESIGN.md (1,737 lines, 30 code blocks) — a single implementation-ready design of record for the market data subsystem, consolidating the four split documents.

15 sections covering:

  • Unified API (§2-6) — PriceUpdate, PriceCache, the MarketDataSource ABC including ensure_priced, the three-error taxonomy and its 400/503 mapping, symbols.py, and the public re-export surface
  • Simulator (§7) — GBM math with the Itô correction, Cholesky-correlated moves, shock events, seed prices and per-ticker parameters, GBMSimulator and SimulatorDataSource
  • Massive API (§8) — REST-polling rationale, response shape and the ms→s timestamp conversion, the full client, ticker management, rate-limit table, market-hours behaviour
  • Connecting layers (§9-15) — factory, SSE streaming, FastAPI lifespan wiring, watchlist/trade/LLM-trade routes, edge cases, configuration, testing

Written against the as-built code, not as a forward-looking spec

The existing planning docs describe three "unresolved gaps" (SSE cadence, ensure_priced, symbols.py) as still open and label snippets "change required" — but all three are already implemented on main. The suite runs 127 tests at 97% coverage, not the 73 tests at 84% the summary claims. market_data_summary.md's "Recommended Implementation Order" is therefore stale; every item on it has landed.

Every snippet in the new document is the shipped implementation. This was verified mechanically rather than by eye: seed prices, GBM parameters, all four correlation constants, and all 72 symbols in SIMULATED_UNIVERSE were diffed against source and match exactly. Seven of the nine modules are quoted verbatim at 100%; the other two differ only in line-wrapping and trimmed docstrings.

The document records the reasoning behind the non-obvious choices, since that is what a reader cannot recover from the code alone — why the SSE stream emits unconditionally and computes direction per connection, why ensure_priced exists alongside add_ticker, why the no-residue guarantee is achieved by ordering rather than rollback, why the cache rounds at the write boundary, and why there is deliberately no runtime failover from Massive to the simulator.

Supersession and the rename

The four split documents are superseded. planning/market_data_design.md moves to planning/archive/MARKET_DATA_DESIGN_V2.md — renamed rather than kept as market_data_design.md because that would collide with the existing archive/MARKET_DATA_DESIGN.md on case-insensitive filesystems (macOS/Windows), which is the same trap that made the new file's placement a question in the first place.

The ten cross-references in the four remaining companion docs are repointed at the new sections. A link checker confirmed every internal link and anchor across planning/ resolves.

Verification

  • uv run --extra dev pytest127 passed, 97% statement coverage of app/market/
  • All internal markdown links and anchors across planning/ resolve
  • Numeric constants in the doc diffed against source: seed prices, ticker params, correlations, and the 72-symbol universe all match
  • No application code changed in the new commit — documentation only

main was not modified, merged into, or pushed to at any point.


Generated by Claude Code

hengky888 and others added 17 commits July 27, 2026 19:59
…4237013

Add claude GitHub actions 1785224237013
Documents the market data subsystem as the current design of record:
the unified MarketDataSource interface, thread-safe PriceCache, GBM
simulator, Massive REST client, SSE streaming endpoint, and FastAPI
lifecycle integration, with runnable code snippets throughout.

Each snippet is labelled as-built or change-required. The design
resolves three contract gaps raised in review:

- SSE cadence: the stream now emits every priced ticker each tick with
  a per-connection direction, matching the PLAN contract instead of
  falling silent between Massive polls
- Unpriced tickers: adds ensure_priced() to the source interface with
  typed errors, defining how a trade in an unpriced symbol resolves a
  fill price in both modes and why no rollback is needed
- Symbol validation: adds a symbols module with shape validation and a
  simulated universe, so unrecognized symbols are rejected before the
  data source or watchlist is mutated

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C5sUx9qhg2z4ygWmtvcceG
planning/MARKET_DATA_DESIGN.md had grown to 1,550 lines covering the whole
subsystem in one file. Split it along the seams an implementing agent
actually works to, so each document answers one kind of question:

- planning/market_data_design.md — architecture, file structure, SSE
  streaming, FastAPI lifecycle wiring, watchlist/trade coordination,
  cross-cutting edge cases, environment configuration
- planning/market_interface.md — PriceUpdate, PriceCache, the
  MarketDataSource ABC and its per-method expected behaviour, the error
  taxonomy and its HTTP mapping, the factory, the public API surface
- planning/market_simulator.md — GBM math, correlated moves, seed prices,
  symbol validation, GBMSimulator, SimulatorDataSource lifecycle, the
  non-PSD fallback, simulator configuration and tests
- planning/massive_api.md — the Massive/Polygon.io endpoints and response
  shape, the polling client, ticker management, poll intervals and rate
  limits, error handling and fallback behaviour, tests
- planning/market_data_summary.md — executive summary, per-module
  implementation status, key decisions, unresolved review gaps, and the
  ordered implementation plan

Content is preserved rather than rewritten; the source document is removed
now that everything in it has a home. Source-specific material moved to its
source (the 14.x edge cases split across the simulator, Massive, and
architecture documents), and each fact now lives in exactly one file, with
cross-references where a second document needs it.

Renamed planning/MARKET_DATA_SUMMARY.md to planning/market_data_summary.md
and merged the design document's status and delta sections into it. Keeping
both would have left two overlapping summaries whose names differ only by
case, which does not survive a checkout on macOS or Windows. Its stale
"all issues resolved" status is corrected: the three contract gaps are
specified but not yet implemented.

References updated in CLAUDE.md, README.md, and planning/PLAN.md.

Verified: 26 Python snippets parse under ast.parse, all 85 internal links
and anchors resolve, and no substantive paragraph from the source document
was dropped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QTMgygimph2t3UJNGfjyKF
Add detailed market data backend design document
Updated Claude workflow to include additional permissions and trigger phrase.
Adds symbols.py (normalize_symbol/SIMULATED_UNIVERSE/is_simulated),
UnknownSymbolError/PricingUnavailableError + ensure_priced on the
MarketDataSource interface (implemented in both the simulator and
Massive client), rewrites the SSE generator to emit every tick with
per-connection direction in a {seq, ts, prices} envelope, locks the
PriceCache.version read, falls back to independent draws on a
non-PSD correlation matrix, reads MASSIVE_POLL_INTERVAL from env,
and escalates repeated Massive poll failures to ERROR after 3
consecutive failures. Also fixes backend/README.md's `uv sync --dev`
to `uv sync --extra dev` (dev is an optional extra, not a group).

Addresses all 9 items in planning/market_data_summary.md's
"Recommended Implementation Order", including tests.

Co-authored-by: hengky888 <291320016+hengky888@users.noreply.github.com>
Implements the complete Market Data backend and all recommended hardening items.

Highlights:
- Added symbol normalization and simulation-symbol handling
- Added pricing availability validation (`ensure_priced`)
- Improved SSE tick delivery and per-connection direction tracking
- Added cache version locking for thread safety
- Added simulator fallback for invalid correlation matrices (`LinAlgError`)
- Added configurable `MASSIVE_POLL_INTERVAL`
- Added escalation after consecutive polling failures
- Expanded automated test coverage (127 tests)
- Updated backend README setup instructions

Validation:
- `uv sync --extra dev` ✓
- `uv run pytest -v` ✓ (127 tests passed)
- `uv run ruff check app/ tests/` ✓

This PR completes the Market Data backend implementation specified in the project plan and brings the backend to a validated, production-ready state.
Single implementation-ready design of record for the market data
subsystem, covering the unified data-source API, the GBM simulator, and
the Massive REST client, plus the shared price cache, SSE streaming, the
FastAPI wiring, and the watchlist/trade routes that consume them.

Written against the as-built code rather than as a forward-looking spec:
every code snippet is the shipped implementation, and the numeric
constants (seed prices, GBM parameters, correlations, simulated
universe) were diffed against source to confirm they match.

Documents the reasoning behind the non-obvious choices — why the SSE
stream emits unconditionally and computes direction per connection, why
ensure_priced exists alongside add_ticker, why the no-residue guarantee
is achieved by ordering rather than rollback, why the cache rounds at
the write boundary, and why there is no runtime failover from Massive to
the simulator.

The four split documents are superseded. market_data_design.md moves to
archive/MARKET_DATA_DESIGN_V2.md (renamed to avoid a case-collision with
the existing archive/MARKET_DATA_DESIGN.md on case-insensitive
filesystems), and the ten cross-references in the remaining companion
docs are repointed at the new sections.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MtZb6BTTzEFNEzR6kq1wJ4
@hengky888
hengky888 merged commit b45d882 into office-development Aug 12, 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.

2 participants