Skip to main content

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​

  1. 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 Common > Authentication & Code Snippet > Futures > Websocket Private Interface.

Websocket URL​

wss://ws.futurescw.com/perpum

Frequency limit​

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

Subscription Parameters​

ParameterMandatoryTypeDescription
eventtrueStringSubscribe or unsubscribe. sub: subscribe; unsub: unsubscribe.
Note: This parameter is case-sensitive.
paramstrueJsonData object, containing the following fields:
-biztrueStringSpecifies the channel, e.g., "futures".
-typetrueStringDefines the function type, e.g., "assets".

Response Parameters​

ParameterTypeDescription
bizStringSpecifies the channel, e.g., "futures".
typeStringFunction type e.g., "assets"
resultbooleanIndicates whether the subscription or unsubscription was successful: true, false.
channelStringSpecifies the action performed: subscribe or unsubscribe.
pairCodeStringBase currency of the instrument, i.e., BTC
dataJsonData object containing the following fields:
-marginBigDecimalThe amount of margin allocated for the position.
-profitUnrealBigDecimalThe unrealized profit or loss of the position.
-freezeBigDecimalThe frozen amount of funds due to open orders or other restrictions.
-sizeBigDecimalThe total contract size or quantity of assets held.
-availableBigDecimalThe available balance that can be used for trading or withdrawals in USDT
-currencyStringQuote currency (e.g., USDT).
-typeIntegerThe account type or classification.(user can ignore it)
-almightyGoldBigDecimalMega Coupon balance
-transferAvailableBigDecimalThe amount available for transfers
-userIdLongContract account user ID.
-availableMarginBigDecimalAvailable margin
-holdBigDecimalThe 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 Common > 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 (Common > Authentication & Code Snippet > Futures > Websocket Private Interface)

Note: For a complete Java code example, please refer to Common > 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'},.........