查詢實時和終態委託單
主要用於實時查詢未成交或部分成交的訂單信息, 但結合入参openOnly能夠查詢到最近500條到達終態的訂單. 若需要查詢更久的訂單紀錄,請使用查詢歷史訂單接口.
提示
信息
- 經典帳戶現貨交易僅能查詢活動狀態的委託單
- 針對統一帳戶, 服務器重啓或發佈後請使用查詢歷史訂單接口去查詢已成交,取消和拒絕類型的訂單信息
HTTP請求
GET /v5/order/realtime
請求參數
| 參數 | 是否必需 | 類型 | 說明 |
|---|---|---|---|
| category | true | string | 產品類型 |
| symbol | false | string | 合約名稱symbol, baseCoin 和 settleCoin必傳其中一個 |
| baseCoin | false | string | 交易幣種linear, inverse和option |
| settleCoin | false | string | 結算幣種
|
| orderId | false | string | 訂單Id |
| orderLinkId | false | string | 用戶自定義訂單Id |
| openOnly | false | integer | |
| orderFilter | false | string | Order: 活動單StopOrder: 條件單, 支持現貨和期貨tpslOrder: 止盈止損單, 僅現貨有效OcoOrder: OCO訂單BidirectionalTpslOrder: 現貨(UTA)雙向止盈止損訂單
|
| limit | false | integer | 每頁數量限制. [1, 50]. 默認: 20 |
| cursor | false | string | 游標,用於翻頁 |
響應參數
| 參數 | 類型 | 說明 |
|---|---|---|
| category | string | 產品類型 |
| nextPageCursor | string | 游標,用於翻頁 |
| list | array | Object |
| > orderId | string | 訂單Id |
| > orderLinkId | string | 用戶自定義Id |
| > blockTradeId | string | Paradigm大宗交易Id |
| > symbol | string | 合約名稱 |
| > price | string | 訂單價格 |
| > qty | string | 訂單數量 |
| > side | string | 方向. Buy,Sell |
| > isLeverage | string | 是否借貸. 僅統一帳戶spot有效0: 否1: 是0 |
| > positionIdx | integer | 倉位標識。用戶不同倉位模式 |
| > orderStatus | string | 訂單狀態 |
| > createType | string | 訂單創建類型 |
| > cancelType | string | 訂單被取消類型 |
| > rejectReason | string | 拒絕原因. 經典帳戶現貨交易不支持 |
| > avgPrice | string | 訂單平均成交價格 """0", 以及部分成交但最終被手動取消的訂單 |
| > leavesQty | string | 訂單剩餘未成交的數量. 經典帳戶現貨交易不支持 |
| > leavesValue | string | 訂單剩餘未成交的價值. 經典帳戶現貨交易不支持 |
| > cumExecQty | string | 訂單累計成交數量 |
| > cumExecValue | string | 訂單累計成交價值. 經典帳戶現貨交易不支持 |
| > cumExecFee | string | 已棄用. 訂單累計成交的手續費. 經典帳戶現貨交易不支持 |
| > timeInForce | string | 執行策略 |
| > orderType | string | 訂單類型. Market,Limit. 對於止盈止損單, 則表示為觸發後的訂單類型 |
| > stopOrderType | string | 條件單類型 |
| > orderIv | string | 隱含波動率 |
| > marketUnit | string | 統一帳戶現貨交易時給入參qty選擇的單位. baseCoin, quoteCoin |
| > triggerPrice | string | 觸發價格. 若stopOrderType=TrailingStop, 則這是激活價格. 否則, 它是觸發價格 |
| > takeProfit | string | 止盈價格 |
| > stopLoss | string | 止損價格 |
| > tpslMode | string | 止盈止損模式 Full: 全部倉位止盈止損, Partial: 部分倉位止盈止損現貨不返回該字段, 期權總是返回"" |
| > ocoTriggerBy | string | 現貨OCO訂單的觸發類型.OcoTriggerByUnknown, OcoTriggerByTp, OcoTriggerBySl經典帳戶現貨不支持該字段 |
| > tpLimitPrice | string | 觸發止盈後轉換為限價單的價格 |
| > slLimitPrice | string | 觸發止損後轉換為限價單的價格 |
| > tpTriggerBy | string | 觸發止盈的價格類型 |
| > slTriggerBy | string | 觸發止損的價格類型 |
| > triggerDirection | integer | 觸發方向. 1: 上漲, 2: 下跌 |
| > triggerBy | string | 觸發價格的觸發類型 |
| > lastPriceOnCreated | string | 下單時的市場價格, 現貨不適用 |
| > basePrice | string | 下單時的市場價格, 僅現貨有這個字段 |
| > reduceOnly | boolean | 只減倉. true表明這是只減倉單 |
| > closeOnTrigger | boolean | 觸發後平倉委託. 什麼是觸發後平倉委託? |
| > placeType | string | 下單類型, 僅期權使用. iv, price |
| > smpType | string | SMP執行類型 |
| > smpGroup | integer | 所屬Smp組ID. 如果uid不屬於任何組, 則默認為0 |
| > smpOrderId | string | 觸發此SMP執行的交易對手的 orderID |
| > createdTime | string | 創建訂單的時間戳 (毫秒) |
| > updatedTime | string | 訂單更新的時間戳 (毫秒) |
| > cumFeeDetail | json | 累積交易費詳情, 替代cumExecFee |
請求示例
- HTTP
- Python
- Java
- Node.js
GET /v5/order/realtime?symbol=ETHUSDT&category=linear&openOnly=0&limit=1 HTTP/1.1
Host: api-testnet.bybit.com
X-BAPI-SIGN: XXXXX
X-BAPI-API-KEY: xxxxxxxxxxxxxxxxxx
X-BAPI-TIMESTAMP: 1672219525810
X-BAPI-RECV-WINDOW: 5000
Content-Type: application/json
from pybit.unified_trading import HTTP
session = HTTP(
testnet=True,
api_key="xxxxxxxxxxxxxxxxxx",
api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
)
print(session.get_open_orders(
category="linear",
symbol="ETHUSDT",
openOnly=0,
limit=1,
))
import com.bybit.api.client.config.BybitApiConfig;
import com.bybit.api.client.domain.trade.request.TradeOrderRequest;
import com.bybit.api.client.domain.*;
import com.bybit.api.client.domain.trade.*;
import com.bybit.api.client.service.BybitApiClientFactory;
var client = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET", BybitApiConfig.TESTNET_DOMAIN).newTradeRestClient();
var openLinearOrdersResult = client.getOpenOrders(openOrderRequest.category(CategoryType.LINEAR).openOnly(1).build());
System.out.println(openLinearOrdersResult);
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'xxxxxxxxxxxxxxxxxx',
secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
});
client
.getActiveOrders({
category: 'linear',
symbol: 'ETHUSDT',
openOnly: 0,
limit: 1,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
響應示例
{
"retCode": 0,
"retMsg": "OK",
"result": {
"list": [
{
"orderId": "fd4300ae-7847-404e-b947-b46980a4d140",
"orderLinkId": "test-000005",
"blockTradeId": "",
"symbol": "ETHUSDT",
"price": "1600.00",
"qty": "0.10",
"side": "Buy",
"isLeverage": "",
"positionIdx": 1,
"orderStatus": "New",
"cancelType": "UNKNOWN",
"rejectReason": "EC_NoError",
"avgPrice": "0",
"leavesQty": "0.10",
"leavesValue": "160",
"cumExecQty": "0.00",
"cumExecValue": "0",
"cumExecFee": "0",
"timeInForce": "GTC",
"orderType": "Limit",
"stopOrderType": "UNKNOWN",
"orderIv": "",
"triggerPrice": "0.00",
"takeProfit": "2500.00",
"stopLoss": "1500.00",
"tpTriggerBy": "LastPrice",
"slTriggerBy": "LastPrice",
"triggerDirection": 0,
"triggerBy": "UNKNOWN",
"lastPriceOnCreated": "",
"reduceOnly": false,
"closeOnTrigger": false,
"smpType": "None",
"smpGroup": 0,
"smpOrderId": "",
"tpslMode": "Full",
"tpLimitPrice": "",
"slLimitPrice": "",
"placeType": "",
"createdTime": "1684738540559",
"updatedTime": "1684738540561",
"cumFeeDetail": {
"MNT": "0.00242968"
}
}
],
"nextPageCursor": "page_args%3Dfd4300ae-7847-404e-b947-b46980a4d140%26symbol%3D6%26",
"category": "linear"
},
"retExtInfo": {},
"time": 1684765770483
}