Skip to main content

Batch New Orders

Description

Batch create and submit new orders. Maximum 5 orders per request.

caution

This endpoint is currently available on Testnet only and returns 405 on the production API.

HTTP Request

POST /fapi/v1/batchOrders (HMAC SHA256)

Weight

5

Request Parameters

NameTypeRequiredDescription
batchOrdersJSON LISTYESOrder list, containing up to 5 order objects
timestampLONGYESTimestamp

Each order object contains the following parameters:

NameTypeRequiredDescription
symbolSTRINGYESTrading pair
sideENUMYESOrder side: BUY, SELL
typeENUMYESOrder type
quantityDECIMALYESOrder quantity
priceDECIMALNOOrder price
stopPriceDECIMALNOStop price
timeInForceENUMNOTime in force
reduceOnlySTRINGNOtrue or false
positionSideENUMNOPosition side
workingTypeENUMNOWorking type

Response Example

[
{
"clientOrderId": "testOrderBatch1",
"cumQty": "0",
"cumQuote": "0",
"executedQty": "0",
"orderId": 2254222045,
"avgPrice": "0.00000",
"origQty": "10",
"price": "0",
"reduceOnly": false,
"side": "SELL",
"positionSide": "BOTH",
"status": "NEW",
"stopPrice": "0",
"closePosition": false,
"symbol": "BTCUSDT",
"timeInForce": "GTC",
"type": "TRAILING_STOP_MARKET",
"origType": "TRAILING_STOP_MARKET",
"activatePrice": "9020",
"priceRate": "0.3",
"updateTime": 1566818724722,
"workingType": "CONTRACT_PRICE",
"priceProtect": false
},
{
"code": -2010,
"msg": "Account has insufficient balance for requested action."
}
]

The response is a list where each element corresponds to an order in the request. If an order fails to create, the corresponding element will contain an error code and error message.

Code Examples

cURL

API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
BATCH='[{"symbol":"BTCUSDT","side":"BUY","type":"LIMIT","timeInForce":"GTC","quantity":"0.01","price":"60000"},{"symbol":"BTCUSDT","side":"SELL","type":"LIMIT","timeInForce":"GTC","quantity":"0.01","price":"80000"}]'
QUERY_STRING="batchOrders=${BATCH}&timestamp=${TIMESTAMP}"
SIGNATURE=$(echo -n "${QUERY_STRING}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')

curl -s -X POST \
-H "X-MBX-APIKEY: ${API_KEY}" \
"https://api-sepolia.ztdx.io/fapi/v1/batchOrders?${QUERY_STRING}&signature=${SIGNATURE}"

Python

import time, hmac, hashlib, requests, json
from urllib.parse import quote

API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL = "https://api.ztdx.io"

def sign(msg: str) -> str:
return hmac.new(API_SECRET.encode(), msg.encode(), hashlib.sha256).hexdigest()

# Place two LIMIT orders in a batch
batch_orders = [
{"symbol": "BTCUSDT", "side": "BUY", "type": "LIMIT", "timeInForce": "GTC", "quantity": "0.01", "price": "60000"},
{"symbol": "BTCUSDT", "side": "SELL", "type": "LIMIT", "timeInForce": "GTC", "quantity": "0.01", "price": "80000"},
]

ts = int(time.time() * 1000)
batch_str = json.dumps(batch_orders, separators=(',', ':'))
encoded = quote(batch_str)
qs = f"batchOrders={encoded}&timestamp={ts}"
sig = sign(qs)
resp = requests.post(
f"{BASE_URL}/fapi/v1/batchOrders?{qs}&signature={sig}",
headers={"X-MBX-APIKEY": API_KEY},
)
print(resp.json())