since and the server replays the matching trades you missed, then continues live.
Cursor format
- The number before
-0is 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. cursorcheckpoints carry entry cursors, and so doessubscribedfor a pair that starts live. For a pair you resume,subscribedechoes 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.
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: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.
- One pair
- Several pairs
since is a cursor string:INVALID_PARAMETERS, message This subscription has several pairs, since must map each pair to its cursor, and details.pairs listing the pair names.- The server sends
subscribed. For resumed pairs, the cursor echoes the one you sent. - 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.
- It hands over to live delivery, with no duplicates and no reordering.
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:
retainedFromis a block number as a string: the oldest block the stream still holds for that chain.- With several pairs,
details.pairslists only the expired pairs.
- Subscribe again without the expired pairs in
since(or withoutsinceat all). Those pairs start live. - If you need the trades you missed, fetch them from
GET /tradesfor 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:fromBlocktotoBlockis 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.
pairfollows 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.
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: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 onRESUME_EXPIRED. Persist cursors (to a file or database) if you want to resume after your process restarts too.
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.