APIError in order new token.

Hello everyone,
today on Binance there was the listing of ALT. I tried to participate with my bot, but at the time of the order, I received this error:

2024-01-25 09:59:59.907 UTC DEBUG urllib3.connectionpool: https://api.binance.com:443 "GET /api/v3/ticker/price HTTP/1.1" 200 18884
waiting new coin...
2024-01-25 09:59:59.941 UTC DEBUG urllib3.connectionpool: https://api.binance.com:443 "GET /api/v3/ticker/price HTTP/1.1" 200 18886
waiting new coin...
2024-01-25 09:59:59.976 UTC DEBUG urllib3.connectionpool: https://api.binance.com:443 "GET /api/v3/ticker/price HTTP/1.1" 200 18883
waiting new coin...
2024-01-25 10:00:00.018 UTC DEBUG urllib3.connectionpool: https://api.binance.com:443 "GET /api/v3/ticker/price HTTP/1.1" 200 18921
2024-01-25 10:00:00.057 UTC DEBUG urllib3.connectionpool: https://api.binance.com:443 "POST /api/v3/order HTTP/1.1" 400 47
Traceback (most recent call last):
  File "/home/admin/my_bot/./bin_newlist_bot_v2.py", line 98, in <module>
    NewCoinCatcher(newPair, myAmount)
  File "/home/admin/my_bot/./bin_newlist_bot_v2.py", line 91, in NewCoinCatcher
    PlaceOrder(pair, amount)
  File "/home/admin/my_bot/./bin_newlist_bot_v2.py", line 73, in PlaceOrder
    order = client.create_order(symbol = pair, side = 'BUY', type = 'MARKET', quoteOrderQty = str(myAmount))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/env_python/lib/python3.11/site-packages/binance/client.py", line 1448, in create_order
    return self._post('order', True, data=params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/env_python/lib/python3.11/site-packages/binance/client.py", line 418, in _post
    return self._request_api('post', path, signed, version, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/env_python/lib/python3.11/site-packages/binance/client.py", line 378, in _request_api
    return self._request(method, uri, signed, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/env_python/lib/python3.11/site-packages/binance/client.py", line 359, in _request
    return self._handle_response(self.response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/env_python/lib/python3.11/site-packages/binance/client.py", line 368, in _handle_response
    raise BinanceAPIException(response, response.status_code, response.text)
binance.exceptions.BinanceAPIException: APIError(code=-2010): Filter failure: LOT_SIZE

This is the error of an order that has been rejected. Could someone give me an explanation of why it was not placed? Keep in mind that mine is a market order for only 20 USDT.

thanks.

Hey,
The error indicates an issue with the LOT_SIZE filter, suggesting that the requested quantity of tokens is not acceptable. You can refer to the filter documentation for more details: Binance API Documentation

1 Like

This is how I place an order:

order = client.create_order(symbol = pair, 
                            side = 'BUY', 
                            type = 'MARKET', 
                            quoteOrderQty = str(myAmount)
                            )

What I don’t understand is why I get an error if the order is sent within the first 20 milliseconds of the market opening, and yet if it is sent after 15 minutes, the order is accepted.

Now I have added this function to calculate the quantity in the correct way, or at least I hope so.

from binance.helpers import round_step_size
def get_quantity(pair, amount):
    last_price = float(client.get_symbol_ticker(symbol = pair)['price'])
    step_size = float(client.get_symbol_info(pair)['filters'][1]['stepSize'])
    
    qty = amount / last_price
    quantity = round_step_size(qty, step_size) - step_size
    return quantity

Obviously, in ‘create_order’, I replace ‘quoteOrderQty’ with ‘quantity’.