跳到主要内容

获取所有当前持仓

API说明

此接口允许用户查询所有当前开仓持仓(已成交订单)。

注意:当前持仓数据可通过RESTful和Websocket接口获取。本页是RESTful接口的描述。如需了解Websocket接口,请参见 跳转

注意事项

  1. 该接口与“市价平仓”接口在URL结构上较为相似,用户应仔细区分以确保采用正确的请求方法,避免因混淆导致非预期操作或数据异常。

认证

这是一个私有接口,需要认证。有关使用RESTful API的详细信息,请参考简介 > 认证和代码示例 > 合约 > RESTful私有接口。

请求方法

GET

接口地址

v1/perpum/positions/all

频率限制

该接口的调用频率限制为每个用户 ID 每秒 30 个请求,每个 IP 每2秒 100000 个请求。 此外,该接口还受到全局频率限制的约束。
有关"全局速率限制"和"API限频策略"的详细信息,请参阅“频率限制”部分,跳转

请求参数

响应参数

参数类型描述
idLong持仓ID
baseString交易品种基础货币,例如btc
baseSizeBigDecimal合约面值
createdDateLong持仓创建时间戳
currentPieceBigDecimal当前持仓张数
closedPieceInteger已平仓合约数量
directionString交易方向:做多(long)/做空(short)
feeBigDecimal资金费
fundingSettleBigDecimal已结算资金费
indexPriceBigDecimal触发时的指数价格
instrumentString交易品种的基础货币,例如BTC或ETH
leverageBigDecimal持仓杠杆率
marginBigDecimal持仓使用的保证金
orderPriceBigDecimal订单执行价格
openPriceBigDecimal持仓开仓价格
originalTypeString原始订单类型
posTypeString订单执行时的持仓类型:plan/planTrigger/execute
positionMarginBigDecimal持仓保证金
positionModelInteger仓位模式:0:逐仓,1:全仓
quantityString基于quantityUnit 指定订单数量:
当 quantityUnit = 0 时,数量以计价货币计量(例如,BTC-USDT 中的 USDT);
当 quantityUnit = 1 时,数量以合约张数计量;
当 quantityUnit = 2 时,数量以基础货币计量(例如,BTC-USDT 中的 BTC)。
quantityUnitBigDecimal用于指定订单数量的计量单位:
0:以计价货币计价(例如,BTC-USDT 合约中的 USDT);
1:以合约张数计价;
2:以基础货币计价(例如,BTC-USDT 合约中的 BTC)。
statusString状态:(open/close)
totalPieceBigDecimal合约总张数
updatedDateString最后更新时间戳
userIdLong用户ID
autoDeleveragingScoreInteger(用户可忽略)
profitUnrealFloat当前持仓的未实现盈亏
liquidationPriceFloat强平价格
triggerTypeInteger指定"triggerPrice"满足时的订单类型:0:限价单,1:市价单
triggerPriceBigDecimal永续合约计划订单的触发价格

请求示例

以下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 (General Information > Authentication and 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': ''}