Hephyrius / binance_futures_bot

A bot that trades leveraged USDT futures markets on binance.
302 stars 124 forks source link

Precision is over the maximum defined for this asset #14

Open ciclanoio opened 3 years ago

ciclanoio commented 3 years ago

I'm running tests but I still haven't got it working, it's not clear to me the amount to be invested in the order and I get this error. Any advice is welcome.

{"code":-1111,"msg":"Precision is over the maximum defined for this asset."} Erro: ('ExecuteError', '[Executing] -1111: Precision is over the maximum defined for this asset.') Traceback (most recent call last): File "C:\binance_futures_bot-main\bot.py", line 44, in qty, side, in_position = bf.handle_signal(client, std, File "C:\binance_futures_bot-main\bot_functions.py", line 218, in handle_signal execute_order(client, _qty=qty, _side=order_side, _market=market) File "C:\binance_futures_bot-main\bot_functions.py", line 107, in execute_order client.post_order(symbol=_market, File "C:\binance_futures_bot-main\venv\lib\site-packages\binance_f\requestclient.py", line 246, in post_order response = call_sync(self.request_impl.post_order(symbol, side, ordertype, File "C:\binance_futures_bot-main\venv\lib\site-packages\binance_f\impl\restapiinvoker.py", line 44, in call_sync check_response(json_wrapper) File "C:\binance_futures_bot-main\venv\lib\site-packages\binance_f\impl\restapiinvoker.py", line 21, in check_response raise BinanceApiException(BinanceApiException.EXEC_ERROR, "[Executing] " + str(code) + ": " + msg) binance_f.exception.binanceapiexception.BinanceApiException: ('ExecuteError', '[Executing] -1111: Precision is over the maximum defined for this asset.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\binance_futures_bot-main\bot.py", line 118, in time.sleep(15)

Hephyrius commented 3 years ago

What market/assets are you trying to trade?

Nai-mul commented 3 years ago

It's happen if you trade eth/usdt, btc/usdt or xrp. Bot just can't place exact amount order. In bot_functions.py change qty = 0.05 or 0.06 or 0.07 like this way.

riuslol commented 3 years ago

im having the same issue, which line we should change exactly and what does it mean basically

Nai-mul commented 3 years ago

in bot_functions.py you need to change qty=qty 0.99 to qty=qty 0.98 or qty=qty 0.97 or qty=qty 0.96 like this way.

the bot are basically failed to calculate how much quantity need to place.

in bot_functions.py you can search buy Ctrl+f by this line qty=qty * 0.99 and then change it.

lid2000 commented 2 years ago

I think this is happening because floats aren't great at accuracy in some cases (vs decimals, more info here). What I suspect happens (unverified, just speculating) is the round_to_precision function in bot_functions.py uses string formatting to strip the position size down to 8 significant digits (if it was rounded instead, there's a chance it would round up and the order wouldn't go through as it's more than the wallet has), but then you see the qty figure gets cast as a float before being passed on to the Binance client - in the case of certain difficult-to-represent-in-binary numbers, this'll cause it to flip out and be some gigantic long fraction like 16.6999999999999999999999999) and then Binance rejects it.

However, turns out you can pass a string to Binance and it'll accept it - I removed the float(new_qty) casting on line 167 so it just returns the number as a string instead, and I haven't had precision issues since.

abuvanth commented 2 years ago

I think this is happening because floats aren't great at accuracy in some cases (vs decimals, more info here). What I suspect happens (unverified, just speculating) is the round_to_precision function in bot_functions.py uses string formatting to strip the position size down to 8 significant digits (if it was rounded instead, there's a chance it would round up and the order wouldn't go through as it's more than the wallet has), but then you see the qty figure gets cast as a float before being passed on to the Binance client - in the case of certain difficult-to-represent-in-binary numbers, this'll cause it to flip out and be some gigantic long fraction like 16.6999999999999999999999999) and then Binance rejects it.

However, turns out you can pass a string to Binance and it'll accept it - I removed the float(new_qty) casting on line 167 so it just returns the number as a string instead, and I haven't had precision issues since.

It works. Just return new_qty instead of float(new_qty).