Skip to main content
Every pair of a subscription (one chain and one event kind) has its own cursor. Store the newest cursor of each pair. When you reconnect, send them back as since and the server replays the matching trades you missed, then continues live.

Cursor format

  • The number before -0 is the block number.
  • The index after : is the trade’s position in that block’s list of swaps. That list also contains swaps that aren’t trades, so indexes can skip numbers.
  • cursor checkpoints carry entry cursors, and so does subscribed for a pair that starts live. For a pair you resume, subscribed echoes the cursor you sent, which can be an item cursor. Events carry item cursors.
  • Cursors are ordered: by block, then by index. An entry cursor sorts after every item cursor of the same block.
Treat cursors as opaque strings that you store and send back. Don’t build them yourself. The same trade delivered as both swap and swap-enriched has the same cursor value under two different pairs, for example swap|evm:1 and swap-enriched|evm:1. Store cursors per pair, not per trade.

Where cursors come from

Keep the newest cursor of each pair from any of these messages: Within a pair, messages arrive in order, so the last cursor you received is the newest.

Checkpoints

Every 30 seconds, each live pair whose chain has moved on since its last cursor gets a checkpoint:
A checkpoint means every block up to and including that one has been processed for your subscription, even if nothing matched your filter. It lets a sparse filter, one that matches only a few trades an hour, resume after a quiet period without falling behind the stream’s history. Sampled subscriptions don’t get checkpoints.

Resuming with since

Subscribe again with the same params and add since. You can use a new id or the same one on a new connection.
since is a cursor string:
Sending a string when the subscription has several pairs fails with INVALID_PARAMETERS, message This subscription has several pairs, since must map each pair to its cursor, and details.pairs listing the pair names.
What happens next:
  1. The server sends subscribed. For resumed pairs, the cursor echoes the one you sent.
  2. It replays every trade after your cursor that matches the filter. With an item cursor, that starts with the rest of the same block; with an entry cursor, with the next block. Gaps in that range are replayed too.
  3. It hands over to live delivery, with no duplicates and no reordering.
Always resume from a cursor the server gave you. A cursor ahead of the stream skips everything up to it.

RESUME_EXPIRED

The stream keeps a limited history per chain: about 10 minutes today. Don’t design for more. The history is kept as a number of blocks, so the exact time varies by chain. If any since cursor is older than that, the whole subscription is refused, including pairs whose cursors were still valid:
  • retainedFrom is a block number as a string: the oldest block the stream still holds for that chain.
  • With several pairs, details.pairs lists only the expired pairs.
To recover:
  1. Subscribe again without the expired pairs in since (or without since at all). Those pairs start live.
  2. If you need the trades you missed, fetch them from GET /trades for the tokens or pools you follow.

Gaps

Blocks are released to the stream strictly in order. If a block’s trades are stuck for more than about 15 seconds, the stream skips ahead and records a gap:
  • fromBlock to toBlock is an inclusive block range. Trades in those blocks are not streamed, now or later.
  • Every subscriber of that chain gets the gap, whatever its filter, including sampled subscriptions. A gap doesn’t mean that a trade matching your filter was lost, only that one might have been.
  • pair follows the same rule as for events: present only with several pairs.
  • The gap message has no cursor. If you resume from a cursor older than the gap, the gap is sent again during replay.
If you need complete data, backfill the range from REST. GET /trades takes a token or pool address and a time window in milliseconds (from, to), not block numbers. Use the timestamp of the last event before the gap and of the first event after it as the window. A token query only covers the token’s top two pools, so backfill by pool address when you can.

Restarts and disconnects

When a server restarts, it sends every client:
then closes the connection with code 1012 and reason Server restarting, reconnect and resume. Closes are spread over about 20 seconds so clients don’t all reconnect at once. Reconnect to the same URL; any server instance can resume your cursors. Subscriptions don’t survive a disconnect. On every new connection, subscribe again with since. The same applies to the other closes listed in Limits and subscription cost, such as 4008 for a client that reads too slowly and 1006 for a missed heartbeat.

Reconnect recipe

This client keeps one cursor per pair, resumes after any disconnect with exponential backoff, and drops expired pairs on RESUME_EXPIRED. Persist cursors (to a file or database) if you want to resume after your process restarts too.
If you change params between connections, only send since for pairs that still exist. A pair you add starts live, and a pair you send that the new params don’t produce fails with Unknown pairs in since.