Stream token trades
const url = 'https://api.chainmetric.io/v2/stream/token/1/c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2/replay?from_block=26527000&from_seq=7184150972001';const options = { method: 'GET', headers: {'Last-Event-ID': '7184150972001', Authorization: '<Authorization>'}};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request GET \ --url 'https://api.chainmetric.io/v2/stream/token/1/c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2/replay?from_block=26527000&from_seq=7184150972001' \ --header 'Authorization: <Authorization>' \ --header 'Last-Event-ID: 7184150972001'Opens a server-sent event stream of one token’s trades.
Use it to follow every swap in a token as it happens.
Each event is one trade in the shape of GET /v2/token/{chain_id}/{address}/trades.
A trade withdrawn by a chain reorganisation arrives again with revoked: true.
The first event is attached; every later frame event is an envelope holding one trade.
Start from history with from_block or from_seq; without either the stream is live only.
Reconnect with Last-Event-ID to receive the trades you missed; it wins over from_block and from_seq.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Chain id: 1 Ethereum, 56 BNB Chain, 8453 Base, 1399811149 Solana.
Example
1Token address. EVM is 40 lowercase hex characters without 0x; Solana is base58.
Example
c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2Header Parameters
Section titled “Header Parameters”The id of the last event you received. The stream resumes after it.
Example
7184150972001Query Parameters
Section titled “Query Parameters”Start the stream at this block height (Solana slot) and replay history from there. Not with from_seq.
Example
26527000Start the stream after this stream sequence. Not with from_block. Answers 410 when the sequence is no longer held.
Example
7184150972001Responses
Section titled “Responses”A server-sent event stream. Each event has an event: name and a data: line holding one JSON object.
Resumable streams also send id: lines: keep the last id and send it as Last-Event-ID when you reconnect.
A : keepalive comment arrives every 20 seconds.
Examples
event: attacheddata: {"subject":"token_trades.1.c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
id: 26527763.112.450.0event: framedata: {"kind":"token_trades","version":1,"chain_id":1,"address":"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","lane":"fast","commitment":"confirmed","seq":7184150972001,"data":{"side":"sell","price_usd":1663.47,"block":26527763,"event_index":450}}
: keepaliveThe request is malformed, for example a bad address, an unknown chain or an out-of-range parameter. Do not retry unchanged.
Every error answer has this shape. error and message carry the same text.
object
What went wrong. For 5xx answers this is the status text.
The same text as error.
The HTTP status.
Examples
{ "error": "blockchain: unknown chain: \"ethereum\"", "message": "blockchain: unknown chain: \"ethereum\"", "statusCode": 400}The key is missing (api key missing), unknown (api key unknown) or revoked (api key revoked). Send Authorization: <key>.
Every error answer has this shape. error and message carry the same text.
object
What went wrong. For 5xx answers this is the status text.
The same text as error.
The HTTP status.
Examples
{ "error": "api key missing", "message": "api key missing", "statusCode": 401}The from_seq sequence is no longer held. Resume with from_block instead.
Every error answer has this shape. error and message carry the same text.
object
What went wrong. For 5xx answers this is the status text.
The same text as error.
The HTTP status.
Example generated
{ "error": "example", "message": "example", "statusCode": 1}The key’s request rate limit is reached. No Retry-After is sent; back off and retry.
Every error answer has this shape. error and message carry the same text.
object
What went wrong. For 5xx answers this is the status text.
The same text as error.
The HTTP status.
Examples
{ "error": "api key rate limit reached", "message": "api key rate limit reached", "statusCode": 429}The service is busy or catching up. Wait for the Retry-After header’s seconds when present (5 or 10), then retry. Without it, retry with exponential backoff.
Every error answer has this shape. error and message carry the same text.
object
What went wrong. For 5xx answers this is the status text.
The same text as error.
The HTTP status.
Examples
{ "error": "Service Unavailable", "message": "Service Unavailable", "statusCode": 503}Headers
Section titled “Headers”Seconds to wait before retrying.