feat(ws): add subscribe_market_events for ordered multi-type market stream#20
Open
iamdoron wants to merge 1 commit intoPolymarket:mainfrom
Open
feat(ws): add subscribe_market_events for ordered multi-type market stream#20iamdoron wants to merge 1 commit intoPolymarket:mainfrom
iamdoron wants to merge 1 commit intoPolymarket:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_eventsto return a single ordered stream of rawWsMessagemarket events for subscribed assets (instead of filtering to one event type), plusunsubscribe_market_eventsas 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.