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

[testnet] Someting wrong with client.futures_create_order()

Open bmw7 opened this issue 4 years ago • 5 comments

I use my testnet account , and run the function futures_create_order() for the symbol BTCUSDT, it is all OK. The code is following:

client.futures_create_order(symbol='BTCUSDT', side='BUY', positionSide='LONG',type='MARKET',quantity=20)

But when I use it for the symbol SOLUSDT:

client.futures_create_order(symbol='SOLUSDT', side='BUY', positionSide='LONG',type='MARKET',quantity=20)

Error message appears:

binance.exceptions.BinanceAPIException: APIError(code=-4131): The counterparty's best price does not meet the PERCENT_PRICE filter limit.

How to solve the problem? thanks!!!

bmw7 avatar Sep 15 '21 07:09 bmw7

Anyone else encountered this? Is it only for the testnet that this error occurs? Any help would be greatly appreciated.

predirsec avatar Jan 16 '22 19:01 predirsec

Check the symbol info using client.get_symbol_info and find PERCENT_PRICE in it.

The price you send for the order should match the PERCENT_PRICE rule, as well as the PRICE_FILTER rule.

Animouse31 avatar Feb 24 '22 08:02 Animouse31

as you can see from @bmw7 sample order properties, there's no price element in order object because it's an MARKET order hence Binance is giving this kind of sh*ty errors of there's a high volatility.

I experienced it many times in production and still couldn't find any solution yet.

ne0c0de avatar May 04 '22 00:05 ne0c0de

@ne0c0de I'm experiencing the same issue, did you ever find a solution for this?

lpellis avatar Aug 11 '22 14:08 lpellis

Unfortunately there's no solution, Binance doesn't allow to open position and giving this kind of false errors to manipulate the developers when there's high volatility.

ne0c0de avatar Aug 11 '22 20:08 ne0c0de

Hey there!

I had the same error a few days ago and found a solution. Maybe it would help some guys ;) First you need to call exchangeInfo endpoint to get the information of the filters on the symbol:

{
         "filterType": "PERCENT_PRICE",
         "multiplierUp": "5",
         "multiplierDown": "0.2",
         "avgPriceMins": 5
       },

You can see "multiplierUp" and "multiplierDown" value. So if the current price is 200 with a multiplierUp of 5 your price must be less than 200 * 5 = 1000. With the multiplierDown of 0.2 your price must be more than 200 * 0.2 = 40.

So all in, the price of your order must be in range:

40 <= your_price <= 1000

And I integrated in my script with:

if round((quantity * leverage) / asset_price, symbolData["quantityPrecision"]) > (float(percentPrice["multiplierUp"])*asset_price):
            quantityThreated = round(float(percentPrice["multiplierUp"])*asset_price, symbolData["quantityPrecision"])
            print("Up", quantityThreated)
        if round((quantity * leverage) / asset_price, symbolData["quantityPrecision"]) < (float(percentPrice["multiplierDown"])*asset_price):
            quantityThreated = round(float(percentPrice["multiplierDown"])*asset_price, symbolData["quantityPrecision"])
            print("Down", quantityThreated)
        if round((quantity * leverage) / asset_price, symbolData["quantityPrecision"]) > float(lotSize["maxQty"]):
            quantityThreated = float(lotSize["maxQty"])
        if round((quantity * leverage) / asset_price, symbolData["quantityPrecision"]) < float(lotSize["minQty"]):
            quantityThreated = float(lotSize["minQty"])

Hope it will help !

moijesuis2enmoi avatar Jan 26 '23 21:01 moijesuis2enmoi

Nice solution and I hope it will help but the problem here is we're giving market order which is means that whatever the price is, just execute my order but Binance rejects it. This can happen only if there's high volatility on the price

ne0c0de avatar Jan 26 '23 22:01 ne0c0de

By "your price", you mean the quantity/position size or bid/ask price? @MOIJESUIS2ENMOI

ambiflextrous avatar Feb 18 '23 08:02 ambiflextrous