diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index c9e08bf69..bfba1380d 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1399,6 +1399,10 @@ class FreqtradeBot(LoggingMixin): cancelled = False order_obj = trade.select_order_by_order_id(order['id']) + if not order_obj: + raise DependencyException( + f"Order_obj not found for {order['id']}. This should not have happened.") + sub_trade = order_obj.amount != trade.amount self._notify_exit_cancel( trade, @@ -1590,10 +1594,8 @@ class FreqtradeBot(LoggingMixin): 'stake_currency': self.config['stake_currency'], 'fiat_currency': self.config.get('fiat_display_currency'), 'sub_trade': sub_trade, + 'cumulative_profit': trade.realized_profit, } - if sub_trade: - # TODO: this should not be conditional. - msg['cumulative_profit'] = trade.realized_profit # Send the message self.rpc.send_msg(msg) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 06e60f85c..3204b94e8 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -961,6 +961,7 @@ def test_telegram_forceexit_handle(default_conf, update, ticker, fee, 'close_rate': ANY, 'stake_amount': 0.0009999999999054, 'sub_trade': False, + 'cumulative_profit': 0.0, } == last_msg @@ -1031,7 +1032,8 @@ def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee, 'close_date': ANY, 'close_rate': ANY, 'stake_amount': 0.0009999999999054, - 'sub_trade': False + 'sub_trade': False, + 'cumulative_profit': 0.0, } == last_msg @@ -1092,7 +1094,8 @@ def test_forceexit_all_handle(default_conf, update, ticker, fee, mocker) -> None 'close_date': ANY, 'close_rate': ANY, 'stake_amount': 0.0009999999999054, - 'sub_trade': False + 'sub_trade': False, + 'cumulative_profit': 0.0, } == msg diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 35089b143..6d297b621 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3249,6 +3249,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_ 'close_date': ANY, 'close_rate': ANY, 'sub_trade': False, + 'cumulative_profit': 0.0, 'stake_amount': pytest.approx(60), } == last_msg @@ -3311,6 +3312,7 @@ def test_execute_trade_exit_down(default_conf_usdt, ticker_usdt, fee, ticker_usd 'close_date': ANY, 'close_rate': ANY, 'sub_trade': False, + 'cumulative_profit': 0.0, 'stake_amount': pytest.approx(60), } == last_msg @@ -3394,6 +3396,7 @@ def test_execute_trade_exit_custom_exit_price( 'close_date': ANY, 'close_rate': ANY, 'sub_trade': False, + 'cumulative_profit': 0.0, 'stake_amount': pytest.approx(60), } == last_msg @@ -3464,6 +3467,7 @@ def test_execute_trade_exit_down_stoploss_on_exchange_dry_run( 'close_date': ANY, 'close_rate': ANY, 'sub_trade': False, + 'cumulative_profit': 0.0, 'stake_amount': pytest.approx(60), } == last_msg @@ -3725,6 +3729,7 @@ def test_execute_trade_exit_market_order( 'close_date': ANY, 'close_rate': ANY, 'sub_trade': False, + 'cumulative_profit': 0.0, 'stake_amount': pytest.approx(60), } == last_msg @@ -4719,9 +4724,8 @@ def test_order_book_exit_pricing( return_value={'bids': [[]], 'asks': [[]]}) with pytest.raises(PricingError): freqtrade.handle_trade(trade) - pair = 'ETH/USDT' assert log_has_re( - rf"{pair} - Exit Price at location 1 from orderbook could not be determined\..*", + r"ETH/USDT - Exit Price at location 1 from orderbook could not be determined\..*", caplog)