Subscribe Assets
API Description
This Websocket interface allows users to retrieve contract account asset information, including available margin, USDT balance, and frozen assets, etc.
Note: Asset data is accessible via both RESTful and Websocket APIs. This page describes the WebSocket API. For information on the RESTful API, please click here
Precautions
- The Websocket connection does not return any response unless there is a change in assets. If no changes occur, the Websocket will not provide updates. Users should ensure that they have active trading activity to receive real-time asset updates.
Authentication
This is a private Websocket and requiresauthentication. For details on using the Websocket API, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Private Interface.
Websocket URL
Frequency limit
The frequency limit for this subscription is 10 requests/2s per user ID.
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 | Data object, containing the following fields: |
| -biz | true | String | Specifies the channel, e.g., "futures". |
| -type | true | String | Defines the function type, e.g., "assets". |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| biz | String | Specifies the channel, e.g., "futures". |
| type | String | Function type e.g., "assets" |
| result | boolean | Indicates whether the subscription or unsubscription was 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: |
| -margin | BigDecimal | The amount of margin allocated for the position. |
| -profitUnreal | BigDecimal | The unrealized profit or loss of the position. |
| -freeze | BigDecimal | The frozen amount of funds due to open orders or other restrictions. |
| -size | BigDecimal | The total contract size or quantity of assets held. |
| -available | BigDecimal | The available balance that can be used for trading or withdrawals in USDT |
| -currency | String | Quote currency (e.g., USDT). |
| -type | Integer | The account type or classification.(user can ignore it) |
| -almightyGold | BigDecimal | Mega Coupon balance |
| -transferAvailable | BigDecimal | The amount available for transfers |
| -userId | Long | Contract account user ID. |
| -availableMargin | BigDecimal | Available margin |
| -hold | BigDecimal | The amount currently held in orders/positions. |
Subscription Example
The following Python code shows how to subscribe to assets using Websocket.
Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Private Interface.
url = "wss://ws.futurescw.com/perpum"
subscription_payload = {"event": "sub",
"params": {"biz": "futures",
"type": "assets"}}
api_key= "your_api_key"
sec_key = "your_sec_key"
FuturesWebsocketPrivate(url, api_key, sec_key, subscription_payload) # function FuturesWebsocketPrivate() is defined in section (Introduction > Authentication & Code Snippet > Futures > Websocket Private Interface)
Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Private Interface.
Response Example
The following is an example response returned by the above Python subscription, it keeps updatating in real-time:
{'biz': 'futures',
'data': {'result': True},
'channel': 'subscribe',
'type': 'assets'}
{'biz': 'futures',
'pairCode': 'USDT',
'data': [{'margin': 0.0,
'profitUnreal': 0,
'freeze': 0.0,
'size': 0,
'available': 488.53777423,
'currency': 'usdt',
'type': 7,
'almightyGold': 0,
'transferAvailable': 488.53777423,
'userId': 1162061,
'availableMargin': 488.53777423,
'hold': 0.0},
{'margin': 0.0,
'profitUnreal': 0,
'freeze': 0.0,
'size': 0,
'available': 488.53777423,
'currency': 'usdt',
'type': 7,
'almightyGold': 0,
'transferAvailable': 488.53777423,
'userId': 1162061,
'availableMargin': 488.53777423,
'hold': 0.0}],
'type': 'assets'},.........