I am trying to build my own bot on Binance API availaible on Python.
What I am currently trying is to make order of buying/selling BTC, based on the amount of money/BTC availaible in my Binance account.
Then, the code is supposed to convert this amount of cash in BTC and make buy/sell orders
if order_book[-1]=="BUY":
for balance in account_info['balances']:
if float(balance['free']) > 0 and balance['asset']=="BTC":
total_btc += float(balance['free'])
for balance in account_info['balances']:
if float(balance['free']) > 0 and balance['asset']=="USDT":
total_balance += float(balance['free'])
So based on the loops above, total_balance gives me the amount of cash I currently have.
Based on that, I can make a buy order :
client.create_order(
symbol='BTCUSDT',
side='BUY',
type='MARKET',
quantity=float(round(float(total_balance)/float(client.get_ticker(symbol='BTCUSDT'```
The main struggle here is that, here I'm trying to convert in BTC or whatever cryptocurrency in the "quantity" argument, and most often I have the following error :
BinanceAPIException: APIError(code=-1013): Filter failure: LOT_SIZE
How can I make this code run everytime without getting a Lot Size error, i.e how can I convert precisely the amount of cash I have into BTC and make the buy order?
EDIT: For example, in my case, the quantity here corresponds to 0.00095922 BTCUSDT, but I have the Lot Size error. When searching, I found that Min Quantity is way lower than the current trade:
{
“filterType”: “LOT_SIZE”,
“minQty”: “0.00000100”,
“maxQty”: “9000.00000000”,
“stepSize”: “0.00000100”
}
I understood that the quantity cannot be up to 6 decimals, so I need to round it. The problem is that sometimes it is rounding up, and I don't have the amount of cash sufficient for the buy order.