为什么我从 python-binance 库收到错误“APIError(code=-1013): Filter failure: LOT_SIZE”?

问题描述

我使用 Python 编程语言创建了一个三角形套利机器人,以便从 VPS 上在 Binance 上进行交易。

我买了BTC,是我想操作的币种,具体一共“0.00278926”。我还有一个用于进行三角套利的各种代币的列表。

想象一下,机器人通过以下对找到了套利机会:['BNBBTC','ADABNB','ADABTC']。显然,机器人应该用 BTC 购买一定数量的 BNB,然后用 BNB 购买 ADA,然后将 ADA 卖给 BTC。到那时就好了。

但是,当它找到机会并尝试购买时,机器人会在控制台中向我发送此错误

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

我之前检查过用 BTC 购买 BNB 的最低金额是否大于我所拥有的金额,但事实并非如此,我的金额介于最低和最高之间。

这是我的代码,一旦套利机会(折扣费用)将为我们带来利润:

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','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)

我不知道如何修复它,我认为自从我将第一个 'order_market_buy' 中的 'quantity' 更改为 0.26 后,我一直在做正确的事情,它购买没有问题。

解决方法

在币安交易 BNBBTC 的最小数量为:0.01

您可以通过向 https://api.binance.com/api/v3/exchangeInfo 发送 GET 请求来检查这一点

以下是响应的摘录(LOT_SIZE 对应 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"
        },],}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...