0

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

我不知道如何解决它,我认为我一直在做正确的事情,因为当我将第一个 'order_market_buy' 中的 'quantity' 更改为 0.26 时,它毫无问题地购买了。

4

1 回答 1

0

BNBBTC在 Binance 上交易的最小数量是:0.01

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

这是响应的摘录(LOT_SIZEfor 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"
        },
    ],
}

于 2021-07-01T23:42:39.483 回答