polymarket-client SDK wraps all of these behind a single subscribe() call that returns an async stream — you iterate it with standard futures::StreamExt combinators and close it with a single method call when you are done.
Enable the websockets feature
WebSocket support is gated behind the websockets feature flag. Add it to your Cargo.toml:
secure feature bundle already includes websockets, so if you have features = ["secure"] you can skip this step.
Subscribe to the market channel
The market channel streams live order book events, price updates, and last-trade data for one or more outcome tokens. You callsubscribe() on PublicClient, passing a Vec of SubscriptionSpec values:
handle implements futures::Stream, so you can use .next(), .take(), .filter_map(), and the rest of the StreamExt API. Call handle.close() when you no longer need updates to cleanly shut down the underlying WebSocket connection.
Subscribe to the user channel
The user channel delivers real-time events scoped to your own wallet — order placements, fills, and cancellations. Because the server must verify your identity before opening this channel, you must callsubscribe() on a SecureClient rather than a PublicClient:
User subscriptions require a SecureClient. Calling subscribe with SubscriptionSpec::User on PublicClient will return an error at runtime.markets to filter events to those markets, or leave the Vec empty to receive events for all your open activity.
Subscription types reference
TheSubscriptionSpec enum covers every channel the Polymarket WebSocket server exposes:
You can combine multiple
SubscriptionSpec values in a single subscribe() call to multiplex several channels over one connection:
Closing the stream
Always callhandle.close() when you are finished consuming events. This sends a clean close frame to the server and releases the underlying TCP connection:
close() will eventually time out on the server side, but calling close() explicitly is faster and avoids leaving stale connections open on the Polymarket WebSocket server.
