Skip to main content

Subscribe Margin Mode

API Description

This Websocket provides real-time updates on the margin mode (Isolated or Cross Margin) and the position layout (Merged or Split Positions), allowing users to manage their trading strategy effectively.

Note: Margin mode 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 does not return data unless there is a change in margin mode or position layout after the connection is established. If no changes occur, no updates will be sent.

Authentication

This is a private Websocket and requires authentication. For details on using the Websocket API, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Private Interface.

Websocket URL

wss://ws.futurescw.com/perpum

Frequency limit

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

Subscription Parameters

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

Response Parameters

ParameterTypeDescription
bizStringSpecifies the channel, e.g., "futures".
typeStringDefines the function type, e.g., "user_setting".
resultbooleanIndicates whether the subscription or unsubscription was successful: true, false.
channelStringSpecifies the action performed: subscribe or unsubscribe.
-layoutIntegerPosition layout:
0: Merged positions
1: Split positions
-positionModelIntegerPosition margin mode:
0: Isolated margin
1: Cross margin
-userIdLongContract account user ID

Subscription Example

The following Python code shows how to check the position layout and position margin mode.

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": "user_setting"}}
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': 'user_setting'}
{'biz': 'futures',
'data': [{'layout': 1, 'positionModel': 1, 'userId': 600001359}],
'type': 'user_setting'}.....