Streams

Open one WebSocket connection and subscribe to any channel. Send a subscribe message with an optional filters object. Events stream back as JSON with the same shape as the REST API.

Connection

Authenticate with your API key as a query parameter when opening the socket.

wss://api.anaxer.com/v1/stream?key=YOUR_KEY

Subscribe

After connecting, send a JSON message with a subscribe field set to the channel name. The server acknowledges before events flow:

const ws = new WebSocket("wss://api.anaxer.com/v1/stream?key=YOUR_KEY");

ws.onopen = () => ws.send(JSON.stringify({
  subscribe: "trades",
  filters: { exchange: "pumpfun", side: "buy", minSol: 0.5 }
}));

ws.onmessage = (msg) => {
  const trade = JSON.parse(msg.data);
  console.log(trade.mint, trade.priceSol);
};

Server response:

{
  "type": "subscribed",
  "channel": "trades"
}

Unsubscribe

Stop a channel without closing the connection. Send unsubscribe with the channel name:

{
  "unsubscribe": "trades"
}

Server response:

{
  "type": "unsubscribed",
  "channel": "trades"
}

Connection health

The server sends an application-level heartbeat every 30 seconds:

{ "type": "ping" }

Reply with a pong within 10 seconds or the connection is closed:

{ "type": "pong" }

This lets you distinguish a dead connection from a quiet channel. The SDKs respond to pings and detect stale connections automatically — including on reconnect with exponential backoff.

Stream errors

If a subscription is rejected — for example, your plan does not include a channel — the server sends an error frame instead of a subscribed ack:

{
  "type": "error",
  "code": "forbidden",
  "channel": "trades",
  "message": "Your plan doesn't include this stream."
}

See Error handling for the full list of codes on both REST and stream responses.

Close codes

When the server closes the WebSocket, it uses these application close codes:

CodeReason
1000Normal closure
4001Invalid or missing API key
4002Rate limit exceeded
4003Plan limit on concurrent connections exceeded

Gap recovery

Every event includes a Solana slot number. If your connection drops, note the last slot you received. After reconnecting, call the REST equivalent with ?since=<last_seen_slot> to backfill anything missed while disconnected:

curl "https://api.anaxer.com/v1/trades?since=309812500&exchange=pumpfun" \
  -H "Authorization: Bearer YOUR_KEY"

The since parameter is supported on list endpoints for creations, graduations, and trades.

Connection limits

One WebSocket connection can hold multiple subscriptions — subscribe to creations and trades on the same socket. Your plan limits how many connections you can have open at once, not how many channels you subscribe to within a connection.

Available streams

Reconnection. If the socket drops, reconnect with exponential backoff and re-send your subscribe messages. Use gap recovery to fill any events you missed. The SDKs handle heartbeat, reconnection, and backfill for you.