Overview
WebSocket Overview
Synpath WebSocket API
Two things stream in Synpath, and they are documented side by side here:
| Kind | Where it connects | What it carries | Auth |
|---|---|---|---|
| SDK streams | The venue's own WebSocket, from your process | Books, quotes, trades, market status; your orders, fills, positions, balances | The venue's credentials, where the venue requires them |
| Engine events | ws://127.0.0.1:8000/trading/ws/events, your self-hosted server (synpath serve) | Everything the execution engine journals, replayable from a sequence number | Access token |
One shape on every venue
A stream is an async iterator of events. You say what to watch with watch_* calls that take Synpath market ids, then read events off the stream; every venue emits the same event types with the same fields.
import asyncio
from synpath import PolymarketMarketStream, BookEvent, StreamStatusEvent
async def main():
async with PolymarketMarketStream() as stream:
await stream.watch_order_book(["polymarket:2252244"])
async for event in stream:
if isinstance(event, BookEvent):
print(event.side, event.best_bid, event.best_ask)
elif isinstance(event, StreamStatusEvent):
print(event.state, event.detail)
asyncio.run(main())Each venue has one stream class for public data and one for the account. Every stream answers has["watch_order_book"] and the other watch_* keys with True, False or "partial", so a capability a venue lacks is known before subscribing.
What the streams promise
- Subscriptions survive reconnects. What you asked for is re-sent after every reconnect, with jittered backoff between attempts.
- Gaps are detected and repaired. A missed message is reported as a
gap; a book is re-snapshotted and markedresynced, and is marked not ready in between. - Private channels ask for reconciliation. No venue replays orders or fills you missed. A reconnect with private subscriptions sets
reconcile_requiredon theconnectedevent: read REST before trusting the stream again. - One bad message does not end the stream. It becomes a
StreamStatusEvent(state="error")and the connection stays up. - Dead connections are noticed, even after the machine sleeps.
Events
All events carry venue and received_at (local ms). Prices and sizes are decimals.
| Event | Meaning |
|---|---|
BookEvent | A snapshot or a delta of one side of a market's book |
QuoteEvent | The venue's top of book and statistics |
TradeEvent | A public print, in the YES price |
MarketStatusEvent | A market opened, paused, closed, resolved |
OrderEvent, FillEvent, PositionEvent, BalanceEvent | Your account, as the REST objects |
VenueEvent | Something venue-specific with no unified shape |
StreamStatusEvent | The stream itself: connected, disconnected, subscribed, gap, resynced, error, failed |
failed is final: the venue refused the stream in a way retrying cannot fix. Iteration ends after it.Authentication
Which streams need credentials, and how the engine socket takes a key
Order book
The first subscription most readers want
REST API reference covers the same objects at rest.

