# 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 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.
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.