trade quantity error ? in some coins work in some coins getting errors

i am building this program in python with python binance library

eachTradePercent = 66
availableUSDT = 20.55
calculatePercentUSDT = float(availableUSDT) * eachTradePercent / 100
avgTickerPrice =  get_avg_Price['price']
calculatedBuyQuantity =  int(calculatePercentUSDT / float(avgTickerPrice))
b = round(calculatedBuyQuantity, 4)

print("===================================================")
print(f" {tv_signal_ticker} average price is -> {avgTickerPrice}")
print(f" calculatePercentUSDT is -> {calculatePercentUSDT}")
print(f" Buy Quantity for with int -> {tv_signal_ticker} is {calculatedBuyQuantity}")
print(f" without int-> {calculatePercentUSDT / float(avgTickerPrice)}")
print(f"b with round -> {b} “)
print(”==================================================")

Output in console

========== console OUTPUT 1 =============
AAVEUSDT average price is -> 398.39542276
calculatePercentUSDT is -> 13.293634200000001
Buy Quantity for with int -> AAVEUSDT is 0
without int-> 0.033367939089019874
b with round -> 0
An exception occurred APIError(code=-1013): Invalid quantity.

.

====== console OUTPUT 2 ===============
ALGOUSDT average price is -> 1.20665746
calculatePercentUSDT is -> 13.293634200000001
Buy Quantity for with int -> ALGOUSDT is 11
without int-> 11.016907979833814
b with round -> 11

.

============console OUTPUT 3 ================
BTCUSDT average price is -> 49909.15790254
calculatePercentUSDT is -> 4.5424302
Buy Quantity for with int -> BTCUSDT is 0
without int-> 9.10139619840956e-05
b with round -> 0
An exception occurred APIError(code=-1013): Invalid quantity.

.

=========console OUTPUT 4 ================
TRXUSDT average price is -> 0.10109436
calculatePercentUSDT is -> 13.293634200000001
Buy Quantity for with int -> TRXUSDT is 131
without int-> 131.49728827602254
b with round -> 131

.

===========CONSOLE OUTPUT 5 =================
BNBUSDT average price is -> 495.91391722
calculatePercentUSDT is -> 13.280665199999998
Buy Quantity for with int -> BNBUSDT is 0
without int-> 0.026780182484994385
b with round -> 0

Sending BUY Order for BNBUSDT Position-> BUY
An exception occurred APIError(code=-1013): Invalid quantity.

sir how to calculate accepted format quantity for all coins
how to fix these types of errors

You should not cast your quantity to integer, otherwise for example you want to buy 0.02 BTC, then you can only buy 0 or 1, right? Also, in your code, there’s no point in rounding an integer.

For your order to be accepted by Binance, you must find the “step size” via exchange info, then calculate how many decimals you should be rounding for that particular symbol because they could be different and change once in a while. You can cache the exchange info for some time before calling its API endpoint again to update.

See the function round_step_size() that does it for you. You just need to pass the quantity and step size. The logic should look like this:

from binance.helpers import round_step_size

step_size = get_step_size(symbol)
calculated_buy_quantity = round_step_size(qt, step_size) - step_size

You can get the exchange info via get_exchange_info()

get_exchange_info = config.client.get_exchange_info()
exchange_info_symbols = get_exchange_info['symbols']
for data_symbols in exchange_info_symbols:
    if data_symbols['symbol'] == tv_signal_ticker:
        print(f" ticker is  {data_symbols['symbol']}")
        data_symbol_filters = data_symbols['filters']
        for data_filters in data_symbol_filters:
            if data_filters['filterType'] == "LOT_SIZE":
                stepSizeForQuantityTickers = data_filters['stepSize']
                print(f" {tv_signal_ticker} and step size is   {stepSizeForQuantityTickers}")

    
    quantityWithRoundStep = round_step_size(calculatedBuyQuantity, stepSizeForQuantityTickers) - stepSizeForQuantityTickers

**output is **

**How to solve this problem sir **

Hi,
I try to test your advice but I dont understand what is the function get_step_size(symbol).
thanks,

Hi.
The error message indicates that the data type is incorrect. Please try to convert the input string to a number.
Please avoid asking programming question as this forum is used for API discussion, thanks.