Skip to main content
Every non-sampled subscription has a position in its chain’s trade stream, called a cursor. If you store the latest cursor and send it back as since when you resubscribe, the server replays everything you missed and then continues live, with no duplicates and no holes.

Cursor format

Cursors are strings in one of two forms:
  • <block> is the block number. Each block is one entry in the stream.
  • <index> is the item’s position in that block’s list of swaps. That list includes swaps your subscription doesn’t receive, so indices on your events can skip numbers.
  • A stream with no entries yet reports 0-0.
Treat cursors as opaque strings: store them and send them back unchanged. They are ordered, though: first by block, then by index, and a whole-block cursor N-0 comes after every item cursor N-0:i of the same block. The server sends cursors for a subscription in increasing order, so the most recent one you received is always the latest. Cursors are per chain. A cursor from one chain is meaningless on another.

Resuming with since

Pass the cursor as since in a subscribe message, with the same channel and params as before:
  • With an item cursor (N-0:i), replay continues inside block N after item i.
  • With a whole-block cursor (N-0), replay starts at the block after N.
  • Replayed events come after subscribed, in order. New trades that arrive during the replay are held back and sent after it, so live events never overtake replayed ones and nothing is sent twice.
  • Without since, a subscription starts live from the current position. Nothing is backfilled.

since as a map

Each subscription on /v1/ws reads exactly one stream, identified by a pair <channel>|<chain>, for example fast-trade|evm:8453. Instead of a plain cursor you can send a map with that single pair:
Both forms are equivalent here. A map that names any other pair is rejected:
A since value that is not a valid cursor or map fails envelope validation, and that error has no id. See error.

Sampled subscriptions can’t resume

Subscriptions with maxUpdatesPerMinute drop trades on purpose, so they have no cursors and reject since. See Sampling.

Checkpoints

About every 30 seconds, the server sends a cursor message to each live, non-sampled subscription whose position has moved:
It means every block up to and including 38123610 has been processed for this subscription, even if none of its trades matched. Quiet subscriptions get checkpoints too. A token that trades once an hour still has a recent cursor, so you can resume it after a disconnect. What to store: for each subscription, keep the most recent cursor from any of these messages:
  • subscribed.cursor
  • event.cursor
  • cursor.cursor
Send it as since when you resubscribe.

History retention

The stream keeps about 10 minutes of blocks per chain. This is a current default and may change. The window is converted to a number of blocks using the chain’s average block time, so it covers more blocks on fast chains. If your cursor is older than the retained history, the subscription is not created:
details.retainedFrom is the oldest block still retained, as a string. To recover:
  1. Subscribe again without since. The subscription starts live.
  2. Backfill the time you missed from REST:
The REST endpoints filter by time (from and to in Unix milliseconds), not by block. Use the date of the last event you processed as from.

Gaps

Blocks are released in order. If a block is missing upstream for about 15 seconds, the stream skips past it and tells every subscriber:
  • fromBlock and toBlock are inclusive. Trades in those blocks were not, and will not be, sent on this stream, including on replay.
  • The subscription’s position moves past the gap, and delivery continues normally.
  • Sampled subscriptions get gap messages too.
If you need complete data, backfill the range from GET /trades. Use the date of the last event before the gap and the first event after it as the from and to window, then keep only trades whose blockNumber is between fromBlock and toBlock.

Reconnect loop

A robust client:
  1. Keeps the channel, params and latest cursor of every subscription.
  2. On every new connection, after welcome, resubscribes with since set to the stored cursor.
  3. Reconnects with exponential backoff and jitter after any close.
  4. Paces its subscribe messages, because the message limit of 20 per second also applies to resubscribes.
  5. Handles RESUME_EXPIRED by dropping the cursor, resubscribing live and backfilling from REST.
If you resubscribe within about 10 minutes, the replay fills the whole disconnect window. You only need REST backfill for gap messages and RESUME_EXPIRED, and to reload recent candles for ohlcv, which does not resend trades already counted into its live candle.