GET /token/ohlcvfor history.- The
ohlcvchannel onwss://api.example.com/v1/wsfor live updates.
0x4200000000000000000000000000000000000006) with 1-minute candles. They run on Node.js 22 or later, which has fetch and WebSocket built in.
How the pieces fit
Both accept the same periods:
1s, 5s, 15s, 30s, 1m, 5m, 15m, 30m, 1h, 4h, 6h, 12h, 1d, 1w, 1M. 1m is one minute and 1M is one calendar month. All buckets are aligned to UTC, and 1w buckets start on Monday.
t is the bucket start in Unix milliseconds on both sides, so it is the key you merge on. Prices are in USD.
Use the evm:8453 form everywhere. The WebSocket API rejects a bare 8453.
Steps
1
Subscribe to live candles first
Open the socket and subscribe before you fetch history. Keep any events that arrive while the REST request runs, so nothing is lost between the two.The server answers with
subscribed and a cursor. If the token has no pool, it answers with an error of code TOKEN_NOT_FOUND and message Token or pool not found.2
Load history
limitis 1 to 2000 candles (default 500). Withoutfrom, the request covers the lastlimitperiods up toto(default now), so you get at mostlimitcandles from that window.fill=trueinserts flat candles (o = h = l = c= previous close,v = 0) for buckets without trades between the first and last candle. Without it, those buckets are missing.- Candles come back oldest first. The last one is the newest bucket that had a trade, which is the bucket in progress if a trade already happened in it.
3
Merge live updates by t
Each
ohlcv event carries the whole current candle, not a delta. Merge it by t:- Same
tas your last candle: replace the last candle. - Greater
t: a new bucket started; append it. - Smaller
t: ignore it.
4
Load older candles on scroll
To page back, request the same period with Here the oldest candle has
to set to one millisecond before your oldest candle:t = 1796306580000, so to is 1796306579999 (candles[0].t - 1). Prepend the result. The request only looks back limit periods before to, so an empty array means there were no trades in that window, not necessarily that there is no older data. To keep going back, move to further back or switch to a longer period.Full example
Reconnects, gaps and expired cursors
- Reconnect. Keep the newest
cursorfrom events and fromcursorcheckpoints (sent every 30 seconds). After a disconnect, subscribe again withsinceset to it. The server replays the updates you missed, then continues live. See Cursors and resume. RESUME_EXPIRED. The stream keeps about 10 minutes of history. If you were away longer, the subscription is refused. Subscribe again withoutsinceand reload the candles from REST.gap. If the stream had to skip blocks, you get agapmessage with an inclusivefromBlock..toBlockrange. Trades in those blocks never reach the channel, so your last candles may be incomplete. Reload the recent candles from REST, which reads from storage.- Restarts. A
{"type":"reconnect"}message followed by close code1012means the server is restarting. Reconnect and resume as above. See Limits and errors.
Things to know
- Which pool. For a token, both endpoints use the token’s best pool: the one with the highest 24-hour volume. The REST endpoint picks it on every request; the live channel re-checks it at most once a minute. Each event’s
data.pooltells you which pool it came from. If it changes, the best pool changed, so reload history from REST. To follow one pool regardless, useGET /market/ohlcvand subscribe withpoolinstead oftoken. - Launchpad tokens. For a token that graduated from a bonding curve, REST history can include older candles from the curve before graduation. Live updates only come from the current pool.
- Updates come with trades. The channel sends a candle only after a trade changes it. Quiet buckets produce no event, and a new bucket opens at the previous close when the next trade arrives. If you want flat candles for quiet periods, like
fill=truedoes, insert them yourself between the last candle and the new one. - Not every trade produces an event. No event is sent until the candle has an opening price, and an update can be skipped if the server is slow to compute it. The next event carries the full candle again, so replacing by
tkeeps the chart correct. - Too many updates. For a busy token, add
maxUpdatesPerMinute(1 to 600) to the subscription params to sample updates. Sampled subscriptions have no cursors and can’t resume, so on reconnect subscribe again withoutsinceand reload recent candles from REST. - Sub-minute periods. For
1sto30s, REST looks back at mostlimit× period beforeto.