订阅当前订单
API说明
此Websocket订阅提供所有合约上所有未成交/已成交订单的实时更新。响应包括合约、方向、数量、数量单位、保证金、杠杆、maker费用、taker费用、时间戳等详情。
注意:当前订单数据可通过RESTful和Websocket接口获取。本页是Websocket接口的描述。如需了解RESTful接口,请参见 跳转
注意事项
- 除非在建立连接后下达新订单,否则Websocket连接不会返回任何响应。如果未下达订单,将不会收到更新。用户应确保有活跃的交易活动才能接收实时订单更新。
- 此Websocket提供所有合约上所有未成交/已成交订单的实时更新。
认证
这是一个私有Websocket,需要认证。有关使用Websocket API的详细信息,请参考简介 > 认证和代码示例 > 合约 > Websocket私有接口。
Websocket URL
频率限制
此订阅的频率限制为每IP每2秒30个请求。
订阅参数
| 参数 | 必填 | 类型 | 描述 |
|---|---|---|---|
| event | true | String | 订阅或取消订阅。sub:订阅;unsub:取消订阅。注意:此参数区分大小写。 |
| params | true | Json | 请求的参数对象,包括: |
| -biz | true | String | 指定频道,例如"futures"。 |
| -type | true | String | 定义功能类型,例如"order"。 |
响应参数
| 参数 | 类型 | 描述 |
|---|---|---|
| biz | String | 指定频道,例如"futures"。 |
| type | String | 定义功能类型,例如"order"。 |
| result | boolean | 表示订阅或取消订阅是否成功:true,false。 |
| channel | String | 指定执行的操作:subscribe或unsubscribe。 |
| pairCode | String | 合约的基础货币,即BTC |
| data | Json | 数据对象,包含以下字段: |
| -currentPiece | String | 当前合约数量 |
| -leverage | Integer | 持仓杠杆率 |
| -originalType | String | 原始订单类型 |
| -contractType | String | 合约类型:1:永续合约 |
| -frozenFee | String | 冻结订单费用 |
| -orderStatus | String | 订单状态:unFinish:未成交,part:部分成交,Finish:完全成交,Cancel:已取消 |
| -instrument | String | 合约的基础货币,即BTC |
| -quantityUnit | Integer | 用于指定订单数量的计量单位: 0:以计价货币计价(例如,BTC-USDT 合约中的 USDT); 1:以合约张数计价; 2:以基础货币计价(例如,BTC-USDT 合约中的 BTC)。 |
| -source | String | 来源:api/web |
| -updatedDate | Long | 最后订单更新的时间戳 |
| -positionModel | Integer | 持仓持仓模式:0:逐仓,1:全仓 |
| -posType | String | 持仓类型:plan/planTrigger/execute |
| -baseSize | String | 基础货币订单规模 |
| -liquidateBy | String | 开仓和平仓事件类型 |
| -makerFee | String | maker费用 |
| -totalPiece | String | 合约总数量 |
| -orderPrice | String | 用户指定的订单价格 |
| -id | String | 订单ID |
| -direction | String | 交易方向:做多(long)/做空(short) |
| -margin | String | 持仓使用的保证金 |
| -indexPrice | String | 最新指数价格 |
| -quantity | String | 基于quantityUnit 指定订单数量: 当 quantityUnit = 0 时,数量以计价货币计量(例如,BTC-USDT 中的 USDT); 当 quantityUnit = 1 时,数量以合约张数计量; 当 quantityUnit = 2 时,数量以基础货币计量(例如,BTC-USDT 中的 BTC)。 |
| -takerFee | String | taker费用 |
| -userId | String | 合约账户用户ID |
| -createdDate | Long | 订单创建时间戳 |
| -positionMargin | String | 持仓保证金 |
| -status | String | 状态:open/close/cancel |
订阅示例
以下Python代码展示了如何订阅当前订单。
注意:完整代码示例请参考简介 > 认证和代码示例 > 合约 > Websocket私有接口。
url= "wss://ws.futurescw.com/perpum"
subscription_payload = {"event": "sub",
"params": {"biz": "futures",
"type": "order"}}
api_key= "your_api_key"
sec_key = "your_sec_key"
FuturesWebsocketPrivate(url, subscription_payload, api_key, sec_key) # function FuturesWebsocketPrivate() is defined in section (Introduction > Authentication & Code Snippet > Futures > Websocket Private Interface)
注意:完整Java代码示例请参考简介 > 认证和代码示例 > 合约 > Websocket私有接口。
响应示例
Websocket订阅将持续实时更新当前订单。为简洁起见,以下仅提供上述Python订阅的初始响应:
{"biz":"futures","data":{"result":true},"channel":"subscribe","type":"order"}
{'biz': 'futures',
'pairCode': 'BTC',
'data': [{'currentPiece': '1',
'leverage': '1',
'originalType': 'plan',
'contractType': 1,
'fee': '0',
'frozenFee': '0.00954',
'orderStatus': 'unFinish',
'instrument': 'BTC',
'quantityUnit': 0,
'source': 'api',
'updatedDate': 1739955929000,
'positionModel': 0,
'posType': 'plan',
'baseSize': '0.001',
'liquidateBy': 'manual',
'makerFee': '0.0001',
'totalPiece': '1',
'orderPrice': '95400',
'id': '33308740320587027',
'direction': 'long',
'margin': '95.4',
'indexPrice': '95670.9',
'quantity': '100',
'takerFee': '0.0006',
'userId': '1162061',
'createdDate': 1739955929000,
'positionMargin': '95.4',
'status': 'open'}],
'type': 'order'}.....