Skip to content

OKX: Duplicate WebSocket subscriptions for the same channel when a pair is enabled across multiple asset types (e.g., spot and margin) #2136

@shazbert

Description

@shazbert

When a trading pair is enabled for multiple asset types that share the same instrument ID on OKX (e.g., the same pair in both spot and margin trading), the WebSocket subscription logic generates identical subscription requests for channels like tickers and orderbooks.

Previously, with a single WebSocket connection, resubscribing to an already-active channel was harmless and did not cause errors.

However, when scaling to multiple WebSocket connections (e.g., due to rate limits or multi-connection support), these duplicate identical subscriptions are sent across different connections. This leads to:

  • Unnecessary resource consumption (multiple connections receiving the same data stream).
  • Potential checksum validation failures for orderbook channels, as the client may receive mismatched or conflicting updates from duplicated feeds.

To resolve this, subscriptions should be deduplicated at the exchange level before allocation/distribution across connections, ensuring each unique channel is subscribed to only once regardless of asset type overlap.

See: #2109 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions