Skip to main content

HFT Sockets Overview

HFT real-time data streams over NATS, a lightweight publish/subscribe messaging system. The protocol is different from the Socket.IO sockets used by Spot and Futures v2, but the idea is the same: open a long-lived connection, tell the server which subjects (topics) you care about, and the server pushes messages on those subjects as soon as they happen.

If you've used MQTT, Redis pub/sub, or Kafka, this will feel familiar. If you haven't — most NATS client libraries reduce it to three calls: connect(), subscribe(subject), and a callback for incoming messages.

Connection

Socket URLwss://pc-nats-prod.coinswitch.co

Use any NATS WebSocket client for your language. Connect to the URL, then subscribe to one or more subjects (NATS terminology for channels).

Subject naming

Subjects follow a hierarchical, dot-delimited convention:

v1.f.<scope>.<feed-type>.<filter>

The trailing component is either a specific market (BTC/USDT) or > — a NATS wildcard meaning "all markets".

SubjectFeed
v1.f.public.futures.ltp.>Last-traded-price stream — every public trade across all markets. See Trades.
v1.f.public.futures.ltp.BTC/USDTTrades for a single market.
v1.f.public.futures.depth-update.>Order-book updates across all markets. See Depth.
v1.f.public.futures.depth-update.BTC/USDTOrder book for a single market.
v1.f.ex1.public.futures.ticker.>24h ticker stats across all markets. See Ticker.
v1.f.ex1.public.futures.ticker.BTC/USDTTicker for a single market.
v1.f.ex1.private.subAccountId.<id>.tradeYour fill stream (private). See Private Streams.
v1.f.ex1.private.subAccountId.<id>.orderYour order updates (private). See Private Streams.

Public vs private subjects

Public subjects (v1.f.public.*, v1.f.ex1.public.*) carry market data and require no authentication. Anyone can connect and subscribe.

Private subjects (v1.f.ex1.private.*) carry your account-specific data. To subscribe, you must:

  1. Call GET /dma/api/v1/socket/signature (over HTTPS, signed as a normal HFT request) to obtain {api_key, expires, signature}.
  2. Use those three values to authenticate the NATS WebSocket connection.

See Private Streams for the full flow with code samples.

Symbol format

Public subjects use BASE/QUOTE (with a slash) — e.g. BTC/USDT, ETH/USDT. This differs from REST endpoints, which use the unseparated form BTCUSDT.

Reconnects

NATS clients reconnect automatically. After a reconnect, you must re-subscribe to all your subjects — subscriptions are bound to the connection, not persisted server-side. Most NATS client libraries expose a callback for this.