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

APIError(code=-4014): Price not increased by tick size

Open Aarron-shaw opened this issue 4 years ago • 9 comments

I get tick size issue with certain coins at random times when setting futures limit orders.

I'm using this function to get the precise price for my limit order.

`def get_price_precision(symbol,price):

info = client.futures_exchange_info()
for item in info['symbols']:
    if(item['symbol'] == symbol):
        

        pricePrecision = item['pricePrecision']
        quantityS = price
        quantityB = "{:0.0{}f}".format(quantityS, pricePrecision)
        #print(item['symbol'],quantityS, quantityB)
        return float(quantityB)`

I'm expecting the order to be valid, in this eth example 3093.42 is a valid limit price as far as I can see, the price was 3122.53. at the time of setting the buy order.

[Sun Jan  9 01:10:07 2022 - trade() - Order, Sym=ETHUSDT, price=3093.42, side=BUY, qty=0.011]
[Sun Jan  9 01:10:08 2022 - trade() - Failed to make order: APIError(code=-4014): Price not increased by tick size.]

Aarron-shaw avatar Jan 09 '22 01:01 Aarron-shaw

res = client.futures_create_order( symbol=cur, side=action, type='LIMIT', timeInForce='GTC', quantity=min, price=price)

The limit order

Aarron-shaw avatar Jan 09 '22 01:01 Aarron-shaw

Solved using binance helper.

def get_min_quant(symbol):
    info = client.futures_exchange_info()
    for item in info['symbols']:
        if(item['symbol'] == symbol):
            for f in item['filters']:
                if f['filterType'] == 'LOT_SIZE':
                
                    return f['minQty']

tick = get_ticksize(cur)
price = round_step_size(float(price), float(tick))


Aarron-shaw avatar Jan 09 '22 19:01 Aarron-shaw

Hello Aarron! I have the same problem as you, but I can't find a way to solve it! Can you share the function code with me?:

get_ticksize round_step_size

Maybe looking at your code I can guide me a bit. I'm programming it in Dart

I appreciate it a lot!

dami0089 avatar Jan 19 '22 21:01 dami0089

The information that the console gives me is the following:

"code":-4014,"msg":"Price not increased by tick size."

dami0089 avatar Jan 19 '22 21:01 dami0089

Hello Aarron! I have the same problem as you, but I can't find a way to solve it! Can you share the function code with me?:

get_ticksize round_step_size

Maybe looking at your code I can guide me a bit. I'm programming it in Dart

I appreciate it a lot!

Sorry it appears I pasted the wrong function.

https://github.com/sammchardy/python-binance/blob/master/binance/helpers.py

round_step_size is here, you can import it using from binance.helpers import round_step_size

for some reason I couldn't import it and just copy and pasted the function from the source code.

def get_ticksize(symbol):
    info = client.futures_exchange_info()
    for item in info['symbols']:
        if(item['symbol'] == symbol):
            for f in item['filters']:
                if f['filterType'] == 'PRICE_FILTER':
                
                    return f['tickSize']

Hope this helps.

Aarron-shaw avatar Jan 19 '22 21:01 Aarron-shaw

Using round_step_size with the tick size works. Here is the full code I'm using:

from binance.helpers import round_step_size


def get_tick_size(symbol: str) -> float:
    info = client.futures_exchange_info()

    for symbol_info in info['symbols']:
        if symbol_info['symbol'] == symbol:
            for symbol_filter in symbol_info['filters']:
                if symbol_filter['filterType'] == 'PRICE_FILTER':
                    return float(symbol_filter['tickSize'])


def get_rounded_price(symbol: str, price: float) -> float:
    return round_step_size(price, get_tick_size(symbol))


price = get_rounded_price(symbol, price)

For spot orders you can avoid looping through all the symbols if you use client.get_symbol_info(symbol):

def get_tick_size(symbol: str) -> float:
    symbol_info = client.get_symbol_info(symbol)

    for symbol_filter in symbol_info['filters']:
        if symbol_filter['filterType'] == 'PRICE_FILTER':
            return float(symbol_filter['tickSize'])

mhawry avatar Jan 26 '22 14:01 mhawry

Getting 'tickSize' without using a for loop

tickSize = my_client.get_symbol_info(symbol=symbol) tickSize = tickSize['filters'] tickSize = float(tickSize[0]['tickSize'])

RichestSmoke avatar Nov 29 '22 00:11 RichestSmoke

@RichestSmoke use price + or - tickSize ?

shunshunuuu avatar Jan 05 '23 08:01 shunshunuuu

Here is my code to apply this to sl and tp

# get tick size and round tp and sl to tick size
tickSize = float(client.get_symbol_info(symbol=symbol)['filters'][0]['tickSize'])
rounded_tp = round_step_size(float(tp), tickSize)
rounded_sl = round_step_size(float(sl), tickSize)

Karlheinzniebuhr avatar Mar 08 '23 17:03 Karlheinzniebuhr