持倉
訂閱持倉數據的推送
Topic: position
響應參數
| 參數 | 類型 | 說明 |
|---|---|---|
| id | string | 消息id |
| topic | string | Topic名 |
| creationTime | number | 消息數據創建時間 |
| data | array | Object |
| > category | string | 產品類型 |
| > symbol | string | 合約名稱 |
| > side | string | 持倉方向. Buy,Sell |
| > size | string | 持倉大小 |
| > positionIdx | integer | 倉位標識 |
| > tradeMode | integer | 交易模式。
|
| > positionValue | string | 倉位價值 |
| > riskId | integer | 風險限額id. |
| > riskLimitValue | string | 風險限額id對應的風險限額度. |
| > entryPrice | string | 入場價 |
| > markPrice | string | 標記價 |
| > leverage | string | 槓桿. |
| > positionBalance | string | 倉位保證金. |
| > autoAddMargin | integer | 是否自動追加保證金. 0: 否, 1: 是. |
| > positionMM | string | 倉位維持保證金。
|
| > positionIM | string | 倉位初始保證金。
|
| > liqPrice | string | 倉位強平價格。
|
| > bustPrice | string | 預估破產價. |
| > tpslMode | string | 該字段廢棄, 無意義, 總是返回"Full". |
| > takeProfit | string | 止盈價格 |
| > stopLoss | string | 止損價格 |
| > trailingStop | string | 追蹤止損 |
| > unrealisedPnl | string | 未結盈虧 |
| > cumRealisedPnl | string | 累計盈虧 |
| > isReduceOnly | boolean | 僅當Zoomex需要降低某個交易對的風險限額時有用。
|
| > mmrSysUpdatedTime | string | 僅當Zoomex需要降低某個交易對的風險限額時有用。
|
| > leverageSysUpdatedTime | string | 僅當Zoomex需要降低某個交易對的風險限額時有用。
|
| > positionStatus | string | 倉位狀態. Normal,Liq, Adl |
| > adlRankIndicator | integer | 自動減倉燈. 什麼是自動減倉機制? |
| > createdTime | string | 倉位創建時間戳 (毫秒) |
| > updatedTime | string | 倉位數據更新時間戳 (毫秒) |
訂閱示例
{
"op": "subscribe",
"args": [
"position"
]
}
var url = require('url');
var WebSocket = require('ws');
var crypto = require('crypto');
var endpoint = "wss://stream-testnet.zoomex.com/v3/private"
console.log('attempting to connect to WebSocket %j', endpoint);
var client = new WebSocket(endpoint);
const apiKey="XXXXXXXXX";
const apiSecret="XXXXXXXXX";
client.on('open', function () {
console.log('"open" event!');
console.log('WebSocket Client Connected');
const expires = new Date().getTime() + 10000;
const signature = crypto.createHmac("sha256", apiSecret).update("GET/realtime" + expires).digest("hex");
const payload={
op: "auth",
args: [apiKey, expires.toFixed(0), signature],
}
client.send(JSON.stringify(payload));
setInterval(()=>{client.ping()}, 30000);
client.ping();
client.send(JSON.stringify({"op": "subscribe", "args": ['position']}));
});
client.on('message', function (data) {
console.log('"message" event! %j', JSON.parse(Buffer.from(data).toString()));
});
client.on('ping', function (data, flags) {
console.log("ping received");
});
client.on('pong', function (data, flags) {
console.log("pong received");
});
推送示例
{
"id": "59232430b58efe-5fc5-4470-9337-4ce293b68edd",
"topic": "position",
"creationTime": 1672364174455,
"data": [
{
"positionIdx": 0,
"tradeMode": 0,
"riskId": 41,
"riskLimitValue": "200000",
"symbol": "XRPUSDT",
"side": "Buy",
"size": "75",
"entryPrice": "0.3615",
"leverage": "10",
"positionValue": "27.1125",
"positionBalance": "0",
"markPrice": "0.3374",
"positionIM": "2.72589075",
"positionMM": "0.28576575",
"takeProfit": "0",
"stopLoss": "0",
"trailingStop": "0",
"unrealisedPnl": "-1.8075",
"cumRealisedPnl": "0.64782276",
"createdTime": "1672121182216",
"updatedTime": "1672364174449",
"tpslMode": "Full",
"liqPrice": "",
"bustPrice": "",
"category": "linear",
"positionStatus": "Normal",
"adlRankIndicator": 2
}
]
}