批量創建委託單
提示
該接口支持批量創建委託單
- 下單時需確保帳戶內有足夠的資金。一旦下單,根據訂單所需資金,您的帳戶資金將在訂單生命週期內凍結相應額度,被凍結的資金額度取決於訂單屬性。
- 每個請求包含的訂單數最大是: 20筆(期权), 10筆(反向合約), 10筆(正向合約), 10筆(現貨), 返回的數據列表中分成兩個list,訂單創建的列表和創建結果的信息返回,兩個list的訂單的序列是完全保持一致的。
信息
期權批量接口頻率規則: 期權是按照實際發送的請求次數來統計頻率的, 因此如果帳戶頻率是10次/秒, 每次請求發送20筆訂單, 則可以每秒發送200筆訂單;
期貨和現貨的批量接口頻率規則: 請從這裡查閱其API限頻說明
風控限制提示:
Bybit 將針對您的 API 請求進行統計監控,當單日 (UTC 0点 - UTC 24点) 單帳號(母帳號和子帳號整體運算)訂單總数超過一定上限,平台將保留提醒、警告,以及進行必要性限制的權利。 使用API的客戶預設接受本條款並負有配合調整的義務。
HTTP請求
POST /v5/order/create-batch
請求參數
參數 | 是否必需 | 類型 | 說明 |
---|---|---|---|
category | true | string | 產品類型linear , option , spot , inverse linear , option , spot |
request | true | array | Object |
> symbol | true | string | 合約名稱 |
> isLeverage | false | integer | 是否借貸. 僅統一帳戶的現貨交易有效. 0 (default): 否,則是幣幣訂單, 1 : 是,則是槓桿訂單 |
> side | true | string | 方向. Buy , Sell |
> orderType | true | string | 訂單類型. Market , Limit |
> qty | true | string | 訂單數量 訂單數量
|
> price | false | string | 訂單價格
|
> marketUnit | false | string | 統一帳戶現貨交易創建市價單時給入參qty 指定的單位, 支持orderFilter=Order, tpslOrder 和 StopOrderbaseCoin : 比如, 買BTCUSDT, 則"qty"的單位是BTCquoteCoin : 比如, 賣BTCUSDT, 則"qty"的單位是USDT |
> triggerDirection | false | integer | 條件單參數. 用於辨別期望的方向.
linear 有效 |
> orderFilter | false | string | 指定訂單品種, 若不傳, 默認Order Order : 普通單tpslOrder : 止盈止損單StopOrder : 條件單 |
> triggerPrice | false | string |
|
> triggerBy | false | string | 條件單參數. 觸發價格類型. LastPrice , IndexPrice , MarkPrice 僅 linear 有效 |
> orderIv | false | string | 隱含波動率. 僅option 有效. 按照實際值傳入, e.g., 對於10%, 則傳入0.1. orderIv 比price 有更高的優先級 |
> timeInForce | false | string | 訂單執行策略
|
> positionIdx | false | integer | 倉位標識, 用戶不同倉位模式. 該字段對於雙向持倉模式是必傳:
|
> orderLinkId | false | string | 用戶自定義訂單Id. category=option 時,該參數必傳 |
> takeProfit | false | string | 止盈價格 |
> stopLoss | false | string | 止損價格 |
> tpTriggerBy | false | string | 觸發止盈的價格類型 MarkPrice IndexPrice LastPrice (默認)僅對 linear 和inverse 有效 |
> slTriggerBy | false | string | 觸發止損的價格類型 MarkPrice IndexPrice LastPrice (默認)僅對 linear 和inverse 有效 |
> reduceOnly | false | boolean | 什麼是只減倉? true 將這筆訂單設為只減倉
|
> closeOnTrigger | false | boolean | 什麼是觸發後平倉委託?此選項可以確保您的止損單被用於減倉(平倉)而非加倉,並且在可用保證金不足的情況下,取消其他委託,騰出保證金以確保平倉委託的執行.linear , inverse 有效 |
> smpType | false | string | Smp執行類型. 什麼是SMP? |
> mmp | false | boolean | 做市商保護. 僅option 有效. true 表示該訂單是做市商保護訂單. 什麼是做市商保護? |
> tpslMode | false | string | 止盈止損模式
linear , inverse 有效 |
> tpLimitPrice | false | string | 觸發止盈後轉換為限價單的價格
|
> slLimitPrice | false | string | 觸發止損後轉換為限價單的價格
|
> tpOrderType | false | string | 止盈觸發後的訂單類型
Market (默認), Limit 對於tpslMode=Full, 僅支持tpOrderType=Market |
> slOrderType | false | string | 止損觸發後的訂單類型
|
響應參數
參數 | 類型 | 說明 |
---|---|---|
result | Object | |
> list | array | Object |
>> category | string | 產品類型 |
>> symbol | string | 合約名稱 |
>> orderId | string | 訂單Id |
>> orderLinkId | string | 用戶自定義訂單Id |
>> createAt | string | 訂單創建時間 (毫秒) |
retExtInfo | Object | |
> list | array | Object |
>> code | number | 成功/錯誤碼 |
>> msg | string | 成功/錯誤消息 |
信息
ack僅表示請求被成功接受. 請使用websocket-order推送來確認訂單狀態
請求示例
- HTTP
- Python
- Go
- Java
- .Net
- Node.js
POST /v5/order/create-batch HTTP/1.1
Host: api-testnet.bybit.com
X-BAPI-SIGN: XXXXX
X-BAPI-API-KEY: XXXXX
X-BAPI-TIMESTAMP: 1672222064519
X-BAPI-RECV-WINDOW: 5000
Content-Type: application/json
{
"category": "spot",
"request": [
{
"symbol": "BTCUSDT",
"side": "Buy",
"orderType": "Limit",
"isLeverage": 0,
"qty": "0.05",
"price": "30000",
"timeInForce": "GTC",
"orderLinkId": "spot-btc-03"
},
{
"symbol": "ATOMUSDT",
"side": "Sell",
"orderType": "Limit",
"isLeverage": 0,
"qty": "2",
"price": "12",
"timeInForce": "GTC",
"orderLinkId": "spot-atom-03"
}
]
}
from pybit.unified_trading import HTTP
session = HTTP(
testnet=True,
api_key="XXXXX",
api_secret="XXXXX",
)
print(session.place_batch_order(
category="spot",
request=[
{
"symbol": "BTCUSDT",
"side": "Buy",
"orderType": "Limit",
"isLeverage": 0,
"qty": "0.05",
"price": "30000",
"timeInForce": "GTC",
"orderLinkId": "spot-btc-03"
},
{
"symbol": "ATOMUSDT",
"side": "Sell",
"orderType": "Limit",
"isLeverage": 0,
"qty": "2",
"price": "12",
"timeInForce": "GTC",
"orderLinkId": "spot-atom-03"
}
]
))
import (
"context"
"fmt"
bybit "https://github.com/bybit-exchange/bybit.go.api")
client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "spot",
"request": []map[string]interface{}{
{
"symbol": "BTCUSDT",
"side": "Buy",
"orderType": "Limit",
"isLeverage": 0,
"qty": "0.05",
"price": "30000",
"timeInForce": "GTC",
"orderLinkId": "spot-btc-03"
},
{
"symbol": "ATOMUSDT",
"side": "Sell",
"orderType": "Limit",
"isLeverage": 0,
"qty": "2",
"price": "12",
"timeInForce": "GTC",
"orderLinkId": "spot-atom-03"
},
},
}
client.NewUtaBybitServiceWithParams(params).PlaceBatchOrder(context.Background())
import com.bybit.api.client.restApi.BybitApiAsyncTradeRestClient;
import com.bybit.api.client.domain.ProductType;
import com.bybit.api.client.domain.TradeOrderType;
import com.bybit.api.client.domain.trade.*;
import com.bybit.api.client.service.BybitApiClientFactory;
import java.util.Arrays;
BybitApiClientFactory factory = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET");
BybitApiAsyncTradeRestClient client = factory.newAsyncTradeRestClient();
var orderRequests = Arrays.asList(TradeOrderRequest.builder().category(ProductType.OPTION).symbol("BTC-10FEB23-24000-C").side(Side.BUY).orderType(TradeOrderType.LIMIT).qty("0.1")
.price("5").orderIv("0.1").timeInForce(TimeInForce.GOOD_TILL_CANCEL).orderLinkId("9b381bb1-401").mmp(false).reduceOnly(false).build(),
TradeOrderRequest.builder().category(ProductType.OPTION).symbol("BTC-10FEB23-24000-C").side(Side.BUY).orderType(TradeOrderType.LIMIT).qty("0.1")
.price("5").orderIv("0.1").timeInForce(TimeInForce.GOOD_TILL_CANCEL).orderLinkId("82ee86dd-001").mmp(false).reduceOnly(false).build());
var createBatchOrders = BatchOrderRequest.builder().category(ProductType.OPTION).request(orderRequests).build();
client.createBatchOrder(createBatchOrders, System.out::println);
using bybit.net.api.ApiServiceImp;
using bybit.net.api.Models.Trade;
var order1 = new OrderRequest { Symbol = "XRPUSDT", OrderType = "Limit", Side = "Buy", Qty = "10", Price = "0.6080", TimeInForce = "GTC" };
var order2 = new OrderRequest { Symbol = "BLZUSDT", OrderType = "Limit", Side = "Buy", Qty = "10", Price = "0.6080", TimeInForce = "GTC" };
List<OrderRequest> request = new() { order1, order2 };
var orderInfoString = await TradeService.PlaceBatchOrder(category: Category.LINEAR, request: request);
Console.WriteLine(orderInfoString);
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'apikey',
secret: 'apisecret',
});
client
.batchSubmitOrders('spot', [
{
"symbol": "BTCUSDT",
"side": "Buy",
"orderType": "Limit",
"isLeverage": 0,
"qty": "0.05",
"price": "30000",
"timeInForce": "GTC",
"orderLinkId": "spot-btc-03"
},
{
"symbol": "ATOMUSDT",
"side": "Sell",
"orderType": "Limit",
"isLeverage": 0,
"qty": "2",
"price": "12",
"timeInForce": "GTC",
"orderLinkId": "spot-atom-03"
},
])
.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",
"createAt": "1713434102752"
},
{
"category": "spot",
"symbol": "ATOMUSDT",
"orderId": "1666800494330512129",
"orderLinkId": "spot-atom-03",
"createAt": "1713434102752"
}
]
},
"retExtInfo": {
"list": [
{
"code": 0,
"msg": "OK"
},
{
"code": 0,
"msg": "OK"
}
]
},
"time": 1713434102753
}