Genesis Arbitrage

Genesis Arbitrage · · 3 min read

WebSocket

WebSocket is a protocol for a persistent two-way connection over TCP: the client opens the connection once, and from then on the server pushes messages as soon as new data appears. The protocol is defined in RFC 6455 (2011); URLs start with ws:// or wss://, the latter encrypted with TLS.

How the connection works

The connection starts as an ordinary HTTP request with an Upgrade: websocket header. The server answers 101 Switching Protocols, and messages then flow both ways over the same TCP connection without new requests. Ping and pong control frames check that the other side is still there.

With a REST API every update has to be requested, which is polling. Over WebSocket the server sends updates on its own, but the connection has to be kept alive, reopened after a drop, and the stream processed as fast as it arrives.

WebSocket at exchanges

Exchanges stream trades and order book changes over WebSocket. On Binance, the btcusdt@trade stream pushes every BTC/USDT trade, and btcusdt@depth@100ms pushes book changes every 100 ms (Binance docs).

// Browser: BTC/USDT trades from Binance, one message per trade
const ws = new WebSocket(
  'wss://stream.binance.com:9443/ws/btcusdt@trade'
);
ws.onmessage = (event) => {
  const trade = JSON.parse(event.data);
  console.log(trade.p, trade.q); // price and quantity
};

The depth stream sends changes only. A full book is built from a REST snapshot (/api/v3/depth) plus the stream events, matched by update ID; if an event is missed, the book is rebuilt from scratch. A single Binance connection lasts at most 24 hours.

WebSocket and Genesis API

Genesis API has no WebSocket: data is served over REST, and the plan sets output freshness, from 60 seconds on Trial to 5 seconds on Max. Genesis Arbitrage collects the exchange streams itself: in the market order book response, the source field shows whether a book came over WebSocket (ws) or REST (rest), and age_sec gives its age in seconds.

TaskWhat fits
Placing orders and reacting in fractions of a secondThe exchange's WebSocket and trading API
Keeping one pair's full order book in memoryThe exchange's WebSocket plus a REST snapshot
Scanning spreads across 20+ exchanges, alerts, dashboardsGenesis API over REST, polled at the plan's freshness

You cannot trade through Genesis API: orders go through the exchange's own API, at your own risk.

See also: latency, webhook, order book APIs, crypto APIs: types and how to choose.

Questions and answers

Does Genesis API have a WebSocket?

No. All requests are HTTP GET calls to a REST API with JSON responses, and data freshness depends on the plan: 60, 30, 10 or 5 seconds.