Stream API
Polymarket exposes WebSocket channels under the CLOB subscription service. This
page covers the public market endpoint:
wss://ws-subscriptions-clob.polymarket.com/ws/market.
- Market channel — public, no auth. Streams order book updates, price changes, and trade events.
- User channel — authenticated. Streams personal order events.
Polygolem implements the market channel through the public pkg/stream
MarketClient, backed internally by internal/stream. The client handles
connection lifecycle, automatic reconnection with backoff, message
normalization, and dedup of duplicate events that the upstream sometimes
delivers across reconnects.
import sdkstream "github.com/TrebuchetDynamics/polygolem/pkg/stream"
client := sdkstream.NewMarketClient(sdkstream.DefaultConfig(""))client.OnPriceChange = func(msg sdkstream.PriceChangeMessage) { _ = msg.PriceChanges}_ = client.Connect(ctx)_ = client.SubscribeAssets(ctx, []string{"7132104567..."})What’s implemented
| Feature | Status |
|---|---|
| Market channel subscribe (book / price / trade) | Implemented |
| Automatic reconnect with backoff | Implemented |
| Message dedup across reconnects | Implemented |
| User channel (authenticated) | Not implemented |
CLI surface
WebSocket subscriptions are surfaced through polygolem stream market.
The CLI emits one JSON object per message on stdout, suitable for piping into
jq or a downstream consumer.
polygolem stream market --asset-ids <token-id-1>,<token-id-2> --max-messages 10--max-messages 0 streams until the process is interrupted. --url can point
to a local WebSocket test server.
Reconnect semantics
When the upstream connection drops, the client:
- Closes any open goroutines tied to the old connection.
- Waits an exponentially increasing backoff (capped, with jitter).
- Re-establishes and re-subscribes to the same set of channels.
- Suppresses duplicate events for a short replay window using a content-hash set, so consumers don’t see the same trade twice.
Related
- Orderbook Data — REST equivalents for one-shot reads
docs/ARCHITECTURE.md—pkg/streampackage boundary- Polymarket API Overview — every API in one place