From 12b471c64b7d87a888224ad9de034e604b10fd4f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Nov 2022 09:28:14 +0100 Subject: [PATCH] Prevent 2 parallel open orders through forceentry this leads to forgetting the prior order closes #7765 --- 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 a0824bcc1..1d3f36844 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -774,6 +774,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}') + if trade.open_order_id is not None: + raise RPCException(f'position for {pair} already open - id: {trade.id} ' + f'and has open order {trade.open_order_id}') else: if Trade.get_open_trade_count() >= self._config['max_open_trades']: raise RPCException("Maximum number of trades is reached.") diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index ef6c8b204..8828b6f33 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -1066,6 +1066,11 @@ def test_rpc_force_entry(mocker, default_conf, ticker, fee, limit_buy_order_open trade = rpc._rpc_force_entry(pair, 0.0001, order_type='limit', stake_amount=0.05) assert trade.stake_amount == 0.05 assert trade.buy_tag == 'force_entry' + assert trade.open_order_id == 'mocked_limit_buy' + + freqtradebot.strategy.position_adjustment_enable = True + with pytest.raises(RPCException, match=r'position for LTC/BTC already open.*open order.*'): + rpc._rpc_force_entry(pair, 0.0001, order_type='limit', stake_amount=0.05) # Test not buying pair = 'XRP/BTC'