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')['lastPrice']),8)))
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 ?
Thank you a lot