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

What’s implemented

FeatureStatus
Market channel subscribe (book / price / trade)Implemented
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> --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:

  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.