How to place batch orders for futures

This url works fine to place batch order:

params = {
    "batchOrders": [
        {
            "symbol":"BTCUSDT",
            "side": "SELL",
            "type": "LIMIT",
            "quantity": "0.001",
            "timeInForce": "GTC",
            "reduceOnly": "false",
            "price": "9563.51"
        },
        {
            "symbol":"BTCUSDT",
            "side": "SELL",
            "type": "LIMIT",
            "quantity": "0.001",
            "timeInForce": "GTC",
            "reduceOnly": "false",
            "price": "9613.51"
        }
}

https://testnet.binancefuture.com/fapi/v1/batchOrders?batchOrders=%5B%7B%22symbol%22%3A+%22BTCUSDT%22%2C+%22side%22%3A+%22SELL%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22quantity%22%3A+%220.001%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22reduceOnly%22%3A+%22false%22%2C+%22price%22%3A+%229563.51%22%7D%2C+%7B%22symbol%22%3A+%22BTCUSDT%22%2C+%22side%22%3A+%22SELL%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22quantity%22%3A+%220.001%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22reduceOnly%22%3A+%22false%22%2C+%22price%22%3A+%229613.51%22%7D%5D&timestamp=1592732592992&signature=2b29764224816bbc2366cf97688958d2bf3e790dc6270804c6982160cf9fb444

json encode the batch orders.

We have an example python script and work out of the box.

I want to send batchOrder in Python, but I recive [{‘code’: 400, ‘msg’: None}, {‘code’: 400, ‘msg’: None}]
What is wrong ?
When I send a simple Order everything is OK.
Here is pice of code.

timestamp2 = (int(time.time() * 1000))
params2 = { “batchOrders”: [
{

    "symbol": "BTCUSDT",
    "type":"STOP_MARKET",
    "positionSide":"BOTH",
    "side": "BUY",
    "quantity":0.03,
    "stopPrice":56000,
    "recvWindow":8000,
    "timestamp": timestamp2
    },
    {
    "symbol": "BTCUSDT",
    "type":"STOP_MARKET",
    "positionSide":"BOTH",
    "side": "SELL",
    "quantity":0.03,
    "stopPrice":51000,
    "recvWindow":8000,
    "timestamp": timestamp2
    }
]
}

sending = send_signed_request(‘POST’, ‘/fapi/v1/batchOrders’, params2)

using the example code above for debugging.

I use example code above and encounter this error. do you know why?
{‘code’: -1130, ‘msg’: “Data sent for parameter ‘batchOrders:[{‘symbol’: ‘ETHUSDT’, ‘side’: ‘BUY’, ‘type’: ‘LIMIT’, ‘quantity’: ‘0.001’, ‘timeInForce’: ‘GTC’, ‘price’: ‘3254.36’}]’ is not valid.”}

the qty can only set up to 2 decimals, please check the rules from the /exchangeInfo.

It could be tricky to debug in the batch order endpoint, I would suggest to test with the same parameters in the single order endpoint first.

If you send a post request to the endpoint to post 1 order: The price and quantity needs to be a FLOAT.

If you send a post request to the batch orders enpoint to post multiple orders (up to 5): The prices and qantities needs to be a STRING.

I dont know if this is what caused your error, but it took me way to much time to figure out the documentation was lying!

Hope this can help someone

5 Likes

THANK YOU, THEY REALLY SHOULD BE STRINGS! WTF Binance? And I didn’t see it in the documentation…

2 Likes