From fa79c48c8ff6d2349af3a968633115d7b513d49a Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 May 2024 16:45:21 +0200 Subject: [PATCH] Exclude unfilled Trades from "all" /profit These are not actual profits, as it's unclear if the order will be filled or will be canceled. Discovered as part of #10165 --- freqtrade/rpc/rpc.py | 3 +++ tests/rpc/test_rpc.py | 6 +++--- tests/rpc/test_rpc_apiserver.py | 30 +++++++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 490e904de..68ccbd211 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -499,6 +499,9 @@ class RPC: losing_profit += profit_abs else: # Get current rate + if len(trade.select_filled_orders(trade.entry_side)) == 0: + # Skip trades with no filled orders + continue try: current_rate = self._freqtrade.exchange.get_rate( trade.pair, side='exit', is_short=trade.is_short, refresh=False) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 427b46dfa..ffaf7a9bc 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -429,9 +429,9 @@ def test_rpc_trade_statistics(default_conf_usdt, ticker, fee, mocker) -> None: assert pytest.approx(stats['profit_closed_coin']) == 2.74 assert pytest.approx(stats['profit_closed_percent_mean']) == -1.67 assert pytest.approx(stats['profit_closed_fiat']) == 3.014 - assert pytest.approx(stats['profit_all_coin']) == -77.45964918 - assert pytest.approx(stats['profit_all_percent_mean']) == -57.86 - assert pytest.approx(stats['profit_all_fiat']) == -85.205614098 + assert pytest.approx(stats['profit_all_coin']) == -57.40975881 + assert pytest.approx(stats['profit_all_percent_mean']) == -50.83 + assert pytest.approx(stats['profit_all_fiat']) == -63.150734691 assert pytest.approx(stats['winrate']) == 0.666666667 assert pytest.approx(stats['expectancy']) == 0.913333333 assert pytest.approx(stats['expectancy_ratio']) == 0.223308883 diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index fd45cc84a..93b7bb272 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -889,11 +889,11 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): ( True, {'best_pair': 'ETC/BTC', 'best_rate': -0.5, 'best_pair_profit_ratio': -0.005, - 'profit_all_coin': 45.561959, - 'profit_all_fiat': 562462.39126200, 'profit_all_percent_mean': 66.41, - 'profit_all_ratio_mean': 0.664109545, 'profit_all_percent_sum': 398.47, - 'profit_all_ratio_sum': 3.98465727, 'profit_all_percent': 4.56, - 'profit_all_ratio': 0.04556147, 'profit_closed_coin': -0.00673913, + 'profit_all_coin': 15.382312, + 'profit_all_fiat': 189894.6470718, 'profit_all_percent_mean': 49.62, + 'profit_all_ratio_mean': 0.49620917, 'profit_all_percent_sum': 198.48, + 'profit_all_ratio_sum': 1.98483671, 'profit_all_percent': 1.54, + 'profit_all_ratio': 0.01538214, 'profit_closed_coin': -0.00673913, 'profit_closed_fiat': -83.19455985, 'profit_closed_ratio_mean': -0.0075, 'profit_closed_percent_mean': -0.75, 'profit_closed_ratio_sum': -0.015, 'profit_closed_percent_sum': -1.5, 'profit_closed_ratio': -6.739057628404269e-06, @@ -905,11 +905,11 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): ( False, {'best_pair': 'XRP/BTC', 'best_rate': 1.0, 'best_pair_profit_ratio': 0.01, - 'profit_all_coin': -45.79641127, - 'profit_all_fiat': -565356.69712815, 'profit_all_percent_mean': -66.41, - 'profit_all_ratio_mean': -0.6641100666666667, 'profit_all_percent_sum': -398.47, - 'profit_all_ratio_sum': -3.9846604, 'profit_all_percent': -4.58, - 'profit_all_ratio': -0.045796261934205953, 'profit_closed_coin': 0.00073913, + 'profit_all_coin': -15.46546305, + 'profit_all_fiat': -190921.14135225, 'profit_all_percent_mean': -49.62, + 'profit_all_ratio_mean': -0.49620955, 'profit_all_percent_sum': -198.48, + 'profit_all_ratio_sum': -1.9848382, 'profit_all_percent': -1.55, + 'profit_all_ratio': -0.0154654126, 'profit_closed_coin': 0.00073913, 'profit_closed_fiat': 9.124559849999999, 'profit_closed_ratio_mean': 0.0075, 'profit_closed_percent_mean': 0.75, 'profit_closed_ratio_sum': 0.015, 'profit_closed_percent_sum': 1.5, 'profit_closed_ratio': 7.391275897987988e-07, @@ -921,11 +921,11 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): ( None, {'best_pair': 'XRP/BTC', 'best_rate': 1.0, 'best_pair_profit_ratio': 0.01, - 'profit_all_coin': -14.94732578, - 'profit_all_fiat': -184524.7367541, 'profit_all_percent_mean': 0.08, - 'profit_all_ratio_mean': 0.000835751666666662, 'profit_all_percent_sum': 0.5, - 'profit_all_ratio_sum': 0.005014509999999972, 'profit_all_percent': -1.49, - 'profit_all_ratio': -0.014947184841095841, 'profit_closed_coin': -0.00542913, + 'profit_all_coin': -14.87167525, + 'profit_all_fiat': -183590.83096125, 'profit_all_percent_mean': 0.13, + 'profit_all_ratio_mean': 0.0012538324, 'profit_all_percent_sum': 0.5, + 'profit_all_ratio_sum': 0.005015329, 'profit_all_percent': -1.49, + 'profit_all_ratio': -0.0148715350, 'profit_closed_coin': -0.00542913, 'profit_closed_fiat': -67.02260985, 'profit_closed_ratio_mean': 0.0025, 'profit_closed_percent_mean': 0.25, 'profit_closed_ratio_sum': 0.005, 'profit_closed_percent_sum': 0.5, 'profit_closed_ratio': -5.429078808526421e-06,