Synpath
Overview

WebSocket Overview

Synpath WebSocket API

Two things stream in Synpath, and they are documented side by side here:

KindWhere it connectsWhat it carriesAuth
SDK streamsThe venue's own WebSocket, from your processBooks, quotes, trades, market status; your orders, fills, positions, balancesThe venue's credentials, where the venue requires them
Engine eventsws://127.0.0.1:8000/trading/ws/events, your self-hosted server (synpath serve)Everything the execution engine journals, replayable from a sequence numberAccess 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 marked resynced, 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_required on the connected event: 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.

EventMeaning
BookEventA snapshot or a delta of one side of a market's book
QuoteEventThe venue's top of book and statistics
TradeEventA public print, in the YES price
MarketStatusEventA market opened, paused, closed, resolved
OrderEvent, FillEvent, PositionEvent, BalanceEventYour account, as the REST objects
VenueEventSomething venue-specific with no unified shape
StreamStatusEventThe 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.

REST API reference covers the same objects at rest.