python-binance: Filter failure: LOT_SIZE
I cannot get the API to properly make a buy order. My current process is to first get my current USDT total, multiply it by 0.9995 to compensate for the 0.050% fee and then take that USDT total and put it into the “quantity=[amount]”. When I do this, I get:
binance.exceptions.BinanceAPIException: APIError(code=-1013): Filter failure: LOT_SIZE
How can I overcome this?
balance = client.get_asset_balance(asset='USDT')
print(balance['free'])
quantity = (float(balance['free']))*0.9995
print(quantity)
order = client.order_market_buy(symbol='BTCUSDT', quantity=(float(quantity)))
orders = client.get_open_orders(symbol='BTCUSDT')
print(orders)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (2 by maintainers)
I’ve found a fix after reading a lot of different stuff. Essentially what I had to do was round off the number that came from dividing my current USDT totals into the current BTC price to 6 decimals only. The number I was getting had 18 decimal points.
Here is the code I used to get what I needed, I was close earlier, but did not realize I had to limit the decimal points.
balance = client.get_asset_balance(asset='USDT')
trades = client.get_recent_trades(symbol='BTCUSDT')
quantity = (float(balance['free']))/float(trades[0]['price'])*0.9995
order = client.order_market_buy(symbol='BTCUSDT', quantity=(round(quantity, 6)))
Instead of rounding to hard-coded 6 digits, you can find actual precision using this API (it can be different for different tokens): https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#lot_size (stepSize). To convert stepSize to the precision, I use this:
precision = int(round(-math.log(stepSize, 10), 0))
, and then doround(quantity, precision)
.Why API do NOT automatically round the order? Why do we need to make it via extra code? Any meaningful reason?
Hi, I think the following code will solve your problem
info = client.get_symbol_info(symbol=pair) f = [i[“stepSize”] for i in info[“filters”] if i[“filterType”] == “LOT_SIZE”][0] qty = round(qty, f.index(“1”) - 1)
this is a really efficient solution to the problem
thank you so much! @goldan @cc345 sym_info = self._client.get_symbol_info(‘BATBNB’) filters = sym_info[‘filters’] for f in filters: print("filter~~~~~~~~~~~~ " + str(f)) if f[‘filterType’] == ‘LOT_SIZE’: self._step_size = float(f[‘stepSize’]) break
from binance.exceptions import *
to import Exception of python-binance
thank you very much! really useful 😃 We can improve it a little more: instead of hard coding 0.9995 as fee, this can be taken dynamically with API and then turn into % with:
(100 - symbol_fee) / 100
For whatever reason, crypto currency has to be traded in strange and unusual quantities. You should try something along the lines of what selimozbas suggested
This is what I have been using (I’m horrible at Python), but it seems to work: for filters:
sym_info = self._client.get_symbol_info(self._pair)
###############################################################################################
###############################################################################################
It’s to compensate the 0.050% transaction fee