批量撤銷委託單
該接口可以批量撤銷多筆訂單
重要
- 您必須指定
orderId
或者orderLinkId
. - 若
orderId
和orderLinkId
之間不匹配, 系統將會優先處理orderId
. - 您只能撤銷未成交和部分成交的訂單.
- 最多支持單個請求中撤銷, 期權: 20個訂單, 反向合約: 10個訂單, 正向合約: 10个訂單, 現貨: 10個訂單.
HTTP請求
POST /v5/order/cancel-batch
請求參數
參數 | 是否必需 | 類型 | 說明 |
---|---|---|---|
category | true | string | 產品類型linear , option , spot , inverse linear , option , spot |
request | true | array | Object |
> symbol | true | string | 合約名稱 |
> orderId | false | string | 訂單Id. orderId 和orderLinkId 必傳其中一個 |
> orderLinkId | false | string | 用戶自定義訂單Id. orderId 和orderLinkId 必傳其中一個 |
響應參數
參數 | 類型 | 說明 |
---|---|---|
result | Object | |
> list | array | Object |
>> category | string | 產品類型 |
>> symbol | string | 合約名稱 |
>> orderId | string | 訂單Id |
>> orderLinkId | string | 用戶自定義訂單Id |
retExtInfo | Object | |
> list | array | Object |
>> code | number | 成功/錯誤碼 |
>> msg | string | 成功/錯誤信息 |
信息
ack僅表示請求被成功接受. 請使用websocket-order推送來確認訂單狀態
請求示例
- HTTP
- Python
- Java
- .Net
- Node.js
POST /v5/order/cancel-batch HTTP/1.1
Host: api-testnet.bybit.com
X-BAPI-SIGN: XXXXX
X-BAPI-API-KEY: XXXXX
X-BAPI-TIMESTAMP: 1672223356634
X-BAPI-RECV-WINDOW: 5000
Content-Type: application/json
{
"category": "spot",
"request": [
{
"symbol": "BTCUSDT",
"orderId": "1666800494330512128"
},
{
"symbol": "ATOMUSDT",
"orderLinkId": "1666800494330512129"
}
]
}
from pybit.unified_trading import HTTP
session = HTTP(
testnet=True,
api_key="XXXXX",
api_secret="XXXXX",
)
print(session.cancel_batch_order(
category="spot",
request=[
{
"symbol": "BTCUSDT",
"orderId": "1666800494330512128"
},
{
"symbol": "ATOMUSDT",
"orderLinkId": "1666800494330512129"
}
]
))
import com.bybit.api.client.restApi.BybitApiTradeRestClient;
import com.bybit.api.client.domain.*;
import com.bybit.api.client.domain.trade.*;
import com.bybit.api.client.service.BybitApiClientFactory;
BybitApiClientFactory factory = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET");
BybitApiAsyncTradeRestClient client = factory.newAsyncTradeRestClient();
var cancelOrderRequests = Arrays.asList(TradeOrderRequest.builder().symbol("BTC-10FEB23-24000-C").orderLinkId("9b381bb1-401").build(),
TradeOrderRequest.builder().symbol("BTC-10FEB23-24000-C").orderLinkId("82ee86dd-001").build());
var cancelBatchOrders = BatchOrderRequest.builder().category(ProductType.OPTION).request(cancelOrderRequests).build();
client.createBatchOrder(cancelBatchOrders, System.out::println);
using bybit.net.api.ApiServiceImp;
using bybit.net.api.Models.Trade;
var order1 = new OrderRequest { Symbol = "BTC-10FEB23-24000-C", OrderLinkId = "9b381bb1-401" };
var order2 = new OrderRequest { Symbol = "BTC-10FEB23-24000-C", OrderLinkId = "82ee86dd-001" };
var orderInfoString = await TradeService.CancelBatchOrder(category: Category.LINEAR, request: new List<OrderRequest> { order1, order2 });
Console.WriteLine(orderInfoString);
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.batchCancelOrders('spot', [
{
"symbol": "BTCUSDT",
"orderId": "1666800494330512128"
},
{
"symbol": "ATOMUSDT",
"orderLinkId": "1666800494330512129"
},
])
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
響應示例
{
"retCode": 0,
"retMsg": "OK",
"result": {
"list": [
{
"category": "spot",
"symbol": "BTCUSDT",
"orderId": "1666800494330512128",
"orderLinkId": "spot-btc-03"
},
{
"category": "spot",
"symbol": "ATOMUSDT",
"orderId": "",
"orderLinkId": "1666800494330512129"
}
]
},
"retExtInfo": {
"list": [
{
"code": 0,
"msg": "OK"
},
{
"code": 170213,
"msg": "Order does not exist."
}
]
},
"time": 1713434299047
}