WebSocket
This document provides a detailed introduction to the QuBit WebSocket API, which offers a stable and low-latency channel for receiving real-time market data and private user data updates.
The WebSocket API operates on a data streaming model. Clients maintain a persistent connection with the server, which actively pushes data updates to subscribed clients. For operations that you need to initiate, such as placing an order or querying historical data, please use our REST API.
1. Endpoints
Mainnet:
wss://ws.qubit.com/ws/v1Testnet:
wss://ws.qubit-test.com/ws/v1
2. Connecting
You can connect to the endpoints listed above using any standard WebSocket client library. Once connected, you can begin sending messages to authenticate and subscribe.
Example Connection via Command Line (wscat):
$ wscat -c wss://ws.qubit.com/ws/v1
Connected (press CTRL+C to quit)
> {"op":"subscribe","args":[{"channel":"trades","instId":"BTC-USDT-SWAP"}]}
< {"event":"subscribe","arg":{"channel":"trades","instId":"BTC-USDT-SWAP"},"ts":...}3. Message Format
All messages transferred between the client and server are UTF-8 encoded JSON strings.
Client Request:
{ "op": "subscribe", // Operation: subscribe, unsubscribe, login, pong "args": [ ... ] // Operation arguments in an array, supporting batch operations }Server Response/Push:
{ "event": "subscribe", // Event type: subscribe, unsubscribe, login, error, or a channel name "arg": { ... }, // Corresponding channel arguments "data": [ ... ], // The pushed business data "ts": 1678889400123 // Message timestamp (milliseconds) }
Last updated