3
votes

When trying to place a buy or sell order with the python-binance api I got the following error:

APIError(code=-1013): Filter failure: LOT_SIZE.

Now I've seen at iceberg_parts that this means there is probably something wrong with my buying or selling quantity. I've tried to increase the quantity by a factor 10 but this only gives me another related error:

APIError(code=-1013): Filter failure: MIN_NOTIONAL.

Here's some of my code:

diff = current_price - prev_price
if diff <= 0.0001:
    order = client.order_market_buy(symbol = market , quantity = '0.0001')
    print('buy order')

if diff >= 0.00040:
    order = client.order_market_sell(symbol =market, quantity ='0.0001')
    print('sell order')

Do you know how to fix this?

6

6 Answers

10
votes

This error appears because you are trying to create an order with a quantity lower than the minimun required.

You can access the minimun required of a specific pair with:

info = client.get_symbol_info('ETHUSDT')
print(info)

Output a dictionary with information about that pair. Now you can access the minimun quantity required with:

print(info['filters'][2]['minQty'])
# 0.00001
4
votes

The buying or selling quantity has to be >= 10.3 USD or 10.3/price, pass the quantity and price to these decimal settings/filters with the amounts set with decimal

from decimal import Decimal as D, ROUND_DOWN, ROUND_UP
import decimal

info = client.get_symbol_info(symbol=pair)
price_filter = float(info['filters'][0]['tickSize'])
ticker = client.get_symbol_ticker(symbol=pair)
price = float(ticker['price'])
price = D.from_float(price).quantize(D(str(price_filter)))
minimum = float(info['filters'][2]['minQty']) # 'minQty'
quant = D.from_float(quantity).quantize(D(str(minimum))) # if quantity >= 10.3/price
1
votes

Here is some code.

def round_down(self, coin, number):
    info = self.client.get_symbol_info('%sUSDT' % coin)
    step_size = [float(_['stepSize']) for _ in info['filters'] if _['filterType'] == 'LOT_SIZE'][0]
    step_size = '%.8f' % step_size
    step_size = step_size.rstrip('0')
    decimals = len(step_size.split('.')[1])
    return math.floor(number * 10 ** decimals) / 10 ** decimals
1
votes

I've just gone through this same problem. As a noob, some of the code in these answers seem quite complicated so I came up with a solution.

Code:

def check_decimals(symbol):
    info = client.get_symbol_info(symbol)
    val = info['filters'][2]['stepSize']
    decimal = 0
    is_dec = False
    for c in val:
        if is_dec is True:
            decimal += 1
        if c == '1':
            break
        if c == '.':
            is_dec = True
    return decimal

then when you place the order, just do for ex: (make sure qty is a float or decimal)

  B_order = round(qty / symbol_price, decimal)
  order = client.order_market_buy(
            symbol=symbol_name,
            quantity=B_order)
0
votes

The minimum quantity is equivalent of 10 USDT. Also please take into account that each coin has its own max allowed decimal digits. I.e. for USDT it is 2, so if, for example, you are trying to trade 10.0002 it will be rounded to 10.00. Also when Binance validating amount looks like it converts to USDT at the current rate so minimum quantity for your coin will be different all the time and you need to ensure in your code that the quantity you specify is greater than 10 USDT at the moment of your request. I also add 1-3% extra to the amount to be sure that it will successfully pass validation as the rate could change between the moment I send request and the moment it will be passing validation. So, when I want to trade with minimum allowed quantity I trade with the equivalent of around 10.30 USDT.

0
votes

I write a function like that. It's working for me.

def getPriceLotFormat(self, priceOrg, quantityOrg):
    price = float(priceOrg)
    quantity = float(quantityOrg)
    response = self.get_symbol_info(car.pair) #self is client btw
    priceFilterFloat = format(float(response["filters"][0]["tickSize"]), '.20f')
    lotSizeFloat = format(float(response["filters"][2]["stepSize"]), '.20f')
    # PriceFilter
    numberAfterDot = str(priceFilterFloat.split(".")[1])
    indexOfOne = numberAfterDot.find("1")
    if indexOfOne == -1:
        price = int(price)
    else:
        price = round(float(price), int(indexOfOne - 1))
    # LotSize
    numberAfterDotLot = str(lotSizeFloat.split(".")[1])
    indexOfOneLot = numberAfterDotLot.find("1")
    if indexOfOneLot == -1:
        quantity = int(quantity)
    else:
        quantity = round(float(quantity), int(indexOfOneLot))
    print(f"""
    ##### SELL #####
    Pair : {str(car.pair)}
    Cash : {str(car.price)}
    Quantity : {str(car.quantity)}
    Price : {str(car.price)}
        """)