tudorelu / pyjuque

⚡ Open Source Algorithmic Trading Bot for Python.
MIT License
456 stars 90 forks source link

error on tryExitOrder; cannot place limit order after buy fill due to balance error #16

Open Joris-H opened 3 years ago

Joris-H commented 3 years ago

Running the bot on multiple symbols. 1m timeframe. After a while all the filled buy orders get this error:

INFO:pyjuque.Engine.BotController:FILLED BUY order on BNB/USDT, try exit. INFO:pyjuque.Engine.BotController:Error placing order for BNB/USDT: (<class 'ccxt.base.errors.InsufficientFunds'>, InsufficientFunds('binance Account has insufficient balance for requested action.'), <traceback object at 0x7f9db3739ec0>)

I tried playing around with removing take profit, changing 'signal_distance' to market orders. But the issue remains.

The bot is unable to evaluate stop loss or exit signals after this error occurred for a symbol.

Help is appreciated!

Thanks

Joris-H commented 3 years ago

The problem might be here, that the quantity calculation does not take fees into account, resulting in a too low budget of the symbol. I noticed that Binance does not always take fees in the form of BNB but sometimes in the form of the target symbol.

def computeMatchingOrderQuantity(self, order):
        """ Compute exit quantity so that also partially 
        filled orders can be handled."""
        if order.side == 'buy':
            exit_quantity = order.executed_quantity
        elif order.side == 'sell':
            exit_quantity = order.original_quantity \
                - order.executed_quantity
        return exit_quantity
tudorelu commented 3 years ago

Hey Joris, thanks a lot for trying pyjuque!

Could you please paste the bot_config that you used to set up this bot?

One potential suggestion is that you set your bot up using a starting_balance parameter that is less than what you actually hold in your inventory. Also, all the symbols in the bot_config should be ending in the same coin.

tudorelu commented 3 years ago

I see now that that might not necessarily be the fix I need to put some checks in place regarding how much the fees cost and what can be sold on top of that.

What version of pyjuque are you running?

mikedigriz commented 3 years ago

Have same issue Now i clean up database with:

Step 1: it need for we can clean database PRAGMA foreign_keys = OFF;

Step 2: look at breaked orders SELECT * FROM [order] WHERE status = 'closed' AND side = 'buy' AND is_entry = 1 AND is_closed = 0; and delete all of them DELETE FROM [order] WHERE status = 'closed' AND side = 'buy' AND is_entry = 1 AND is_closed = 0;