Skip to content

serve: library parity for data and buckets (into experimental branch) - #30

Merged
YukiC0804 merged 7 commits into
codex/order-lifecycle-storagefrom
sp/serve-parity
Oct 21, 2026
Merged

YukiC0804 merged 7 commits into
codex/order-lifecycle-storagefrom
sp/serve-parity

Conversation

@YukiC0804

Copy link
Copy Markdown
Collaborator

Targets codex/order-lifecycle-storage, not main. Part 1 of the terminal plan (terminal/specs/draft/ORDER_PLACEMENT_PLAN.md in prediction_market): all data and trading live in synpath serve; the terminal's web backend becomes a router with no venue connections or keys. No merge to main, no release.

Changes

  • Auth (S8): every market-data route and the new streams require the serve token. /, /health, /docs stay open.
  • Live streams (S4): WS /ws/market for books, trades and quotes on all 8 venues. One shared, reference-counted venue connection per market, shared with the engine's Feeds (screen and stops see the same book). Reconnect with ready:false then a fresh snapshot. Feeds.dispatch only hands the engine books for markets it watches.
  • Batch and search (S6): /markets?ids=, /books?ids= (≤100 ids, per-id errors), /search/markets, /search/events.
  • Hosted (S5): /matching/market, /matching/event, /matching/arbitrage, /history/order-book/at|range, /history/trades/range using serve's Synpath key; hosted errors mapped.
  • Buckets (S7): client-supplied ids, PATCH /trading/buckets/{id}, a merged bucket_book on /ws/market (library router.view/merge, flip handled), POST /trading/buckets/{id}/plan (library router.plan, nothing placed).
  • Member On/Off (B2): BucketMember.enabled; an Off member is not streamed, merged or routed (including orders on a bucket). Alembic revision 0003 adds bucket_members.enabled (default on), schema version 8; existing buckets load with every member On.
  • Tests: tests/serve_harness.py (in-process serve, mocked venues, SQLite and PostgreSQL) and serve tests for auth, streams, batch, hosted and buckets.

Verification (offline only, no venue calls)

  • SQLite: 2378 passed, 136 skipped (PostgreSQL cases).
  • PostgreSQL (SYNPATH_TEST_POSTGRES_DSN, throwaway postgres:16): 2511 passed, 3 skipped.

After merge

Bump synpath-sdk-revision in prediction_market to the merged commit (the terminal PR depends on this).

🤖 Generated with Claude Code

Yuki Chu and others added 2 commits October 15, 2026 16:24
…, hosted, bucket books)

synpath serve now carries every data feature the terminal needs, so the
terminal's web backend can be a router with no venue connections or keys.

- Auth: every market-data route and stream requires the serve token.
- /ws/market: live books, trades and quotes for all venues, one shared
  reference-counted venue connection per market, shared with the
  engine's feeds; reconnect with a fresh snapshot.
- Batch reads and search: /markets?ids=, /books?ids=, /search/markets,
  /search/events, with per-id errors.
- Hosted routes: /matching/market|event|arbitrage and /history/* through
  serve's Synpath key, with mapped errors.
- Buckets: client ids, PATCH, a merged bucket book on /ws/market built
  with router.view/merge, and POST /trading/buckets/{id}/plan.
- BucketMember.enabled: an Off member is not streamed, merged or routed.
  Alembic revision 0003 adds bucket_members.enabled (default on); schema 8.
- tests/serve_harness.py: in-process serve with mocked venues, SQLite and
  PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On CI's slower runners the bucket tests reached for the fake Polymarket
stream before the hub had opened it (KeyError: 'polymarket'). The
harness now waits for it, polling the dict directly so the helper also
works inside conditions that already run on the server's loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Smarkets sends up to nine fraction digits. The digit scan also picked up the
time zone's digits, and Python 3.10's fromisoformat takes only three or six
fraction digits, so every timestamp came back as None there. Take the
leading digits only and pad them to six.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps #30's venue_streams / market_stream / MarketStreams structure and fits
main into it:

- venue_streams accepts a MarketDataKey (Opinion, predict.fun, SX Bet) and
  builds the market stream alone from it, with a keyed catalog where no
  adapter supplies one; market_stream and default_streams(market_data) go
  through it.
- Betfair and Smarkets market streams (Smarkets without credentials).
- SX Bet's account stream only with an account address, warning otherwise.
- serve always loads market_data, passes it to default_streams and to the
  /ws/market factory, and gives the read app's default VenueRegistry its
  dotenv keys; #30's auth dependency, hosted routes and buckets stay.
- The dotenv read-app test sends serve's access token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
YukiC0804 pushed a commit that referenced this pull request Oct 21, 2026
Merges cleanly. Main's trading changes (SX Bet's key-only trading, Betfair
and Smarkets instruments, init/doctor) build no OrderRequest, Order or Fill
and bring back no reduce_only or fair values, so nothing needed porting to
outcome + action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
YukiC0804 and others added 2 commits October 21, 2026 12:49
smarkets: parse nanosecond timestamps on Python 3.10
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YukiC0804
YukiC0804 merged commit 7d5c593 into codex/order-lifecycle-storage Oct 21, 2026
5 checks 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