Hello,
I am trying to place 5 limit orders at a time through python, however it is giving me an error code 400 as a response when I send the request. The URL also looks to be okay after checking here.
Any idea on how I could solve this issue. Appreciate any help. Thanks
https://fapi.binance.com/fapi/v1/batchOrders?batchOrders=%5B%7B%22symbol%22%3A+%22BNBUSDT%22%2C+%22side%22%3A+%22BUY%22%2C+%22positionSide%22%3A+%22LONG%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22quantity%22%3A+0.01%2C+%22price%22%3A+%22511.073%22%7D%2C+%7B%22symbol%22%3A+%22BNBUSDT%22%2C+%22side%22%3A+%22BUY%22%2C+%22positionSide%22%3A+%22LONG%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22quantity%22%3A+0.01%2C+%22price%22%3A+%22510.483%22%7D%2C+%7B%22symbol%22%3A+%22BNBUSDT%22%2C+%22side%22%3A+%22BUY%22%2C+%22positionSide%22%3A+%22LONG%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22quantity%22%3A+0.01%2C+%22price%22%3A+%22509.894%22%7D%2C+%7B%22symbol%22%3A+%22BNBUSDT%22%2C+%22side%22%3A+%22BUY%22%2C+%22positionSide%22%3A+%22LONG%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22quantity%22%3A+0.01%2C+%22price%22%3A+%22509.306%22%7D%2C+%7B%22symbol%22%3A+%22BNBUSDT%22%2C+%22side%22%3A+%22BUY%22%2C+%22positionSide%22%3A+%22LONG%22%2C+%22type%22%3A+%22LIMIT%22%2C+%22timeInForce%22%3A+%22GTC%22%2C+%22quantity%22%3A+0.01%2C+%22price%22%3A+%22508.718%22%7D%5D×tamp=1619009636823&signature=(signature hidden for posting here)
[{'code': 400, 'msg': None}, {'code': 400, 'msg': None}, {'code': 400, 'msg': None}, {'code': 400, 'msg': None}, {'code': 400, 'msg': None}]
batch = []
print(numberOfOrders)
#send request of batchOrders if 5 or less orders
if numberOfOrders <= 5:
for k in range(numberOfOrders):
params = {
"symbol": symbol,
"side": "BUY",
"positionSide": "LONG",
"type": "LIMIT",
"timeInForce": "GTC",
"quantity": orderQuantities[k],
"price": str(entryPrices[k]),
}
batch.append(params)
response = send_signed_request('POST', '/fapi/v1/batchOrders', {"batchOrders": batch})
print(response)
batch.clear()
#send request of batchOrders for orders more than 5
else:
for k in range(numberOfOrders):
params = {
"symbol": symbol,
"side": "BUY",
"positionSide": "LONG",
"type": "LIMIT",
"timeInForce": "GTC",
"quantity": orderQuantities[k],
"price": str(entryPrices[k]),
}
batch.append(params)
#send request of batchOrders for every 5 orders
if ((k + 1)// 5 > 0) and ((k + 1) % 5 == 0):
response = send_signed_request('POST', '/fapi/v1/batchOrders', {"batchOrders": batch})
print(response)
batch.clear()
#send request of remaining batchOrders
if k == numberOfOrders-1:
response = send_signed_request('POST', '/fapi/v1/batchOrders', {"batchOrders": batch})
print(response)
batch.clear()