python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

APIError(code=-1111): Precision is over the maximum defined for this asset

Open mark-antony1 opened this issue 8 years ago • 31 comments

There is an issue placing orders on binance for xmr/btc

The ticker information is as follows for the pair. {'symbol': 'XMRBTC', 'status': 'TRADING', 'baseAsset': 'XMR', 'baseAssetPrecision': 8, 'quoteAsset': 'BTC', 'quotePrecision': 8, 'orderTypes': ['LIMIT', 'LIMIT_MAKER', 'MARKET', 'STOP_LOSS_LIMIT', 'TAKE_PROFIT_LIMIT'], 'icebergAllowed': False, 'filters': [{'filterType': 'PRICE_FILTER', 'minPrice': '0.00000100', 'maxPrice': '100000.00000000', 'tickSize': '0.00000100'}, {'filterType': 'LOT_SIZE', 'minQty': '0.00100000', 'maxQty': '10000000.00000000', 'stepSize': '0.00100000'}, {'filterType': 'MIN_NOTIONAL', 'minNotional': '0.00100000'}]}

However, If i were to submit a buy where the quantity submitted is precise to 8 decimals, i.e. 0.44500000 It will return with the error binance.exceptions.BinanceAPIException: APIError(code=-1111): Precision is over the maximum defined for this asset.

What is the issue here?

mark-antony1 avatar Jun 19 '18 20:06 mark-antony1

https://github.com/sammchardy/python-binance/issues/57

CJ1976 avatar Dec 29 '18 09:12 CJ1976

Did u guys solve this ? I got this error too.

tnpxu avatar Mar 22 '20 02:03 tnpxu

Use the round function and round your quantity or price to the precision needed like:

quantity = float(round(quantity, precision))

Podzied avatar Mar 28 '21 03:03 Podzied

best fix is quantity = float(round(quantity, 6))

Abdulrahmantommy avatar Mar 31 '21 00:03 Abdulrahmantommy

decimal_count = 4
quantity = f"{float(value):.{decimal_count}f}"

avatar-lavventura avatar May 29 '21 11:05 avatar-lavventura

All of this is not working for me with quantity=round(self.quantity, self.precisions[self.coinName]) where, you guessed it, precisions is a dict of all needed precisions for each coin. This is still throwing an error.

I tried transforming it to string : same error. substracting random numbers from precision (1, 2, 3, ...) : same error. manually trying in a loop all possible precisions from 1 to 1000 : same error. Transforming it to DECIMAL : same error.

Help me please, I might cut my veins soon

ArthurDetaille avatar May 30 '21 14:05 ArthurDetaille

@ArthurDetaille Try this:

 _entryPrice = _entryPrice.rstrip("0").rstrip(".") if "." in _entryPrice else _entryPrice
decimal_count = len(str(_entryPrice).split(".")[1])
try:
    self.order_limit(symbol, _amount, _side, _entryPrice, decimal_count)
except:
    self.order_limit(symbol, _amount, _side, _entryPrice, decimal_count - 1)  # here you are attempting with 1 lower decimal value

avatar-lavventura avatar May 31 '21 10:05 avatar-lavventura

I'm afraid it's not working either :(

ArthurDetaille avatar May 31 '21 13:05 ArthurDetaille

Allright, add me on discord 'Ærth uur#0767'

ArthurDetaille avatar May 31 '21 13:05 ArthurDetaille

Maybe you could give you yours ? (thank again for your time)

ArthurDetaille avatar May 31 '21 22:05 ArthurDetaille

API exchangeInfo https://api.binance.com/api/v3/exchangeInfo https://fapi.binance.com/fapi/v1/exchangeInfo

dvdieu avatar Jun 06 '21 17:06 dvdieu

I solve in this way: price = float(open_inf['entryPrice']) round_len = len(str(price).rsplit('.', 1)[-1]) (use round_len for your purposes, price - any that you get from binance)

GeorgKantsedal avatar Jul 05 '21 12:07 GeorgKantsedal

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)

teranoib avatar Jul 19 '21 12:07 teranoib

This is so frustrating I have been for a few days dealing with this, if not this error then other filter errors, isn't there any API to get to the closest feasible number that the exchange will accept?

