获取批量历史订单(3个月)
API说明
该接口返回过去三个月的历史订单记录,并支持通过“symbols”参数进行批量查询。用户可通过页码、每页数量和订单类型进行筛选。返回结果包含订单状态、保证金、杠杆以及订单数量等关键订单信息。
注 意: 批量历史订单数据只能通过 RESTful API 获取。
注意事项
- 此接口仅返回已执行(即已进入交易)的订单。
认证
这是一个私有接口,需要认证。有关使用RESTful API的详细信息,请参考简介 > 认证和代码示例 > 合约 > RESTful私有接口。
请求方法
GET
接口地址
/v1/perpum/orders/batchInsArchive
频率限制
该接口的调用频率限制为:每个 IP 和用户 ID 每1秒最多请求1次。
此外,该接口还受到全局频率限制的约束。
有关"全局速率限制"和"API限频策略"的详细信息,请参阅“频率限制”部分,跳转
请求参数
| 参数 | 必填 | 类型 | 描述 |
|---|---|---|---|
| page | false | Integer | 当前页码, 默认值:500 |
| pageSize | false | Integer | 每页结果数。默认值:500 注意:订单数量上限为 500 笔 |
| originType | true | String | 初始订单类型:plan/planTrigger/execute execute:市价单 plan:用于不同计划订单,包括限价单、触发限价单、带SL/TP的限价单、带SL/TP的触发限价单、触发市价单、带SL/TP的触发市价单 planTrigger:计划触发订单 |
| symbols | true | String | 使用逗号分隔的基础币种简称来指定多个交易品种。 例如:"BTC,ETH,1000PEPE" 注意:USDT 合约只需传入基础货币名称,如 BTCUSDT 传 BTC 即可。单次请求最多允许指定20个交易品种。 |
响应参数
| 参数 | 类型 | 描述 |
|---|---|---|
| userId | Long | 合约账户用户ID |
| baseSize | BigDecimal | 基础货币订单规模 |
| completeUsdt | BigDecimal | USDT交易金额 |
| createdDate | Long | 订单创建的时间戳 |
| currentPiece | BigDecimal | 当前持有的合约数量 |
| direction | String | 交易方向:做多(long)/做空(short) |
| entrustUsdt | BigDecimal | USDT订单规模 |
| havShortfall | Boolean | 表示用户是否有清算风险 |
| hedgeId | Long | 关联对冲ID |
| indexPrice | BigDecimal | 指数价格/最新价格 |
| instrument | String | 交易品种的基础货币,例如BTC或ETH |
| leverage | BigDecimal | 持仓杠杆率 |
| liquidateBy | String | 开仓和平仓事件类型:Manual |
| margin | BigDecimal | 持仓使用的保证金 |
| openId | Long | 持仓ID |
| orderId | Long | ID(用户可忽略) |
| orderPrice | BigDecimal | 用户设置的订单价格。注意:市价单情况下忽略 |
| orderStatus | String | 订单状态:unFinish:未成交part:部分成交Finish:完全成交Cancel:已取消 |
| originalType | String | 原始订单类型 |
| posType | String | 持仓类型:plan/planTrigger/execute |
| positionModel | Integer | 持仓模式:0:逐仓,1:全仓 |
| quantity | BigDecimal | 基于quantityUnit 指定订单数量: 当 quantityUnit = 0 时,数量以计价货币计量(例如,BTC-USDT 中的 USDT); 当 quantityUnit = 1 时,数量以合约张数计量; 当 quantityUnit = 2 时,数量以基础货币计量(例如,BTC-USDT 中的 BTC)。 |
| quantityUnit | Integer | 用于指定订单数量的计量单位: 0:以计价货币计价(例如,BTC-USDT 合约中的 USDT); 1:以合约张数计价; 2:以基础货币计价(例如,BTC-USDT 合约中的 BTC)。 |
| status | String | 状态:open/close |
| totalPiece | String | 合约总数量 |
| updatedDate | Date | 最新交易更新的时间戳 |
| thirdOrderId | String | 自定义订单ID |
| tradePiece | Integer | 要交易的合约 |
| stepMarginVersion | Integer | (用户可忽略) |
| id | Long | 订单ID |
| cancelPiece | Integer | 取消的合约数量 |
| contractType | Integer | 合约类型:1:U本位永续合约 |
| source | String | 来源:web/api |
| avgPrice | String | 平均成交价格 |
| triggerPrice | String | 永续合约计划订单的触发价格 |
| triggerType | Integer | 指定触发价格满足时的订单类型:0:限价单,1:市价单 |
| thirdOrderId | String | 用户分配的自定义订单ID |
请求示例
以下Python代码展示了如何获取过去三个月的历史订单记录。
注意:完整代码示例请参考简介 > 认证和代码示例 > 合约 > RESTful私有接口。
params = {
"page" : 1,
"pageSize" : 5,
"originType" : "execute",
"symbols" : "BTC,ETH,XRP",
}
api_url = "/v1/perpum/orders/batchInsArchive"
method = "GET"
response_code, response_data = FuturesRestfulPrivate(params, api_url, method, sec_key, api_key) # 函数FuturesRestuflPrivate()在章节 (简介 > 认证和代码示例 > 合约 > RESTful私有接口)
注意:完整Java代码示例请参考简介 > 认证和代码示例 > 合约 > RESTful私有接口。
响应示例
以下是上述Python请求返回的示例响应。该响应包含过去三个月内5个订单。为简洁起见,下面仅显示三个订单:
{'code': 0,
'data':
{'nextId': 0,
'prevId': 0,
'rows':
[{'avgPrice': '3027.94',
'base': 'eth',
'baseSize': '0',
'cancelPiece': 0,
'completeUsdt': '60.5588',
'contractType': 1,
'createdDate': 1763452322000,
'currentPiece': '2',
'direction': 'long',
'entrustUsdt': '60.5588',
'fee': 0.03633528,
'finalOrderStatus': 'finish',
'havShortfall': False,
'hedgeId': 23765440242368518,
'id': '33309107055452107',
'indexPrice': '3027.92',
'instrument': 'ETH',
'leverage': '3',
'liquidateBy': 'manual',
'margin': '0.030279400000002',
'openId': 2435521222639519743,
'orderId': 2776199686,
'orderPrice': '2147483647',
'orderStatus': 'finish',
'originalType': 'execute',
'posType': 'execute',
'positionModel': 0,
'quantity': '2',
'quantityUnit': 1,
'quote': 'usdt',
'source': 'web',
'status': 'open',
'stepMarginVersion': 0,
'thirdOrderId': '',
'totalPiece': '2',
'tradePiece': 2,
'updatedDate': 1763452322000,
'userId': 1162061},
{'avgPrice': '2.1602',
'base': 'xrp',
'baseSize': '0',
'cancelPiece': 0,
'completeUsdt': '21.602',
'contractType': 1,
'createdDate': 1763452306000,
'currentPiece': '1',
'direction': 'long',
'entrustUsdt': '21.602',
'fee': 0.0129612,
'finalOrderStatus': 'finish',
'havShortfall': False,
'hedgeId': 23765438112317446,
'id': '33309107055004625',
'indexPrice': '2.1603',
'instrument': 'XRP',
'leverage': '50',
'liquidateBy': 'manual',
'margin': '0.4328',
'openId': 2435521222639519647,
'orderId': 1760048126,
'orderPrice': '0',
'orderStatus': 'finish',
'originalType': 'execute',
'posType': 'execute',
'positionModel': 0,
'quantity': '0.4328',
'quantityUnit': 1,
'quote': 'usdt',
'source': 'web',
'status': 'close',
'stepMarginVersion': 0,
'thirdOrderId': '',
'totalPiece': '1',
'tradePiece': 1,
'updatedDate': 1763452306000,
'userId': 1162061}, .........
{'avgPrice': '104411.5',
'base': 'btc',
'baseSize': '0',
'cancelPiece': 0,
'completeUsdt': '626.469',
'contractType': 1,
'createdDate': 1762867068000,
'currentPiece': '6',
'direction': 'short',
'entrustUsdt': '626.469',
'fee': 0.3758814,
'finalOrderStatus': 'finish',
'havShortfall': False,
'hedgeId': 23688729854065670,
'id': '33309091808516140',
'indexPrice': '104410.3',
'instrument': 'BTC',
'leverage': '13',
'liquidateBy': 'manual',
'margin': '1.8100769230769376',
'openId': 2435521222639289274,
'orderId': 3060259335,
'orderPrice': '0',
'orderStatus': 'finish',
'originalType': 'execute',
'posType': 'execute',
'positionModel': 0,
'quantity': '50',
'quantityUnit': 0,
'quote': 'usdt',
'source': 'web', '
status': 'open',
'stepMarginVersion': 0,
'thirdOrderId': '',
'totalPiece': '6',
'tradePiece': 6,
'updatedDate': 1762867068000,
'userId': 1162061}],
'total': 27},
'msg': ''}