Skip to main content

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

  1. This Websocket returns the depth information for the specified instrument.
  2. 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

wss://ws.futurescw.com/perpum

Frequency Limit

The frequency limit for this subscription is 10 requests/2s per IP.

Subscription Parameters

ParameterMandatoryTypeDescription
eventtrueStringSubscribe or unsubscribe. sub: subscribe; unsub: unsubscribe.
Note: This parameter is case-sensitive.
paramstrueJsonRequested parameter objects including:
-biztrueStringSpecifies the channel, e.g., "futures".
Note: Lowercase is recommended.
-typetrueStringDefines the function type, e.g., "depth".
Note: Lowercase is recommended.
-pairCodetrueStringThe 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

ParameterTypeDescription
bizStringSpecifies the channel, e.g., "futures".
typeStringFunction type e.g., "depth"
resultbooleanIndicates whether the subscription or or unsubscription is successful: true, false
channelStringSpecifies the action performed: subscribe or unsubscribe.
pairCodeStringBase currency of the instrument, i.e., BTC
dataJsonData object, containing the following fields:
-askListSell-side depth containing 100 levels
-bidsListBuy-side depth containing 100 levels
--pBigDecimalPrice
--mBigDecimalQuantity
nStringBase 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'}