Binance API: APIError(code=-1111): Precision is over the maximum defined for this asset. ||蟒蛇

问题描述 投票:0回答:6

我有一个在“ADAUSDT”中运行的交易机器人,具有动态买卖数量,是我的整个 USDT 余额初始数量,并以相同的余额 + 利润或损失进行交易(它基本上交易并保持与整个 USDT 交易一遍又一遍地平衡)。这是一些代码:

from binance.client import Client
import Keys #personal api keys

client = Client(Keys.b_keys, Keys.b_secret)

infoa = client.get_account()
bal= infoa['balances']
i_o = float(bal[11]["free"])
v_min = v_min #some value of ADA, for example: 1.2 

order = client.create_order(
        symbol = "ADAUSDT" , 
        side=SIDE_BUY ,
        type=ORDER_TYPE_LIMIT ,
        timeInForce = TIME_IN_FORCE_GTC ,
        quantity = float(round((i_o) , 8)) , 
        price = v_min ,
        )               

我知道 quoteAsset 和 baseAsset 所需的精度都是 8,因此在订单本身的数量值中使用了

round()
函数,但即使在那之后,API 仍然会抛出错误“Precision超过为此资产定义的最大值”。请帮助我:c

编辑:i_o 是我的“USDT”余额,理论上它应该随着每笔交易而变化,因此使用这个变量而不是每个订单数量的普通数字。

注意:我对 Python 很菜鸟哈哈,我一周前才学了一些基础知识,所以如果你能详细说明那就太棒了:D

python trading binance cryptocurrency binance-api-client
6个回答
4
投票

根据您的代码和对交易加密货币的一些熟悉,我假设您正在计算的“余额”是您的 USDT 余额,而不是您通过

i_o = float(bal[11]["free"])
获得的 ADA 余额,这意味着您正在下达一定数量的买单ADA 等于您当前的 USDT 余额(四舍五入)——您确定这就是您想要做的吗?

为了更直接地回答您关于为什么会出现该错误的问题,我只能推断您必须使用包含除法的函数计算您想要购买的价格,并且您的结果

v_min
正在结束类似于 1.32578935987532098325 而不是 1.2.

因此,为了您的方便,您也想将其四舍五入:

price = float(round(v_min,8)) ,


2
投票

使用python Binance API获取精准数据的代码:

from binance.client import Client
client = Client()
info = client.futures_exchange_info()

requestedFutures = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'DYDXUSDT']
print(
    {si['symbol']:si['quantityPrecision'] for si in info['symbols'] if si['symbol'] in requestedFutures}
)

0
投票

解决方案:

我将指定每个买卖订单价格的变量以及

i_o
(“USDT”余额)四舍五入 2.


0
投票

对于努力获得正确答案的人,这里是我用来截断数量和价格的函数的干净版本:

def __get_trimmed_quantity(self, quantity):
    trimmed_quantity = round(quantity / self.step_size) * self.step_size
    return trimmed_quantity

def __get_trimmed_price(self, price):
    trimmed_price = round(price / self.tick_size) * self.tick_size
    return trimmed_price

-1
投票
tradingPairs = ['BTCUSDT','ETHUSDT','BNBUSDT']

#Loop though cryptos

for i in range(0,len(tradingPairs)):

info = client.futures_exchange_info()

if info['symbols'][0]['pair'] == tradingPairs[i]:

print("Price Pre ",info['symbols'][0]['pricePrecision'])

pricePrecision = info['symbols'][0]['pricePrecision']
quantityS = 5.2
quantityB = "{:0.0{}f}".format(quantityS, pricePrecision)

-1
投票

最简单的方法是这样的:

1。

sell_amount = int(0.99 * (float(coins_amount)))
2.
quantity = sell_amount

通过上述方法,您将能够出售99%的基础资产。

© www.soinside.com 2019 - 2024. All rights reserved.