Skip to content

WebSocket

Connect, subscribe, handle snapshots and deltas, keep the connection alive, and post signed actions over the socket.

Updated Nov 4, 2026Builders2 min read
On this page

The WebSocket API streams market data and account updates. Public subscriptions require no authentication. User subscriptions require an account address; posted actions require a signature.

Connect

code
wss://api.nexwest.app/ws

The server sends a JSON message per frame. There is no binary protocol and no multiplexed stream ID; the subscription type identifies the feed.

Subscribe

code
{
  "method": "subscribe",
  "subscription": { "type": "l2Book", "coin": "BTC-PERP" }
}

The first message after a subscription is a snapshot tagged with isSnapshot: true. Subsequent messages are deltas. If you reconnect, discard local state and wait for a new snapshot.

Subscription types

TypeRequired fieldsData
allMids—Mid prices for all markets
l2BookcoinBook snapshot and deltas
bbocoinBest bid/offer
tradescoinPublic trades
candlecoin, intervalOHLCV updates
clearinghouseStateuserMargin and positions
openOrdersuserResting orders
userFillsuserFills for the account
userEventsuserFunding, liquidations, transfers
activeAssetCtxcoinFunding, open interest, mark price
notificationuserAccount notifications

Snapshot then delta

Never apply a delta before the snapshot. If a message is missed or the connection drops, resubscribe and replace local state with the new snapshot.

Book example

code
{
  "channel": "l2Book",
  "data": {
    "coin": "BTC-PERP",
    "time": 1762732800123,
    "levels": [
      [["104279.5", "0.842", 4]],
      [["104281.0", "0.514", 3]]
    ]
  }
}

Use nSigFigs and mantissa in the subscription to control aggregation.

Post requests

Signed actions can be posted over the socket to save a round trip:

code
{
  "method": "post",
  "request": {
    "action": { "type": "cancel", "cancels": [{ "asset": 0, "oid": 91490942 }] },
    "nonce": 1762732800123,
    "signature": { "r": "0x...", "s": "0x...", "v": 27 }
  }
}

The response is correlated by id if you provide one.

Heartbeats

Send a ping every 30 seconds:

code
{ "method": "ping" }

The server responds with { "method": "pong" }. If no pong is received within 10 seconds, reconnect. The server closes idle connections after 60 seconds.

Reconnect strategy

  1. Reconnect with exponential backoff (1s, 2s, 4s, capped at 30s).
  2. Resubscribe to every channel.
  3. Wait for snapshots before applying deltas.
  4. Reconcile open orders and positions with a REST call if the gap was longer than 30 seconds.

Rate limits

WebSocket messages are limited to 30 per second per connection. Subscription count is limited to 200 per connection. See rate limits.

Was this page helpful?