Skip to main content

Subscribe Order Book

API Description

This Websocket API provides real-time order book updates for a specified spot market instrument, streaming live bid and ask data.

Note: Order book data is accessible via both RESTful and Websocket APIs. This page describes the Websock API. For information on the RESTful API, please click here

Precautions

  1. The Websocket interface provides real-time order book updates, delivering 20 levels of bids and asks by default.
  2. Currently, two methods are availabe for order book subscription. User should exercise caution while creating connection.

Method 1

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 1

Websocket URL

wss://ws.futurescw.info?token={your_token}

Frequency Limit

None

Subscription Parameters

ParameterMandatoryTypeDescription
eventTrueStringsubscribe
argsTrueString"spot/level2_20:symbol", where "symbol" is the trading instrument to be subscribed.
Example: "spot/level2_20:BTC-USDT"

Response Parameters

ParameterTypeDescription
channelStringSubscribed channel, i.e., 'spot/level2_20:BTC-USDT'
subjectStringSubscribed subject, i.e., 'spot/level2_20'
datajsonData object
asksArrayArray containing 20 asks levels
StringPrice in quote currency
StringVolume in base currency
bidsArrayArray containing 20 bids levels
StringPrice in quote currency
StringVolume in base currency
timeLongTimestamp (in milliseconds)
seqBig decimalSequence number

Subscription Example

The following Python code shows how to subscribe order book for BTC-USDT.

Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 1

symbol = "BTC-USDT"
args = f'spot/level2_20:{symbol}'
SpotWebsocketPublic(args)    # the function SpotWebsocketPublic() is defined in section (Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 1)

Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 1.

Response Example

The following is an example response returned by the above Python subscription. The Websocket subscription will keep updating the order book in real-time. For brevity, only the initial response is provided below:

{'channel': 'spot/level2_20:BTC-USDT',
'subject': 'spot/level2_20',
'data': '{
"asks":[
["85276.46","0.3085"],["85276.58","0.5241"],["85276.69","0.0396"],["85276.81","0.0447"],["85276.86","0.3087"],["85276.92","0.0454"],["85276.98","0.6008"],["85277.04","0.0685"],["85277.09","0.0259"],["85277.15","0.0466"],["85277.21","0.0469"],["85277.27","0.0485"],["85277.32","0.0374"],["85277.38","0.0437"],["85277.44","0.0784"],["85277.50","0.0378"],["85277.55","0.0989"],["85277.62","0.0714"],["85277.67","0.0270"],["85277.73","0.0547"]
],
"bids":[
["85276.10","0.6228"],["85275.87","1.3056"],["85275.84","0.7416"],["85275.78","0.0267"],["85275.72","0.7025"],["85275.66","0.0829"],["85275.61","0.0192"],["85275.55","0.0662"],["85275.49","0.0425"],["85275.43","0.0441"],["85275.38","0.0282"],["85275.32","0.0208"],["85275.30","1.2221"],["85275.26","0.0800"],["85275.20","0.0245"],["85275.15","0.0519"],["85275.08","0.0634"],["85275.03","0.0216"],["85274.97","0.0451"],["85274.92","0.0202"]
],
"time":1743151955887,
"seq":639334113}'
}

Method 2

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

wss://ws.futurescw.com

Frequency Limit

None

Request Parameters

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

Response Parameters

ParameterTypeDescription
bizStringChannel name, e.g., "exchange".
pairCodeStringCurrency 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.
channelStringSubscription type, e.g., "subscribe".
typeStringDefines the function type, e.g., "depth_snapshot".
-resultBooleanResult of the subscription request: true or false.
dataJsonData object, containing the following fields:
asksArrayArray containing 100 asks levels
StringPrice in quote currency
StringVolume in base currency
bidsArrayArray containing 100 bids levels
StringPrice in quote currency
StringVolume in base currency
timeLongTimestamp (in milliseconds)
seqBig decimalSequence number

Request Example

The following Python code shows how to subscribe to order book for "BTC-USDT".

Note: For complete code, 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_snapshot",
"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, 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 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_snapshot"}

{"biz":"exchange","pairCode":"78","data":
"{\"asks\":
[[\"94702.48\",\"0.7071\"],[\"94702.98\",\"0.3480\"],
[\"94703.01\",\"0.9511\"],[\"94703.09\",\"0.2665\"],
[\"94703.20\",\"0.0152\"],[\"94703.32\",\"0.0422\"],
[\"94703.43\",\"0.0198\"],[\"94703.54\",\"0.0567\"],
[\"94703.65\",\"0.0693\"],[\"94703.77\",\"0.0386\"],
[\"94703.82\",\"0.9674\"],[\"94703.88\",\"0.0336\"],
[\"94703.99\",\"0.0196\"],[\"94704.10\",\"0.0437\"],
[\"94704.21\",\"0.0372\"],[\"94704.33\",\"0.0239\"],
[\"94704.34\",\"0.9195\"],[\"94704.44\",\"0.0343\"],
[\"94704.55\",\"0.0198\"],[\"94704.58\",\"0.7682\"]],
\"bids\":
[[\"94702.32\",\"0.2128\"],[\"94702.24\",\"0.0753\"],
[\"94702.21\",\"0.2408\"],[\"94702.12\",\"0.0540\"],
[\"94702.10\",\"0.0253\"],[\"94702.01\",\"0.0298\"],
[\"94701.98\",\"0.0377\"],[\"94701.90\",\"0.0263\"],
[\"94701.87\",\"0.0341\"],[\"94701.76\",\"0.0695\"],
[\"94701.67\",\"0.0758\"],[\"94701.65\",\"0.0635\"],
[\"94701.53\",\"0.0271\"],[\"94701.45\",\"0.0178\"],
[\"94701.42\",\"0.0166\"],[\"94701.34\",\"0.0261\"],
[\"94701.31\",\"0.0354\"],[\"94701.23\",\"0.0187\"],
[\"94701.20\",\"0.0529\"],[\"94701.09\",\"0.0471\"]],
\"time\":1745826899772,
\"seq\":704538922}",
"type":"depth_snapshot"},.................