Rounded order quantities cause insufficient balance when selling

Hi,

I am giving automated orders using the spot trade API POST /api/v3/order

  • I set the quoteOrderQtyto a fixed USDT amount for each BUY order
  • The response provides me with a executedQty number, which I save into my position model
  • When my bot gives a sell decision, it sends a sell order to Binance API with quantity as the executedQty that was returned before

This sometimes works; but sometimes when selling, I get an insufficient balance error due to the rounded-up quantity returned by Binance.
Let me tell by an example:

  • I bought 12$ worth of IOTAUSDT via API ('quoteOrderQty': 12). Binance returned 7.7 for the executedQty
  • When I check my wallet in Binance UI, I have 7.69230000 IOTA
  • When I try to sell the position with quantity=7.7, I get
{'code': -2010, 'msg': 'Account has insufficient balance for requested action.'}

How can I get around this?
I looked for a command like ‘sell all the coin that was bought with this order ID’ in the API documentation, but I couldn’t find such an option. Is there a specific variable I could send to binance to sell exactly the same amount, or at least the floored amount of it?

Probably charged for commission. Please check /api/v3/myTrades to see the related commission part

Indeed that was it. I see the commission in the fills part of the order response, so I can now calculate the correct amount to sell. Thanks for the swift reply, it would take me days to figure out otherwise!