Skip to main content
The V3 perps WebSocket is a separate stream for perps market data. The SDK client handles authentication, waits for control-message acknowledgements, preserves unknown additive messages, reconnects, and resubscribes to the channels you accepted.

Channels

Use the SDK channel helpers to avoid formatting mistakes.

Connect and subscribe

The initial connection returns a hello message with the server’s channel limit and currently active channels. subscribe() returns only after the server responds.

Partial acceptance

A subscription acknowledgement can accept some channels and reject others. Always inspect both lists:
  • channels contains the accepted channels that the SDK will restore after reconnect
  • rejected contains { channel, reason } entries
  • active_subscriptions is the resulting server-side count
Do not treat a resolved subscribe call as proof that every requested channel was accepted.

Book events replace state

Every received perps_book event is a complete replacement snapshot. Replace the prior bids and asks; do not merge it as a delta. A successful subscription acknowledgement confirms that the channel is active; it does not mean a book snapshot has already arrived. The managed cache returns no book until the first perps_book event. If startup requires state within a fixed readiness deadline, read the V3 perps orderbook and replace it with subsequent WebSocket snapshots. The managed clients retain the latest complete book:
Perps prices and quantities are decimal strings. Preserve them as exact values for trading, accounting, and comparisons.

Reconnect and gaps

Automatic reconnect is enabled by default. After reconnect, the SDK resubscribes only the previously accepted channels and emits an explicit reconnect notice. The perps WebSocket does not replay messages missed while disconnected. Every reconnect notice sets gap_possible to true. Recover state as follows:
  • ticker, BBO, statistics, and book consumers can wait for a fresh event or refetch the matching REST endpoint
  • book consumers should discard the old book and wait for a new complete snapshot
  • trades and klines consumers should use the V3 REST routes to fill the time interval if continuity matters
See Perps market data for REST endpoints.

Backpressure and lag

Two different warnings can occur:

Terminal closes

Authentication close code 4401 and connection-cap close code 4429 are terminal. The SDK does not loop forever on credentials or account limits that require user action. Correct the API key or close another connection before starting a new client.

Unknown messages

Additive protocol messages remain observable:
  • TypeScript: message.type === 'unknown'
  • Python: PerpsUnknownMessage
  • Rust: PerpsMessage::Unknown
Upgrade the SDK when you see one. Avoid logging credentials or an unbounded raw payload.

Unsubscribe and close

For channel payloads and instrument identifiers, see Perps WebSocket channels.