Binance API: APIError(code=-1111): Precision is over the maximum defined for this asset. || Python
Asked Answered
L

8

5

I have a trading bot which operates in 'ADAUSDT' with dynamic quantities for buying and selling, being my whole USDT balance the initial quantity, and trading with that same balance + profits or losses (it basically trades and keeps trading with the whole USDT balance over and over again). Here's some code:

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

I know that the precision required both for the quoteAsset and for the baseAsset is 8, hence the usage of the round() function in the quantity value for the order itself, but even after that, the API still throws me the error "Precision is over the maximum defined for this asset". Please help me :c

Edit: i_o is my "USDT" balance, which in theory should change with each trade, hence the usage of this variable instead of a plain number for the quantity of each order.

Note: I'm pretty noob at Python lol I just learned some basics a week ago, so it would be amazing if you could elaborate :D

Liverpudlian answered 30/6, 2021 at 17:11 Comment(0)
H
6

Based on your code and a bit of familiarity with trading crypto I am assuming that the 'balance' you are calculating is your USDT balance and not your ADA balance via i_o = float(bal[11]["free"]) which would mean that you are placing a buy order for an amount of ADA equal to your current USDT balance (rounded) -- are you sure that's what you want to be doing?

To more directly answer your question as to why you are getting that error, I can only deduce that you must be calculating the price at which you would like to buy using a function that includes division and that your resultant v_min is ending up being something like 1.32578935987532098325 and not 1.2.

Therefore, you would like to also round it, for your convenience:

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

Hirst answered 30/6, 2021 at 19:22 Comment(0)
A
3

For people struggling to get the right answer, here are clean versions of the functions I use to truncate quantity and price:

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
Atheistic answered 10/3, 2023 at 22:20 Comment(0)
R
2

Code for getting precision data using 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}
)
Reins answered 17/1, 2022 at 15:7 Comment(0)
L
0

Solution:

I rounded the variable that specifies the price for each buy and sell order, aswell as i_o ("USDT" balance), by 2.

Liverpudlian answered 30/6, 2021 at 20:6 Comment(0)
A
0
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)
Agricola answered 19/7, 2021 at 12:37 Comment(0)
H
0

Here is the code, reference video here.

    def getTickerPricePrecision(symbol):
        resp = client.exchange_info()['symbols']
        for elem in resp:
            if elem['symbol'] == symbol:
                return elem['pricePrecision']
    
    def getTickerQtyPrecision(symbol):
        resp = client.exchange_info()['symbols']
        for elem in resp:
            if elem['symbol'] == symbol:
                return elem['quantityPrecision']

    orderQuantity = round(yourMoneyAmount / tickerPrice, tickerQtyPrecision)
Heyduck answered 29/3, 2024 at 19:16 Comment(0)
K
-2

The easiest way to do it is like this:

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

By the above method, you will be able to sell 99% of your base asset.

Klockau answered 22/9, 2021 at 7:53 Comment(0)
E
-2
def Pric_Precision(price, symbol):

    return str(round(float(price),[x['pricePrecision'] for x in client.futures_exchange_info()['symbols'] if x['symbol'] == symbol][0]))


def QUN_Precision(quantity, symbol):
    return str(round(float(quantity),[x['quantityPrecision'] for x in client.futures_exchange_info()['symbols'] if x['symbol'] == symbol][0]))
Ellon answered 28/5, 2023 at 10:4 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Crackerbarrel

© 2022 - 2025 — McMap. All rights reserved.