Skip to content
Sign up

WebSocket

WebSocket

One connection for every market: prices, trades and books pushed the moment they change, and your own orders as they fill.

Not live yet. This page shows how it will work, so you can plan your build today. Everything under REST works now, and so does live market data over a stream.

Connect#

Open a WebSocket to wss://ws.reirex.com/v1. You send JSON and receive JSON, one message per frame.

const socket = new WebSocket("wss://ws.reirex.com/v1");

socket.addEventListener("open", () => {
  socket.send(JSON.stringify({
    op: "subscribe",
    channels: [
      { name: "ticker", symbol: "BTC" },
      { name: "trades", symbol: "BTC" },
    ],
  }));
});

socket.addEventListener("message", (event) => {
  const message = JSON.parse(event.data);
  if (message.event === "ping") socket.send(JSON.stringify({ op: "pong" }));
  else console.log(message);
});

Subscribe#

Send subscribe with the channels you want. Each one is confirmed, then its data starts to arrive.

JSON
{
  "event": "subscribed",
  "channel": "ticker",
  "symbol": "BTC"
}

unsubscribe takes the same list and stops them.

JSON
{
  "op": "unsubscribe",
  "channels": [
    {
      "name": "trades",
      "symbol": "BTC"
    }
  ]
}

Stay connected#

We send a ping every 15 seconds; answer it with pong. A connection that stays silent for 60 seconds is closed.

JSON
{"event":"ping","t":1791994457757}
{"op":"pong"}

If the connection drops, reconnect with backoff and subscribe again. The book channel always opens with a full snapshot, so there is never anything to replay.

Errors#

A request we can't serve is answered with an error event, and the connection stays open.

JSON
{
  "event": "error",
  "error": "not_found",
  "channel": "ticker",
  "symbol": "NOPE"
}

Limits#

  • 5 connections per IP address.
  • 100 subscriptions per connection.
  • 20 messages a second from you.