I want a python function to sell the entire balance of an asset to USDT. If I have n ETH, this function should transfer the entire ETH balance to USDT.
I tried something like:
bal = client.get_asset_balance(asset='ETH')['free']
sell = client.order_market_buy(symbol='ETHUSDT', quantity = bal)
print(sell)
This sometimes outputs a Api Error: Insufficient Balance for some reason. Please help me with a better option.
You use buy order. Use "client.order_market_sell" instead of "client.order_market_buy"