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
wss://api.nexwest.app/wsPublic market data requires no authentication. Send a subscription message immediately after the socket opens.
Subscribe
{
"method": "subscribe",
"subscription": { "type": "allMids" }
}{
"method": "subscribe",
"subscription": { "type": "l2Book", "coin": "BTC-PERP" }
}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
{
"channel": "allMids",
"data": {
"mids": {
"BTC-PERP": "74363.0",
"ETH-PERP": "2114.9",
"SOL-PERP": "86.267"
}
}
}L2 book
{
"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
| Message | Meaning |
|---|---|
isSnapshot: true | Replace local state for the channel |
| No flag | Apply the update to the existing snapshot |
| Empty levels | The 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:
- Reconnect after 1s, 2s, 4s, capped at 30s.
- Resubscribe to
allMidsand eachl2Book. - Wait for snapshots before rendering.
- 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:
| Mode | Source | How to enable |
|---|---|---|
custom | Your Nexwest feed | Set NEXT_PUBLIC_MARKET_WS_URL |
hyperliquid | Public demo feed | Default when no URL is set |
simulated | Local random walk | Automatic fallback after connection failure |
Set the environment variable at build time:
NEXT_PUBLIC_MARKET_WS_URL=wss://api.nexwest.app/wsThe 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.