Skip to content

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"
cfg := sdkstream.DefaultConfig("")
cfg.CustomFeatureEnabled = true
client := sdkstream.NewMarketClient(cfg)
client.OnPriceChange = func(msg sdkstream.PriceChangeMessage) {
_ = msg.PriceChanges
}
client.OnBestBidAsk = func(msg sdkstream.BestBidAskMessage) {
_ = msg.BestBid
}
_ = client.Connect(ctx)
_ = client.SubscribeAssets(ctx, []string{"7132104567..."})

What’s implemented

FeatureStatus
Market channel subscribe (book / price / trade)Implemented
Market channel custom features (best_bid_ask, new_market, market_resolved)Implemented with CustomFeatureEnabled
Tick-size change eventsImplemented
Automatic reconnect with backoffImplemented
Message dedup across reconnectsImplemented
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.

Terminal window
polygolem stream market --asset-ids <token-id-1>,<token-id-2> \
--custom-features --level 2 --max-messages 10

For bot-friendly snapshots with best bid, best ask, midpoint, last trade, and current book levels, use the normalized market-data command:

Terminal window
polygolem marketdata live --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. marketdata live enables custom features by default so top-of-book best_bid_ask events update the normalized snapshots.

Reconnect semantics

When the upstream connection drops, the client:

  1. Closes any open goroutines tied to the old connection.
  2. Waits an exponentially increasing backoff (capped, with jitter).
  3. Re-establishes and re-subscribes to the same set of channels.
  4. Suppresses duplicate events for a short replay window using a content-hash set, so consumers don’t see the same trade twice.