Python Forum
Selling gives me ‘Insufficient balance’ error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Selling gives me ‘Insufficient balance’ error (/thread-37887.html)



Selling gives me ‘Insufficient balance’ error - gerald - Aug-03-2022

Hi everyone,

When I try to sell it gives me error: APIError(code=-2010): Account has insufficient balance for requested action. Even though I should have enough balance left to pay for the fees. What can possibly be wrong with my code ?
Here is my sell code:

pr = client.get_symbol_ticker(symbol=symbol)
                price=float(pr['price'])
                bal = client.get_asset_balance(asset='RIF')
                quantity = ((float(bal['free'])) / price)  # 0.995
                sym_info = client.get_symbol_info(symbol)
                filters = sym_info['filters']
                for f in filters:
                    print("filter~~~~~~~~~~~~ " + str(f))
                    if f['filterType'] == 'LOT_SIZE':
                        step_size = float(f['stepSize'])
                        break
                precision = int(round(-math.log(step_size, 10), 0))
                quantity = float(round(quantity*0.99, precision))
                order = client.create_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity)
Any help would be much appreciated.


RE: Selling gives me ‘Insufficient balance’ error - woooee - Aug-03-2022

Too little code to help. Check the get_asset_balance function

What happens to precision when f['filterType'] does not equal 'LOT_SIZE':

How do you expect to be able to use step_size after a break statement.


RE: Selling gives me ‘Insufficient balance’ error - gerald - Aug-04-2022

(Aug-03-2022, 06:40 PM)woooee Wrote: Too little code to help. Check the get_asset_balance function

What happens to precision when f['filterType'] does not equal 'LOT_SIZE':

How do you expect to be able to use step_size after a break statement.

Thanks, the problem is solved now.

Cheers !


RE: Selling gives me ‘Insufficient balance’ error - Larz60+ - Aug-04-2022

gerald: Please share your solution so others may benefit.