Skip to content

Market data feed

WebSocket protocol used by the Nexwest market ticker, including allMids, l2Book, snapshots, deltas, and reconnect rules.

Updated Nov 9, 2026Builders2 min read
On this page

The market data feed is a WebSocket stream of mid prices and order book updates. The docs home ticker uses the same protocol, so you can point it at testnet or your own relay without changing the UI.

Connect

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

Public market data requires no authentication. Send a subscription message immediately after the socket opens.

Subscribe

code
{
  "method": "subscribe",
  "subscription": { "type": "allMids" }
}

The subscription acknowledgement contains the current snapshot. Subsequent messages are deltas. Apply a delta only after the snapshot for that channel.

Message shapes

All mids

code
{
  "channel": "allMids",
  "data": {
    "mids": {
      "BTC-PERP": "74363.0",
      "ETH-PERP": "2114.9",
      "SOL-PERP": "86.267"
    }
  }
}

L2 book

code
{
  "channel": "l2Book",
  "data": {
    "coin": "BTC-PERP",
    "time": 1794207236139,
    "levels": [
      [{ "px": "74355.0", "sz": "13.2549", "n": 45 }],
      [{ "px": "74356.0", "sz": "0.1088", "n": 3 }]
    ]
  }
}

The first array is bids, the second is asks. Levels may also be sent as [price, size, orderCount] tuples. The docs ticker accepts both forms.

Snapshot and deltas

MessageMeaning
isSnapshot: trueReplace local state for the channel
No flagApply the update to the existing snapshot
Empty levelsThe side is empty; do not reuse the previous side

Do not apply deltas before a snapshot

After a reconnect, discard local book state and wait for a new snapshot. Applying a stale delta to a fresh snapshot is the most common source of incorrect books.

Reconnect

Use exponential backoff and resubscribe to every channel:

  1. Reconnect after 1s, 2s, 4s, capped at 30s.
  2. Resubscribe to allMids and each l2Book.
  3. Wait for snapshots before rendering.
  4. If the gap was longer than 30 seconds, reconcile orders and positions with a REST call.

The docs ticker

The ticker on the home page supports three modes:

ModeSourceHow to enable
customYour Nexwest feedSet NEXT_PUBLIC_MARKET_WS_URL
hyperliquidPublic demo feedDefault when no URL is set
simulatedLocal random walkAutomatic fallback after connection failure

Set the environment variable at build time:

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

The ticker connects directly from the browser. Cloudflare serves the static site; no Worker sits in the market-data path. If you need to normalize multiple venues or hide an upstream credential, add a Worker + Durable Object relay later and point the ticker at its URL.

Was this page helpful?