Skip to main content
The ChainQuery WebSocket API pushes trades to you as they are indexed, so you don’t have to poll the REST API. One connection can carry many subscriptions across four channels.

Endpoint

  • No authentication is needed. Open the socket and start subscribing.
  • All frames are JSON text, in both directions. A binary frame or invalid JSON gets a BAD_REQUEST error, and the connection stays open.
The Pulse stream (/v1/ws/pulse) and the multi-events stream (/streams/v1/ws) are separate endpoints with their own protocols. This section covers /v1/ws only.

The welcome message

The server sends a welcome message as soon as the connection opens:

Channels

Every channel is fed by the same ordered stream of trades for one chain. Each event is produced by one trade. The channels differ in how a trade is selected and what is sent for it. Only swaps classified as trades are streamed. Liquidity adds and removals, MEV swaps and other non-trade swaps are left out.

WebSocket or REST?

  • Use REST for anything historical or one-off: token and market snapshots, candle history, past trades. See the REST API overview.
  • Use WebSocket to keep that data up to date afterwards. A common pattern is to load history from REST, then subscribe and apply live events on top. For example, load candles from GET /token/ohlcv, then follow the ohlcv channel.
  • The WebSocket API keeps only about 10 minutes of history for resuming (see Cursors and resuming). It does not replace the REST history endpoints.

Chain identifiers

On the WebSocket API, chain must be a string in the form evm:<chainId>, for example "evm:1" or "evm:8453". A bare number such as "8453" or 8453 is rejected:
This differs from REST, which also accepts a bare 1. Also, any well-formed evm:<n> passes validation. On fast-trade, token-details and market-details, a chain that ChainQuery does not index subscribes without error and then never sends events. ohlcv checks that the pool or token exists, so it fails the subscribe instead. See Chains and identifiers for the supported chains.
Addresses are case-insensitive and are lowercased by the server. All addresses in events are lowercase.

End-to-end example

This example subscribes to every trade of one token on Base and prints each one.
The conversation looks like this (-> is sent by you, <- by the server, event data shortened):
The id you choose is echoed on every message for that subscription, so you can route events when several subscriptions share one connection.

Heartbeats

Every heartbeatMs (30 s by default) the server sends a WebSocket protocol ping frame. If it did not receive a pong since the previous ping, it drops the connection without a close frame, and your client sees close code 1006.
  • Browsers, Node ws and Python websockets answer protocol pings automatically. You don’t need to do anything.
  • If you turned automatic pongs off in your client library, you must answer pings yourself.
  • The application-level {"op":"ping"} message is optional. It returns {"type":"pong"} and is useful for measuring round-trip time, but it does not count as a heartbeat answer. It also counts toward the message rate limit.

Reconnecting

Subscriptions belong to a connection. When the connection closes for any reason, all its subscriptions are removed, and you must subscribe again on the new connection. To continue without missing trades, store the latest cursor of each subscription and pass it as since when you resubscribe. See Cursors and resuming for the full reconnect loop.

Next steps

Message reference

Every client op and server message type, with fields.

Cursors and resuming

Resume after a disconnect without gaps or duplicates.

Limits and errors

Message limits, close codes and error codes.

fast-trade channel

Start with the simplest channel.