Subscribe Trades
API Description
This Websocket interface provides real-time trade data for a specified instrument, including trade quantity, trade price, total trade amount, trade timestamp, and trade direction.
Note: Trades data is accessible via both RESTful and Websocket APIs. This page describes the Websock API. For information on the RESTful API, please please click here
Precautions
- Currently, two methods are availabe for trades 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
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| event | True | String | subscribe |
| args | True | String | "spot/match:symbol", where "symbol" is the trading instrument to be subscribed.Example: "spot/match:BTC-USDT" |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| channel | String | Subscribed channel, i.e., "spot/match:BTC-USDT" |
| subject | String | subject, i.e., "spot/match" |
| data | Array | Data object |
| price | String | Price in quote currency |
| seq | String | Sequence number |
| side | String | Trade direction: BUY/SELL |
| size | String | Quantity in base currency |
| symbol | 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. |
| time | String | Trade time (timestamp in milliseconds) |
Subscription Example
The following Python code shows how to subscribe to trade data for BTC.
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/match:{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 will keep updating the trade data in real-time. For brevity, only one trade data is shown below:
{'channel': 'spot/match:BTC-USDT',
'subject': 'spot/match',
'data': '[{
"price":"82861.81",
"seq":"127365683",
"side":"SELL",
"size":"0.0004",
"symbol":"78",
"time":"1741944585776"
}]'
}
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
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., "fills". 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 Instruments interface. |
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 | Defines the function type, e.g., "fills". |
| -result | Boolean | Result of the subscription request: true or false. |
| data | Json | Data object, containing the following fields: |
| price | String | Price in quote currency |
| seq | String | Sequence number |
| side | String | Trade direction: BUY/SELL |
| size | String | Quantity in base currency |
| symbol | 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. |
| time | String | Trade time (timestamp in milliseconds) |
Subscription Example
The following Python code shows how to subscribe to trade data for BTC.
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":"fills",
"pairCode":"78"}} #78 for 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 will keep updating the trade data in real-time. For brevity, only one trade data is shown below:
{"biz":"exchange","pairCode":"78","data":{"result":true},"channel":"subscribe","type":"fills"}
{"biz":"exchange","pairCode":"78","data":"[
{\"price\":\"94718.84\",
\"seq\":\"130167227\",
\"side\":\"BUY\",
\"size\":\"0.0010\",
\"symbol\":\"78\",
\"time\":\"1745825592789\"
}]","type":"fills"},.....