Subscribe Order Book
API Description
This Websocket API provides real-time order book data for a specified instrument, including bids and asks.
Note: Order book data is available via both Resful and Websocket APIs. This page describes the Websocket API. For information on the RESTful API, please click here
Precautions
- This Websocket returns the depth information for the specified instrument.
- This Websocket does not allow user to specify a bid/ask levels. By default, it returns 100 levels of bids and asks in response.
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 > Futures > Websocket Public Interface.
Websocket URL
Frequency Limit
The frequency limit for this subscription is 10 requests/2s per IP.
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., "futures". Note: Lowercase is recommended. |
| -type | true | String | Defines the function type, e.g., "depth". Note: Lowercase is recommended. |
| -pairCode | true | String | The base currency of a instrument. (e.g., BTC or btc). This parameter is case-insensitive. Note: For instruments that start with numbers (e.g., 1000PEPE), both uppercase and lowercase formats are valid. |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| biz | String | Specifies the channel, e.g., "futures". |
| type | String | Function type e.g., "depth" |
| result | boolean | Indicates whether the subscription or or unsubscription is successful: true, false |
| channel | String | Specifies the action performed: subscribe or unsubscribe. |
| pairCode | String | Base currency of the instrument, i.e., BTC |
| data | Json | Data object, containing the following fields: |
| -ask | List | Sell-side depth containing 100 levels |
| -bids | List | Buy-side depth containing 100 levels |
| --p | BigDecimal | Price |
| --m | BigDecimal | Quantity |
| n | String | Base currency of the instrument, i.e., btc. |
Subscription Example
The following Python code shows how to subscribe to the order book of BTC.
Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Public Interface.
subscription_params = { "event": "sub",
"params": {
"biz": "futures",
"pairCode": "BTC",
"type": "depth"}}
url = "wss://ws.futurescw.com/perpum"
FuturesWebsocketPublic(url, subscription_params) # function FuturesWebsocketPublic() is defined in section (Introduction > Authentication & Code Snippet > Futures > Websocket Public Interface.)
Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Public Interface.
Response Example
The Websocket will keep updating the order book for BTC in real time. For brevity, only 8 levels of asks and bids are shown below from Python Subscription:
{'biz': 'futures',
'pairCode': 'BTC',
'data': {'result': True},
'channel': 'subscribe',
'type': 'depth'}
{'biz': 'futures',
'pairCode': 'BTC',
'data': {'asks': [{'p': '95640.3', 'm': '0.807'},
{'p': '95640.5', 'm': '0.201'},
{'p': '95640.6', 'm': '0.317'},
{'p': '95640.7', 'm': '0.08'},
{'p': '95640.8', 'm': '0.234'},
{'p': '95640.9', 'm': '0.39'},
{'p': '95641', 'm': '0.454'},
..........................................
{'p': '96202.8', 'm': '5.819'}],
'bids': [{'p': '95640.2', 'm': '0.068'},
{'p': '95639.9', 'm': '1.381'},
{'p': '95639.8', 'm': '0.099'},
{'p': '95639.7', 'm': '0.655'},
{'p': '95639.5', 'm': '0.441'},
{'p': '95639.4', 'm': '0.187'},
{'p': '95639.2', 'm': '1.104'},
..........................................
{'p': '95095.8', 'm': '0.02'}]......},
'n': 'btc'},
'type': 'depth'}