And what about other exchanges? How do they manage this problem?


  def normalize_number(self,my_float_number):
        amount_int = int(float(my_float_number) / float(self.symbol.get_step_size()))
        quote_step_size = float(self.symbol.get_step_size())
        amount = 0
        quote_asset_precision = self.symbol.get_base_asset_precision()
        for i in range(0,amount_int):    
            amount = amount + quote_step_size
        return "{:0.0{}f}".format(amount, quote_asset_precision)
  def val(self):
        min_qty_i_can_buy = self.symbol.min_quantity_i_can_buy()
        max_qty_i_can_buy = self.symbol.max_quantity_i_can_buy()
        if float(self.get_base_float()) <= max_qty_i_can_buy:
            if float(self.get_base_float()) > min_qty_i_can_buy:
                
                exchange_format_value = self.normalize_number(float(self.get_base_float()))
                return float(exchange_format_value)
                #return float(round(float(exchange_format_value),self.symbol.get_base_asset_precision()))
                        
            else:
                exchange_format_value = self.normalize_number(float(self.symbol.min_quantity_i_can_buy()))
                return exchange_format_value
       

And then I do:


        float_amount = self.amount.val()
        exchange.futures_create_order(symbol=symbol.uppercase_format(), side='BUY', type='MARKET', quantity=float_amount)
    

PabloBorda avatar Jul 21 '21 02:07 PabloBorda

For Futures i used this and it worked very well url = "https://api.binance.com/api/v3/exchangeInfo?symbol="+symbol info_data = requests.get(url).json() pricePrecision = info_data['symbols'][0]['baseAssetPrecision'] minQty = info_data['symbols'][0]['filters'][2]['minQty'] qtyTrueQ = info_data['symbols'][0]['filters'][1]['avgPriceMins'] quantityS = float(qtyTrueQ) quantityB = D.from_float(quantityS).quantize(D(str(pricePrecision)))

teranoib avatar Aug 25 '21 16:08 teranoib

None of the answers you have given have helped me.

I have a variable with the available quantity on futures (av_quantity). And I want that when I create the order quantity = av_quantity and it gives me the "APIError (code = -1111): Precision is over the maximum defined for this asset".

Any suggestion?

sevivq avatar Nov 09 '21 14:11 sevivq

    def round_down( client, quantity, symbol):
        info = client.get_symbol_info(symbol)
        step_size = [float(_['stepSize']) for _ in info['filters'] if _['filterType'] == 'LOT_SIZE'][0]
        step_size = '%.8f' % step_size
        step_size = step_size.rstrip('0')
        decimals = len(step_size.split('.')[1])
        return math.floor(quantity * 10 ** decimals) / 10 ** decimals

lr2bmail avatar Nov 21 '21 14:11 lr2bmail

hi .... I've seen that TP = float(round((tp) , 2)) only works with ethusdt .... how do I make it work for other pairs? how do I use the def described above? can make an example? thanks

jsgaston avatar Jan 02 '22 20:01 jsgaston

Hey ! That. Is bit of a hassle but I found the way by using this on pyhon 3.9.5, THAT IS THE ONLY THING THAT WORKED FOR ME , I WASTED SO MUCH TIME ON THIS SH 1T

There is bina

from binance.helpers import round_step_size

def get_rounded_base_quantity(self):
    return round_step_size((float(self.get_quote_value())/float(self.get_symbol().get_current_price())), float(self.get_symbol().get_step_size()))

On 2 Jan 2022, at 20:09, jsgaston @.***> wrote:

hi .... I've seen that TP = float(round((tp) , 2)) only works with ethusdt .... how do I make it work for other pairs? how do I use the def described above? can make an example? thanks

— Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/296#issuecomment-1003768426, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDNE45YY44VIRDVDKO4M23UUCWGNANCNFSM4FFYSZCQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.

PabloBorda avatar Jan 02 '22 20:01 PabloBorda

HI, can't make it work (just tried with bnbusdt) . I've imported the libreries. ... dont really know what to do to make it work... can u please tell me what I need to do to make it wokr?

jsgaston avatar Jan 02 '22 20:01 jsgaston