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 PolymarketMarketDataStream, BookEvent, StreamStatusEvent

async def main():
    async with PolymarketMarketDataStream() as stream:
        async with stream.events() as reader:
            await stream.watch_order_book(["polymarket:2252244"])
            async for event in reader:
                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 supported venue has a market-data stream and, where implemented, an account-data stream. 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. When the venue provides enough information to detect a missed message, it 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. When an account channel cannot replay missed updates, a reconnect 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.