From 156c20288914019e0146a343740bae5594c25936 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 15 Jun 2023 20:46:35 -0400 Subject: [PATCH] fix more tests including process_open_trade_positions --- freqtrade/freqtradebot.py | 19 +++++++------------ tests/test_freqtradebot.py | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index c444509c3..f8b370de3 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -615,7 +615,8 @@ class FreqtradeBot(LoggingMixin): # Walk through each pair and check if it needs changes for trade in Trade.get_open_trades(): # If there is any open orders, wait for them to finish. - if trade.open_order_id is None: + # TODO Remove to allow mul open orders + if trade.open_entry_or_exit_orders_count == 0: try: self.check_and_call_adjust_trade_position(trade) except DependencyException as exception: @@ -1213,7 +1214,6 @@ class FreqtradeBot(LoggingMixin): """ logger.debug('Handling stoploss on exchange %s ...', trade) - stoploss_order = None try: @@ -1236,16 +1236,11 @@ class FreqtradeBot(LoggingMixin): self.handle_protections(trade.pair, trade.trade_direction) return True - print("***************open_orders DEBUG***************") - print(f"trade.open_orders: {trade.open_orders}") - print(f"trade.open_orders_count: {trade.open_orders_count}") - print(f"trade.open_entry_or_exit_orders_count: {trade.open_entry_or_exit_orders_count}") - - # if trade.open_entry_or_exit_orders_count != 0 or not trade.is_open: - # Trade has an open Buy or Sell order, Stoploss-handling can't happen in this case - # as the Amount on the exchange is tied up in another trade. - # The trade can be closed already (sell-order fill confirmation came in this iteration) - # return False + if trade.open_entry_or_exit_orders_count != 0 or not trade.is_open: + # Trade has an open Buy or Sell order, Stoploss-handling can't happen in this case + # as the Amount on the exchange is tied up in another trade. + # The trade can be closed already (sell-order fill confirmation came in this iteration) + return False # If enter order is fulfilled but there is no stoploss, we add a stoploss on exchange if not stoploss_order: diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index b8a729372..92c28b170 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -5958,7 +5958,7 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None: assert len(orders) == 2 trade = Trade.session.scalars(select(Trade)).first() assert trade - assert trade.open_order_id == '651' + assert '651' in trade.open_orders_ids assert trade.open_rate == 11 assert trade.amount == 10 assert trade.stake_amount == 110 @@ -5995,7 +5995,7 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None: # Assert trade is as expected trade = Trade.session.scalars(select(Trade)).first() assert trade - assert trade.open_order_id == '651' + assert '651' in trade.open_orders_ids assert trade.open_rate == 11 assert trade.amount == 10 assert trade.stake_amount == 110