获取所有当前持仓
API说明
此接口允许用户查询所有当前开仓持仓(已成交订单)。
注意:当前持仓数据可通过RESTful和Websocket接口获取。本页是RESTful接口的描述。如需了解Websocket接口,请参见 跳转
注意事项
- 该接口与“市价平仓”接口在URL结构上较为相似,用户应仔细区分以确保采用正确的请求方法,避免因混淆导致非预期操作或数据异常。
认证
这是一个私有接口,需要认证。有关使用RESTful API的详细信息,请参考公共 > 认证和代码示例 > 合约 > RESTful私有接口。
请求方法
GET
接口地址
频率限制
该接口的调用频率限制为每个用户 ID 每秒 30 个请求,每个 IP 每2秒 100000 个请求。
此外,该接口还受到全局频率限制的约束。
有关"全局速率限制"和"API限频策略"的详细信息,请参阅“频率限制”部分,跳转
请求参数
无
响应参数
| 参数 | 类型 | 描述 |
|---|---|---|
| id | Long | 持仓ID |
| base | String | 交易品种基础货币,例如btc |
| baseSize | BigDecimal | 合约面值 |
| createdDate | Long | 持仓创建时间戳 |
| currentPiece | BigDecimal | 当前持仓张数 |
| closedPiece | Integer | 已平仓合约数量 |
| direction | String | 交易方向:做多(long)/做空(short) |
| fee | BigDecimal | 资金费 |
| fundingSettle | BigDecimal | 已结算资金费 |
| indexPrice | BigDecimal | 触发时的指数价格 |
| instrument | String | 交易品种标识,例如 BTC(USDT 合约)或 BTC_USDC(USDC 合约) |
| leverage | BigDecimal | 持仓杠杆率 |
| margin | BigDecimal | 持仓使用的保证金 |
| orderPrice | BigDecimal | 订单执行价格 |
| openPrice | BigDecimal | 持仓开仓价格 |
| originalType | String | 原始订单类型 |
| posType | String | 订单执行时的持仓类型:plan/planTrigger/execute |
| positionMargin | BigDecimal | 持仓保证金 |
| positionModel | Integer | 仓位模式:0:逐仓,1:全仓 |
| quantity | String | 基于quantityUnit 指定订单数量: 当 quantityUnit = 0 时,数量以计价货币计量(例如,BTC-USDT 中的 USDT / BTC-USDC 中的 USDC); 当 quantityUnit = 1 时,数量以合约张数计量; 当 quantityUnit = 2 时,数量以基础货币计量(例如,BTC-USDT 中的 BTC)。 |
| quantityUnit | BigDecimal | 用于指定订单数量的计量单位: 0:以计价货币计价(例如,BTC-USDT 合约中的 USDT / BTC-USDC 合约中的 USDC); 1:以合约张数计价; 2:以基础货币计价(例如,BTC-USDT 合约中的 BTC)。 |
| status | String | 状态:(open/close) |
| totalPiece | BigDecimal | 合约总张数 |
| updatedDate | String | 最后更新时间戳 |
| userId | Long | 用户ID |
| autoDeleveragingScore | Integer | (用户可忽略) |
| profitUnreal | Float | 当前持仓的未实现盈亏 |
| liquidationPrice | Float | 强平价格 |
| triggerType | Integer | 指定"triggerPrice"满足时的订单类型:0:限价单,1:市价单 |
| triggerPrice | BigDecimal | 永续合约计划订单的触发价格 |
请求示例
以下Python代码展示了如何获取所有当前开仓持仓信息。
注意:完整代码示例请参考公共 > 认证和代码示例 > 合约 > RESTful私有接口。
params = {}
api_url = "/v1/perpum/positions/all"
method = "GET"
response_code, response_data = FuturesRestfulPrivate(params, api_url, method, sec_key, api_key) # function FuturesRestfulPrivate() is defined in section (Common > Authentication & Code Snippet > Futures > RESTful Private Interface)
注意:完整Java代码示例请参考公共 > 认证和代码示例 > 合约 > RESTful私有接 口。
响应示例
以下是上述Python请求返回的示例响应:
{'code': 0,
'data': [{'autoDeleveragingScore': 1,
'base': 'sand',
'baseSize': 10.0,
'closedPiece': 0,
'createdDate': 1751972973000,
'currentPiece': 1,
'direction': 'long',
'fee': '0.0014',
'fundingFee': '0',
'fundingSettle': 0,
'id': 2435521222635399738,
'indexPrice': 0.24477,
'instrument': 'SAND',
'leverage': 2,
'liquidationPrice': 0.123594777082913,
'margin': 1.2223,
'openPrice': 0.24477,
'orderPrice': 2147483647,
'originalType': 'execute',
'posType': 'execute',
'positionMargin': 1.22385,
'positionModel': 0,
'positionVersion': 0,
'profitReal': 0,
'profitUnreal': 0.0001,
'quantity': 1.22385,
'quantityUnit': 1,
'source': 'web',
'status': 'open',
'totalPiece': 1,
'updatedDate': 1751972973000,
'userId': 1162061},
{'autoDeleveragingScore': 1,
'base': 'btc',
'baseSize': 0.001,
'closedPiece': 0,
'createdDate': 1751973010000,
'currentPiece': 1,
'direction': 'short',
'fee': '0.0652',
'fundingFee': '0',
'fundingSettle': 0,
'id': 2435521222635399758,
'indexPrice': 108828,
'instrument': 'BTC',
'leverage': 2,
'liquidationPrice': 162591.22485053807,
'margin': 54.3486,
'openPrice': 108827.9,
'orderPrice': 0,
'originalType': 'execute',
'posType': 'execute',
'positionMargin': 54.41395,
'positionModel': 0,
'positionVersion': 0,
'profitReal': 0,
'profitUnreal': -0.0002,
'quantity': 54.41395,
'quantityUnit': 1,
'source': 'web',
'status': 'open',
'totalPiece': 1,
'updatedDate': 1751973010000,
'userId': 1162061}],
'msg': ''}