Skip to content

Commit

Permalink
Exclude unfilled Trades from "all" /profit
Browse files Browse the repository at this point in the history
These are not actual profits, as it's unclear if the order
will be filled or will be canceled.

Discovered as part of #10165
  • Loading branch information
xmatthias committed May 5, 2024
1 parent 28449f5 commit fa79c48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions freqtrade/rpc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ def _rpc_trade_statistics(
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)
Expand Down
6 changes: 3 additions & 3 deletions tests/rpc/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions tests/rpc/test_rpc_apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit fa79c48

Please sign in to comment.