Skip to main content
Use WebSockets for subscription updates. Use HTTP POST /info for individual reads and POST /exchange for signed actions. WebSocket post requests are not supported.

Connection

Client messages are JSON text, up to 16 KiB. Methods: subscribe, unsubscribe, and ping. For example, connect from the command line:

Subscribe

Send a subscription message to choose a data feed. Put the fields listed in each channel’s Subscription Body inside subscription:
Subscriptions on /ws require no signature, and every update is delayed by 20 seconds. Use the account owner’s user address for user-scoped channels. The server confirms the subscription with subscriptionResponse. This acknowledgment contains the subscription, not the feed’s data:
The feed sends separate data messages. For example, an account with no funding history receives:
An acknowledgment does not mean that the initial data has arrived or that history is complete. The table below lists each feed’s initial data. isSnapshot marks an initial snapshot where supported; it does not imply that the snapshot contains all history.

Unsubscribe

To unsubscribe, send the same subscription with method: "unsubscribe". Its acknowledgment uses data.method: "unsubscribe". Subscription keys normalize user addresses to lowercase and coin to uppercase.

Channels and Initial Data

Heartbeat

Send a JSON ping every 30 seconds, even while receiving feed updates:
The server replies with:
After 60 seconds without client activity, a connection is eligible to close with code 1000 and reason Idle timeout. Incoming client messages and WebSocket control ping/pong frames reset this timer; outgoing server updates do not. Browser clients can use the JSON ping above. A pong confirms that the connection responds; it does not confirm that a feed is current or its history is complete. If a ping goes unanswered past your client’s response deadline, close the connection and reconnect. Clear heartbeat timers when closing or replacing a connection.

Limits

Each connection can hold 64 distinct subscriptions. Another one is refused with an error frame, Subscription limit reached (64 per connection), and the connection stays open. Repeating a held subscription is allowed, and unsubscribe frees a slot. Each connection can send 128 messages at once, refilled at 4 per second. Every message counts, including ping and invalid messages. A connection over this limit is closed with code 1008 and reason Rate limit exceeded, without an error frame. Reconnect with backoff and resubscribe.

Reconnecting

Connections may close without notice. There is no general message replay or WebSocket replay cursor. Reconnect, restore subscriptions, and recover missing data through the matching HTTP reads. Snapshots and accountUpdateIds provide only the feed-specific recovery described above. Reconnect with increasing retry delays and random variation. Restore subscriptions before fetching HTTP history, keep updates received during recovery, and merge overlapping records by their stable identities. Scope cached data and recovery work to the wallet and network. Recover missed fills with userFillsByTime, using aggregateByTime: false to match individual WebSocket fills. Identify external fills by tid and internal fills by (matchId, lowercase counterparty). Each HTTP response contains at most 2,000 fills from the most recent 10,000 fills. A full response may be incomplete; narrow the time range and deduplicate overlaps without skipping fills that share a timestamp. Recover order state with openOrders and historicalOrders. The initial orderUpdates snapshot is not full order history. A missing update does not mean an HTTP action failed; check its outcome and the endpoint’s retry rules before submitting again.

Economic history

User Fundings, User Non-Funding Ledger Updates, and User Borrow/Lend Interest use the same rows as their matching HTTP reads: userFundings, userNonFundingLedgerUpdates, and userBorrowLendInterest. The acknowledgment precedes a snapshot of the latest 100 matching rows, oldest first, including an empty snapshot. Live messages follow it and contain at most 100 new or changed rows. Merge the snapshot into cached history; an empty snapshot does not delete older rows. Update existing rows by id (ledger.id for funding and interest). Separate rows can share a hash, market, and timestamp. Withdrawals and outcome operations keep their IDs through lifecycle changes, even when their hash or time changes. Preserve terminal receipts when an older pending row arrives, including from an HTTP source that lags the socket. On reconnect, read each matching HTTP history category to recover gaps and changes to older rows. Querying only after the newest cached timestamp can miss changes to existing rows. For paginated reads, continue from the last row’s time and id using startTime and afterId; do not add one millisecond and skip other rows at that timestamp. Messages and snapshots can repeat.

Errors

Invalid JSON, unsupported methods, and invalid subscriptions return channel: "error", for example:
An error can arrive after a subscription acknowledgment if its initial read fails. Handle errors alongside feed data; receiving an acknowledgment alone is not a successful initial load.