簡體   English   中英

Binance API:APIError(code=-1111):精度超過了為該資產定義的最大值。 || Python

[英]Binance API: APIError(code=-1111): Precision is over the maximum defined for this asset. || Python

我有一個交易機器人,它在“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 仍然會向我拋出錯誤“精度是超過為此資產定義的最大值”。 請幫助我:c

編輯:i_o 是我的“USDT”余額,理論上應該隨着每筆交易而改變,因此使用這個變量而不是每個訂單數量的普通數字。

注意:我對 Python 很陌生,哈哈,我一周前剛學了一些基礎知識,所以如果你能詳細說明一下,那就太棒了:D

根據您的代碼和對加密貨幣交易的一些熟悉,我假設您計算的“余額”是您的 USDT 余額,而不是您通過i_o = float(bal[11]["free"]) ADA 余額,這意味着您正在下一個 ADA 的買單,金額等於您當前的 USDT 余額(四舍五入)——您確定這就是您想要做的嗎?

為了更直接地回答您關於為什么會收到該錯誤的問題,我只能推斷您必須使用包含除法的函數來計算您想要購買的價格,並且您的結果v_min最終是這樣的1.32578935987532098325 而不是 1.2。

因此,為了方便起見,您還想對其進行四舍五入:

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

解決方案:

我將指定每個買賣訂單價格的變量以及i_o (“USDT”余額)四舍五入為 2。

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)

使用 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}
)

最簡單的方法是這樣的:

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

通過上述方法,您將能夠出售 99% 的基礎資產。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM