Hephyrius / binance_futures_bot

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

"Margin is insufficient" - I have plenty of margin. #9

Open XMVZ opened 3 years ago

XMVZ commented 3 years ago

Please help.. I have plenty of margin room.

{"code":-2019,"msg":"Margin is insufficient."} Encountered Exception ('ExecuteError', '[Executing] -2019: Margin is insufficient.') Traceback (most recent call last): File "C:\Users\mxwo\Documents\Apps\binance_futures_bot\bot.py", line 47, in <module> qty, side, in_position = bf.handle_signal(client, std, File "C:\Users\mxwo\Documents\Apps\binance_futures_bot\bot_functions.py", line 218, in handle_signal execute_order(client, _qty=qty, _side=order_side, _market=market) File "C:\Users\mxwo\Documents\Apps\binance_futures_bot\bot_functions.py", line 107, in execute_order client.post_order(symbol=_market, File "C:\Users\mxwo\Documents\Programs\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:\Users\mxwo\Documents\Programs\lib\site-packages\binance_f\impl\restapiinvoker.py", line 44, in call_sync check_response(json_wrapper) File "C:\Users\mxwo\Documents\Programs\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] -2019: Margin is insufficient.')

XMVZ commented 3 years ago

When I bring it down to 1x it works fine.. However, another question. If it opens a trade (IE SELL: 4.0 $37.902) and the price doesn't hit that/does not fill and continues to go down, does the bot reset? When does it reset? Or does it ever move on past that signal?

Thanks!

XMVZ commented 3 years ago

Looks like trades are occuring via Binance, but nothing is really being printed to console..

XMVZ commented 3 years ago

How does one follow updates in addition to all of these questions?

XMVZ commented 3 years ago

And without changing anything it now does not work at all.

Nai-mul commented 3 years ago

In bot_function.py you need to change qty = 0.1 or something your portfolio persent. In bot_function.py change cross leverage to isolated. then in settings.json change margin type isolated.

Hephyrius commented 3 years ago

In bot_function.py you need to change qty = 0.1 or something your portfolio persent. In bot_function.py change cross leverage to isolated. then in settings.json change margin type isolated.

when I get some time i'll see if i can make this simpler.

abuvanth commented 2 years ago

facing the same issue

kosmetron commented 2 years ago

In my case the "Margin is insufficient." error was occurring when the bot tries to place a trailing stop loss order, following the initial long or short position.

I was able to prevent this from happening by leaving some percentage of the total margin available in the wallet. Effectively, changed the calculate_position_size bot function to not use 99% of the total margin when opening the initial position. Done this by modifying line 119 in bot_functions.py:

From: qty = round(qty * 0.99,8)

To: qty = round(qty * 0.74,8)

And also using ISOLATED margin_type in settings.json.