Skip to content

feat(ws): add subscribe_market_events for ordered multi-type market stream#20

Open
iamdoron wants to merge 1 commit intoPolymarket:mainfrom
iamdoron:main
Open

feat(ws): add subscribe_market_events for ordered multi-type market stream#20
iamdoron wants to merge 1 commit intoPolymarket:mainfrom
iamdoron:main

Conversation

@iamdoron
Copy link
Copy Markdown

@iamdoron iamdoron commented Apr 28, 2026

Summary

Adds Client::subscribe_market_events / unsubscribe_market_events, exposing every WsMessage for the subscribed assets (except custom-features events: BestBidAsk, NewMarket, MarketResolved) as a single stream.

Motivation

Needed this to build a local orderbook. You can combine subscribe_orderbook (for the Book snapshot) with subscribe_prices (for PriceChange deltas), but merging them doesn't preserve the original websocket ordering, which is required to correctly apply deltas to the snapshot. I might be possible to use timestamps but I think getting the entire stream is safer


Note

Low Risk
Low risk: additive client API that reuses existing market subscription plumbing, plus new tests; no protocol or auth logic changes.

Overview
Adds Client::subscribe_market_events to return a single ordered stream of raw WsMessage market events for subscribed assets (instead of filtering to one event type), plus unsubscribe_market_events as the corresponding unsubscribe entrypoint.

Extends WebSocket integration tests to assert the new stream receives multiple event variants (Book, PriceChange, TickSizeChange, LastTradePrice), preserves on-wire ordering (snapshot then deltas), and continues to filter out messages for non-subscribed assets.

Reviewed by Cursor Bugbot for commit dd4db58. Bugbot is set up for automated code reviews on this repo. Configure here.

These methods allow subscribing to and unsubscribing from all market
events for specified assets as a single ordered stream. Includes tests
to verify event ordering and filtering by asset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant