Skip to main content
A single WebSocket connection streams trades, transfers, candles, tokens, wallet balances, positions, holders, native prices, trending boards and the discovery board to you as they change.

Connect

Browsers cannot set the Authorization header on a WebSocket. A browser instead passes metastreams.v1 and a session token as subprotocols, and the server selects metastreams.v1. An API key is not accepted in the subprotocol list.
Browser
Each session token has its own 20 connections, 20 subscriptions and 2,000 addresses, counted separately from its key. All the session tokens of one key share a limit of 10,000 open connections.

Routes

A connection can use one of two routes. Frames, limits and billing are the same on both. The direct route connects to the server with no proxy between. The connect request costs no credit, and one token opens connections, within the key’s connection limit, until it expires. Browsers and session tokens use the proxied route only.
When the connect request returns 404 NOT_FOUND, no direct URL is available; use the proxied route. When it or the direct handshake fails for another reason, the proxied route is a safe fallback. A 401, 402, 403 or 429 is returned on both routes, so do not retry it on the other one. Neither route is faster from every location. Measure both from where your client runs. The Rust SDK takes the direct route by default and falls back to the proxied route on its own.

Channels

  • ? marks an optional key, so {} matches every trade, transfer, candle or token, and … means the channel takes more keys. Each channel page lists all of them.
  • spot.trades, spot.transfers, spot.candles and spot.tokens share one filter language, described in Filtering streams.
  • spot.tokens also sends an exit frame when a token stops matching. spot.tokens, spot.candles and spot.positions accept throttleMs alongside filters, up to 60,000. Each channel page gives its default. spot.candles also accepts metric, denomination and closedOnly.
  • No REST endpoint returns transfers. Every other data object has the same shape as the matching REST response, with two exceptions. A streamed candle also includes its chain, token, pool and timeframe. A streamed holder has no rank. A streamed position is priced the same way as GET /v1/positions.

Frames

Client messages

Server messages

  • Use subscriptionId to route updates and to unsubscribe. The subscribe ack returns it, and every update includes it.
  • The ack for a subscription always arrives before its first update, and the ack for an unsubscribe arrives after that subscription’s last update.

Frame timing

Add timing=true to the handshake URL, such as wss://api.metastreams.dev/v1/stream?timing=true, to measure delivery latency. Every update frame on that connection then includes a timing object beside data. Other frames never include it, and it costs no credit.
sentAt minus receivedAt is the server’s processing time, plus any delay that throttleMs or closedOnly adds. Compare sentAt with the time your client reads the frame to measure the network leg. The two clocks are not synchronized, so treat a small negative difference as zero. The parameter works on both routes.

Initial snapshot

A stream only sends changes that happen after you subscribe. spot.trending and spot.discovery are the exceptions: their first updates contain the full board. To build a complete view on any other channel:
  1. Subscribe and buffer the updates.
  2. Read the snapshot from the REST endpoint, with the parameters that match the stream: hideLowLiquidity=false on GET /v1/positions, because the stream includes low-liquidity positions, and the subscription’s period, lifetime by default, on GET /v1/holders, with a limit of up to 150.
  3. Apply the buffered updates, and then each new update, on top of the snapshot.
Repeat all three steps after every reconnect. Use the key and rule below to merge each object type.
A subscription survives a server-side interruption, but missed updates are not replayed and no frame marks the gap. If you need every row, also re-read the snapshot on a schedule.

Errors

When a frame is rejected, the server returns an error frame with a REST error code, and the connection stays open. A rejected frame’s error has no subscriptionId. An error frame with a subscriptionId ends that subscription and frees its slot and addresses. No public channel sends one, but a client can handle it: drop the subscription’s state, and subscribe again only when the code is INTERNAL_ERROR or SERVICE_UNAVAILABLE. The error includes the id of the frame that caused it. It has no id when that frame is not JSON, has no string id, or is an unsubscribe.

Heartbeat

Send {"action": "ping"} about every 30 seconds. Reconnect when no pong has arrived for 45 seconds. The examples below check this at each ping. The server never closes an idle connection and sends no pings of its own.

Close codes

Subscriptions do not survive a reconnect. Send your subscribe frames again, then fill the gap with a fresh snapshot.

Reconnection

The examples below resubscribe after every close. They reconnect immediately after 1001, back off after any other close, and stop on 401, 402, 403, 1008, 4402 or 4403. They connect with an API key. A browser client with a session token requests a new token from its backend and reconnects after a 1008 close with the reason token expired.