From fb3d4083384dceff02ff65fca64021664c66a0dc Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 28 Sep 2022 09:32:07 +0000 Subject: [PATCH] Respect max_open_trades when forceentering closes #7489 --- freqtrade/rpc/rpc.py | 3 +++ tests/rpc/test_rpc.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 48174f6a8..143b11911 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -773,6 +773,9 @@ class RPC: is_short = trade.is_short if not self._freqtrade.strategy.position_adjustment_enable: raise RPCException(f'position for {pair} already open - id: {trade.id}') + else: + if Trade.get_open_trade_count() >= self._config['max_open_trades']: + raise RPCException("Maximum number of trades is reached.") if not stake_amount: # gen stake amount diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index e157470d6..54a4cbe9a 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -1030,6 +1030,7 @@ def test_rpc_count(mocker, default_conf, ticker, fee) -> None: def test_rpc_force_entry(mocker, default_conf, ticker, fee, limit_buy_order_open) -> None: default_conf['force_entry_enable'] = True + default_conf['max_open_trades'] = 0 mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) buy_mm = MagicMock(return_value=limit_buy_order_open) mocker.patch.multiple( @@ -1044,6 +1045,10 @@ def test_rpc_force_entry(mocker, default_conf, ticker, fee, limit_buy_order_open patch_get_signal(freqtradebot) rpc = RPC(freqtradebot) pair = 'ETH/BTC' + with pytest.raises(RPCException, match='Maximum number of trades is reached.'): + rpc._rpc_force_entry(pair, None) + freqtradebot.config['max_open_trades'] = 5 + trade = rpc._rpc_force_entry(pair, None) assert isinstance(trade, Trade) assert trade.pair == pair