Subscribe Incremental Order Book
API Description
This Websocket API provides real-time incremental order book for spot market instrument, streaming live bids and asks data.
Note: Incremental Order Book data is only available via Websocket API.
Precautions
- This interface provides an incremental order book with sequence numbers. If there are no changes in the market in certain sequence, the response will include empty asks or bids accordingly.
- Only method 2 is available to achieve this functionality.
Authentication
This is a public Websocket and does not require authentication. For details on using the Websocket API, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2
Websocket URL
Frequency Limit
None
Subscription Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| event | true | String | Subscribe or unsubscribe: sub: subscribe, unsub: unsubscribe. Note: This parameter is case-sensitive. |
| params | true | Json | Requested parameter objects including: |
| -biz | true | String | Specifies the channel, e.g., "exchange". Note: Lowercase is recommended. |
| -type | true | String | Defines the function type, e.g., "depth". Note: Lowercase is recommended. |
| -pairCode | true | String | Currency pair ID, i.e., 78 : BTC_USDT Note: The mapping between currency pair ID and trading instrument can be obtained through Get 24H Trade Summary for All Instrumentsinterface. |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| biz | String | Channel name, e.g., "exchange". |
| pairCode | String | Currency pair ID, i.e., 78 : BTC_USDT Note: The mapping between currency pair ID and trading instrument can be obtained through Get 24H Trade Summary for All Instruments interface. |
| channel | String | Subscription type, e.g., "subscribe". |
| type | String | Message type, e.g., "depth". |
| -result | Boolean | Result of the subscription request: true/false. |
| data | Json | Data object, containing the following fields: |
| -startSeq | Long | Starting sequence number of depth update. |
| -endSeq | Long | Ending sequence number of depth update. |
| -asks | Array | Sell-side depth |
| - | String | Price in quote currency |
| - | String | Quantity in base currency |
| - | String | Sequence number |
| -bids | Array | Buy-side depth |
| - | String | Price in quote currency |
| - | String | Quantity in base currency |
| - | String | Sequence number |
Subscription Example
The following Python code shows how to subscribe incremental order book for BTC-USDT.
Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2.
url = "wss://ws.futurescw.com"
subscription_params = {"event":"sub",
"params":{"biz":"exchange",
"type":"depth",
"pairCode":"78"}} # "78" : BTC-USDT
SpotWebsocketPublic(url, subscription_params) # the function SpotWebsocketPublic() is defined in section (Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2)
Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2.
Response Example
The following is an example response returned by the above Python subscription. The Websocket subscription will keep updating the incremental order book in real-time. For brevity, only the initial response is provided below:
{"biz":"exchange","pairCode":"78","data":{"result":true},"channel":"subscribe","type":"depth"}
{"biz":"exchange","pairCode":"78","data":
"{\"startSeq\":4999544967,\"endSeq\":4999544973,
\"asks\":[
[\"94734.66\",\"0.1137\",\"4999544972\"],
[\"94733.65\",\"0.0685\",\"4999544971\"],
[\"94732.06\",\"0.0000\",\"4999544970\"]],
\"bids\":[
[\"94730.63\",\"0.0903\",\"4999544967\"],
[\"94728.84\",\"0.0554\",\"4999544973\"]]}","type":"depth"},......