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
wss://api.nexwest.app/wsThe server sends a JSON message per frame. There is no binary protocol and no multiplexed stream ID; the subscription type identifies the feed.
Subscribe
{
"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
| Type | Required fields | Data |
|---|---|---|
allMids | — | Mid prices for all markets |
l2Book | coin | Book snapshot and deltas |
bbo | coin | Best bid/offer |
trades | coin | Public trades |
candle | coin, interval | OHLCV updates |
clearinghouseState | user | Margin and positions |
openOrders | user | Resting orders |
userFills | user | Fills for the account |
userEvents | user | Funding, liquidations, transfers |
activeAssetCtx | coin | Funding, open interest, mark price |
notification | user | Account 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
{
"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:
{
"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:
{ "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
- Reconnect with exponential backoff (1s, 2s, 4s, capped at 30s).
- Resubscribe to every channel.
- Wait for snapshots before applying deltas.
- 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.