撤銷委託單
重要
- 您必須指定
orderId
或者orderLinkId
. - 若
orderId
和orderLinkId
之間不匹配, 系統將會優先處理orderId
. - 您只能撤銷未成交和部分成交的訂單.
HTTP請求
POST /v5/order/cancel
請求參數
參數 | 是否必需 | 類型 | 說明 |
---|---|---|---|
category | true | string | 產品類型 |
symbol | true | string | 合約名稱 |
orderId | false | string | 訂單Id. orderId 和orderLinkId 必傳其中一個 |
orderLinkId | false | string | 用戶自定義訂單Id. orderId 和orderLinkId 必傳其中一個 |
orderFilter | false | string | 僅現貨交易有效Order : 普通單tpslOrder : 止盈止損單StopOrder : 條件單Order |
響應參數
參數 | 類型 | 說明 |
---|---|---|
orderId | string | 訂單Id |
orderLinkId | string | 用戶自定義訂單Id |
信息
ack僅表示請求被成功接受. 請使用websocket-order推送來確認訂單狀態
請求示例
- HTTP
- Python
- Java
- .Net
- Node.js
POST /v5/order/cancel HTTP/1.1
Host: api-testnet.bybit.com
X-BAPI-SIGN: XXXXX
X-BAPI-API-KEY: XXXXX
X-BAPI-TIMESTAMP: 1672217376681
X-BAPI-RECV-WINDOW: 5000
Content-Type: application/json
{
"category": "linear",
"symbol": "BTCPERP",
"orderLinkId": null,
"orderId":"c6f055d9-7f21-4079-913d-e6523a9cfffa"
}
from pybit.unified_trading import HTTP
session = HTTP(
testnet=True,
api_key="XXXXX",
api_secret="XXXXX",
)
print(session.cancel_order(
category="linear",
symbol="BTCPERP",
orderId="c6f055d9-7f21-4079-913d-e6523a9cfffa",
))
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 cancelOrderRequest = TradeOrderRequest.builder().category(ProductType.SPOT).symbol("XRPUSDT").orderId("1523347543495541248").build();
var canceledOrder = client.cancelOrder(cancelOrderRequest);
System.out.println(canceledOrder);
using bybit.net.api.ApiServiceImp;
using bybit.net.api.Models.Trade;
BybitTradeService tradeService = new(apiKey: "xxxxxxxxxxxxxx", apiSecret: "xxxxxxxxxxxxxxxxxxxxx");
var orderInfoString = await TradeService.CancelOrder(orderId: "1523347543495541248", category: Category.SPOT, symbol: "XRPUSDT");
Console.WriteLine(orderInfoString);
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.cancelOrder({
category: 'linear',
symbol: 'BTCPERP',
orderId: 'c6f055d9-7f21-4079-913d-e6523a9cfffa',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
響應示例
{
"retCode": 0,
"retMsg": "OK",
"result": {
"orderId": "c6f055d9-7f21-4079-913d-e6523a9cfffa",
"orderLinkId": "linear-004"
},
"retExtInfo": {},
"time": 1672217377164
}