Subscribe Mark Price
API Description
This websocket allows querying the real time mark price for a specified trading instrument.
Note: This function is only available via Websocket API.
Precautions
None
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 > Futures > Websocket Public Interface.
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., "futures". Note: Lowercase is recommended. |
| -type | true | String | Defines the function type, e.g., "mark_price" Note: Lowercase is recommended. |
| -pairCode | true | String | The base currency of the instrument. (e.g., BTC or btc). This parameter is case-insensitive. Note: For instruments that start with numbers (e.g., 1000PEPE), both uppercase and lowercase formats are valid. |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| biz | String | Specifies the channel, e.g., "futures" |
| type | String | Defines the function type, e.g., "mark_price" |
| 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, e.g., BTC. |
| data | Json | Data object, containing the following fields: |
| -p | Big Decimal | Index price. |
| -n | String | Base currency of the instrument, e.g., btc |
Subscription Example
The following Python code shows how to subscribe to mark price for "BTC".
Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Public Interface.
subscription_params = { "event": "sub",
"params": {
"biz": "futures",
"pairCode": "BTC",
"type": "mark_price"}}
url = "wss://ws.futurescw.com/perpum"
FuturesWebsocketPublic(url, subscription_params) #function FuturesWebsocketPublic() is defined in section (Introduction > Authentication & Code Snippet > Futures > Websocket Public Interface)
Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Futures > Websocket Public Interface.
Response Example
The Websocket subscription will keep updating the mark price in real-time. For brevity, only the initial response for python subscrption is provided below:
{'biz': 'futures',
'pairCode': 'BTC',
'data': {'result': True},
'channel': 'subscribe',
'type': 'mark_price'}
{'biz': 'futures',
'pairCode': 'btc',
'data': {'p': 92396.9, 'n': 'btc'},
'type': 'mark_price'},....