Allow order book subscriptions to share a websocket connection#25
Allow order book subscriptions to share a websocket connection#25Da-Teach wants to merge 1 commit into
Conversation
|
Hi, the current situation is nog ideal, but setting AllowTopicsOnTheSameConnection to true will break the logic. See https://docs.whitebit.com/websocket/market-streams/overview#managing-subscriptions. To fix this there would need to be some kind of logic which keeps track what symbols are currently subscribed to a topic so a new subscribe/unsubscribe can send that full list again. |
WhiteBitSocketClientV4Api set AllowTopicsOnTheSameConnection = false, forcing every order book subscription (all share Topic "OrderBook") onto its own websocket. For a large universe that sprawls to ~one socket per symbol and exhausts WhiteBit's per-IP connection allowance, leaving books empty. Separate per-symbol depth_subscribe calls sent with multiple_subscriptions = true (which this client always does) coexist on a connection rather than replacing each other — verified against the live API: 200 markets streaming on one socket, and per-market depth_unsubscribe. Setting the flag true lets SocketSubscriptionsCombineTarget pool them. WhiteBit rate-limits depth_subscribe to ~200 requests per connection per burst, so the default combine target is set to 150 to stay safely under that when a reconnect re-subscribes a connection's whole set in one burst.
890a7f8 to
913445f
Compare
|
Thanks for taking a look! I went and tested this against the live API, and I don't think the override you're describing happens for the subscriptions this client makes — but I'd genuinely like your read on whether I'm missing a case. The key detail is the 4th parameter of Verified directly against
So the per-symbol One real constraint I did hit: WhiteBit rate-limits I've updated this PR accordingly: the flag flip, the 150 default, and a comment documenting the above. Does that line up with your understanding, or is there a scenario where the override still kicks in that I haven't tested? |
Problem
WhiteBitSocketClientV4ApisetsAllowTopicsOnTheSameConnection = false. Every order book subscription uses the same topic ("OrderBook"), so CryptoExchange.Net's connection-reuse rule(AllowTopicsOnTheSameConnection || !connection.Topics.Contains(topic))excludes any connection that already holds a book subscription. As a resultSocketSubscriptionsCombineTargetis effectively ignored for order books and the client opens one websocket per symbol.Subscribing a large universe (hundreds of pairs) then sprawls to ~one connection per symbol, which exhausts the venue's per-IP connection limit — some subscriptions then silently never receive data.
Fix
Set
AllowTopicsOnTheSameConnection = true. WhiteBit supports multiple subscriptions per connection (depth_subscribeis sent withmultiple_subscriptions = true), so order book subscriptions can safely share a connection.Verification
Subscribing 785 spot symbols (combine target 500, depth 20) drops from 777 sockets to ~40 once enabled, with no loss of data.