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.
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 assince in a subscribe message, with the same channel and params as before:
- With an item cursor (
N-0:i), replay continues inside blockNafter itemi. - With a whole-block cursor (
N-0), replay starts at the block afterN. - 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:
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 withmaxUpdatesPerMinute drop trades on purpose, so they have no cursors and reject since. See Sampling.
Checkpoints
About every 30 seconds, the server sends acursor message to each live, non-sampled subscription whose position has moved:
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.cursorevent.cursorcursor.cursor
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:
- Subscribe again without
since. The subscription starts live. - Backfill the time you missed from REST:
- Trades:
GET /trades. Its trade objects include every field of the WebSocket trade event. - Candles:
GET /market/ohlcvorGET /token/ohlcv. - Token or market snapshots:
GET /tokenorGET /market/details.
- Trades:
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:fromBlockandtoBlockare 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.
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:- Keeps the channel, params and latest cursor of every subscription.
- On every new connection, after
welcome, resubscribes withsinceset to the stored cursor. - Reconnects with exponential backoff and jitter after any close.
- Paces its subscribe messages, because the message limit of 20 per second also applies to resubscribes.
- Handles
RESUME_EXPIREDby dropping the cursor, resubscribing live and backfilling from REST.