Search code examples
pythonbinancebinance-api-client

Why am I receiving the error "APIError(code=-1013): Filter failure: LOT_SIZE" from python-binance library?


I have created a triangle arbitrage bot with the Python programming language to trade on Binance from a VPS.

I have bought BTC, which is the currency with which I want to operate, specifically a total of "0.00278926". I also have a list of various tokens to do the triangular arbitrage.

Imagine that the bot has found an Arbitrage opportunity with these pairs: ['BNBBTC', 'ADABNB', 'ADABTC']. Obviously, the bot should buy with BTC an amount of BNB, then with BNB it would buy ADA and then sell ADA to BTC. Until then fine.

However, when it finds that opportunity and tries to buy, the bot sends me this error in the console:

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

And I have previously checked to see if the minimum amount to buy BNB with BTC was larger than what I had and it is not, I have amount between the minimum and the maximum.

This is my code once the arbitrage opportunity (discounting the fees) is going to bring us profit:

from binance.client import Client
from binance.enums import *
import time
from datetime import datetime
import matplotlib
from matplotlib import cm
import matplotlib.pyplot as plt
import math
from binance_key import BinanceKey
import json

"""
... Here is the code for the Keys, the initialization of the bot, etc.
"""

list_of_arb_sym = [
            ['BNBBTC', 'ADABNB', 'ADABTC'],         #Buying BNB
            ['BNBBTC', 'AAVEBNB', 'AAVEBTC'],
            ['...'] #Imagine that here there are a list of 300 pairs

#Then I have taken care of passing the values ​​of a line from the list to list_of_sym [0], list_of_sym [1], list_of_sym [2] but I do not add it so that it is not excessively long
"""
... here will be that code
"""

# Get values and prices
price_order_1 = client.get_avg_price(symbol=list_of_sym[0])
price_order_2 = client.get_avg_price(symbol=list_of_sym[1])
price_order_3 = client.get_avg_price(symbol=list_of_sym[2])

price1 = float(price_order_1["price"])
price2 = float(price_order_2["price"])
price3 = float(price_order_3["price"])

"""
... more irrelevant code that is working
"""

if arb_opportunity == 'Yes':
    place_order_msg = "STARTING TO TRADE\n\n"
    print(place_order_msg)
    data_log_to_file(place_order_msg)

    #First buy
    balance1 = client.get_asset_balance('BTC')
    quantity1 = (float(balance1['free'])/price1)
    quantity_1 = round(quantity1, 5)
    
    
    order_1 = client.order_market_buy(
        symbol=list_of_sym[0],
        quantity=quantity_1)
    
    first_order = "FIRST ORDER DID IT.\n\n"
    print(first_order)
    data_log_to_file(first_order)

    #Second buy
    simbolo2 =list_of_sym[0]
    simbolo2form = simbolo2[0:3]
    balance2 = client.get_asset_balance(simbolo2form)
    quantity2 = (float(balance2['free'])/price2)
    quantity_2 = round(quantity2, 5)
    
    order_2 = client.order_market_buy(
        symbol=list_of_sym[1],
        quantity=quantity_2)

    second_order = "SECOND ORDER DID IT.\n\n"
    print(second_order)
    data_log_to_file(second_order)

    #Sell 
    simbolo3 = list_of_sym[1]
    simbolo3form = simbolo3[0:-3]
    balance3 = client.get_asset_balance(simbolo3form)
    quantity3 = (float(balance3['free'])/price3)
    quantity_3 = round(quantity3, 5)

    order_3 = client.order_market_sell(
        symbol=list_of_sym[2],
        quantity=quantity_3)
    

    third_order = "SELL DID. \n\n"
    third_order += "THE BOT HAS FINISHED"
    print(third_order)
    data_log_to_file(third_order)

I don't know how to fix it, I think I have done the right thing all the time since when I changed the 'quantity' in the first 'order_market_buy' to 0.26, it bought without problems.


Solution

  • The minimal quantity for trading BNBBTC on Binance is: 0.01

    You can check this by sending a GET request to https://api.binance.com/api/v3/exchangeInfo

    Here is an extract of the response (LOT_SIZE for BNBBTC):

    {
        "symbol": "BNBBTC",
        "status": "TRADING",
        "baseAsset": "BNB",
        "baseAssetPrecision": 8,
        "quoteAsset": "BTC",
        "quotePrecision": 8,
        "quoteAssetPrecision": 8,
        "baseCommissionPrecision": 8,
        "quoteCommissionPrecision": 8,
        ...
        "filters": [
            ...
            {
                    "filterType": "LOT_SIZE",
                    "minQty": "0.01000000",
                    "maxQty": "100000.00000000",
                    "stepSize": "0.01000000"
            },
        ],
    }