Skip to main content
Connect to wss://api.gains.trade/v1/{chain}/ws. The server greets with {"op":"hello","chain":"arbitrum","heartbeatMs":15000}.

Messages you send

Private channels need one auth message first, then the same subscribe:
The auth signature is the REST request signature with primaryType: "wsAuth", method: "WS", path: "/v1/{chain}/ws" and the empty-body hash. timestamp and nonce are strings here.

Messages you receive

Every subscription is acknowledged with {"op":"subscribed","channel":...,"market":...} and the first data message carries snapshot: true. Deltas follow with snapshot: false.
Data objects have the same shape as the REST resources (Price, OrderBook, Candle, RecentTrade, Order, Position, Account in the reference).

Heartbeat and reconnects

The server sends {"op":"ping","timestamp":...} every 15 seconds and closes the connection after 45 seconds without any message from you; answer with {"op":"pong"} or send your own ping. On book and prices, a gap in seq means you missed a message: unsubscribe and subscribe again to get a fresh snapshot. After a reconnect, authenticate again and re-send your subscriptions. The SDK’s GainsWebSocket does both automatically and exposes channels as event listeners or async iterators.

Limits

Client messages are capped at 4 KB. One connection carries any number of channels; open one connection per chain rather than one per channel.