WebSocket Push
Overview WebSocket is a new protocol in HTML5 that enables full-duplex communication between clients and servers, allowing rapid bidirectional data transmission. A client-server connection can be established through a simple handshake, and the server can actively push information to clients based on business rules. Its advantages include:
Small request headers (~2 bytes) during client-server data transfer.
Both client and server can actively send data.
Eliminates repeated TCP connection creation/destruction, saving bandwidth and server resources.
Developers are strongly advised to use the WebSocket API to obtain market data, order book depth, and other information.
Basic Information Spot Market Base URL: wss://api.xxx.com/spot/ws
Futures Market Base URL: wss://api.xxx.com/futures/ws (Replace xxx.xxx with the exchange's primary domain)
All returned data (except heartbeat data) is compressed in binary format (requires Gzip decompression).
Demo https://github.com/exchange2021/openapidemo/blob/master/src/main/java/com/ws/WsTest.java
Parameter Examples Event Channel Description sub market_$symbol_depth_step0 Subscribe to order book depth unsub market_$symbol_depth_step0 Unsubscribe from depth sub market_$symbol_trade_ticker Subscribe to real-time trades unsub market_$symbol_trade_ticker Unsubscribe from trades sub market_$symbol_ticker Subscribe to 24h ticker unsub market_$symbol_ticker Unsubscribe from 24h ticker sub market_$symbol_kline_1min Subscribe to 1min K-line req market_$symbol_kline_1month Request 1month historical K-line java { "pong": 15359750 } Subscribe to Full Order Book Depth Subscription Example:
java { "event": "sub", "params": { "channel": "market_$symbol_depth_step0", // $symbol e.g., Spot: btcusdt, Futures: e_btcusdt "cb_id": "1" // (Optional) Business ID } } Returns up to 30 buy/sell orders:
java { "channel": "market_btcusdt_depth_step0", "ts": 1506584998239, "tick": { "asks": [ // Sell orders [10000.19, 0.93], [10001.21, 0.2], [10002.22, 0.34] ], "buys": [ // Buy orders [9999.53, 0.93], [9998.2, 0.2], [9997.19, 0.21] ] } } Subscribe to Real-Time Trades Subscription Example:
java { "event": "sub", "params": { "channel": "market_$symbol_trade_ticker", "cb_id": "1" // (Optional) } } Response:
java { "channel": "market_$symbol_trade_ticker", "ts": 1506584998239, // Timestamp "tick": { "id": 12121, // Max trade ID in data "ts": 1506584998239, // Max timestamp in data "data": [ { "side": "buy", // Direction: buy/sell "price": 32.233, // Price "vol": 232, // Volume "amount": 323, // Total value "ds": "2017-09-10 23:12:21" // Timestamp (human-readable) } ] } } Subscribe to K-line Data Subscription Example:
java { "event": "sub", "params": { "channel": "market_$symbol_kline_[1min/5min/15min/30min/60min/1day/1week/1month]", "cb_id": "1" // (Optional) } } Response:
java { "channel": "market_$symbol_kline_1min", // 1min = 1-minute K-line "ts": 1506584998239, "tick": { "id": 1506602880, // Interval start time "vol": 1212.12211, // Volume "open": 2233.22, // Open price "close": 1221.11, // Close price "high": 22322.22, // High price "low": 2321.22 // Low price } } Subscribe to 24h Ticker Subscription Example:
java { "event": "sub", "params": { "channel": "market_$symbol_ticker", "cb_id": "1" // (Optional) } } Response:
java { "channel": "market_$symbol_ticker", "ts": 1506584998239, "tick": { "amount": 123.1221, // Turnover "vol": 1212.12211, // Volume "open": 2233.22, // Open price "close": 1221.11, // Close price "high": 22322.22, // High price "low": 2321.22, // Low price "rose": -0.2922 // Price change ratio } } Request Historical K-line Data Request Example:
java { "event": "req", "params": { "channel": "market_$symbol_kline_[1min/5min/15min/30min/60min/1day/1week/1month]", "cb_id": "1", "endIdx": "1506602880", // (Optional) Return data before this timestamp "pageSize": 100 // (Optional) Number of records } } Response (max 300 records):
java { "event_rep": "rep", "channel": "market_$symbol_kline_5min", "cb_id": "Original cb_id", "ts": 1506584998239, "data": [ { "id": 1506602880, // Interval start time "amount": 123.1221, // Turnover "vol": 1212.12211, // Volume "open": 2233.22, // Open price "close": 1221.11, // Close price "high": 22322.22, // High price "low": 2321.22 // Low price }, ... ] } Request Trade Records Request Example:
java { "event": "req", "params": { "channel": "market_$symbol_trade_ticker", "cb_id": "1" // (Optional) } } Response:
java { "event_rep": "rep", "channel": "market_$symbol_trade_ticker", "cb_id": "Original cb_id", "ts": 1506584998239, "status": "ok", "data": [ { "side": "buy", // Direction "price": 32.233, // Price "vol": 232, // Volume "amount": 323 // Total value }, ... ] }
Last updated