From 51b94889b27e7453b815afb2a988cee1469481af Mon Sep 17 00:00:00 2001 From: Reigo Reinmets Date: Sun, 23 Jan 2022 17:56:41 +0200 Subject: [PATCH] Just in case also check for closed to avoid counting in canceled orders. --- freqtrade/persistence/models.py | 2 +- tests/test_integration.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index ba5d11caf..c3aabd928 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -587,7 +587,7 @@ class LocalTrade(): tmp_price = o.average or o.price or 0.0 if o.filled is not None: tmp_amount = o.filled - if tmp_amount > 0.0 and tmp_price is not None: + if tmp_amount > 0.0 and tmp_price is not None and o.status == 'closed': total_amount += tmp_amount total_stake += tmp_price * tmp_amount diff --git a/tests/test_integration.py b/tests/test_integration.py index 356ea5c62..ed38f1fec 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -243,6 +243,8 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None: freqtrade.process() trade = Trade.get_trades().first() assert len(trade.orders) == 2 + for o in trade.orders: + assert o.status == "closed" assert trade.stake_amount == 120 # Open-rate averaged between 2.0 and 2.0 * 0.995 @@ -258,7 +260,6 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None: assert trade.orders[1].amount == 60 / ticker_usdt_modif['bid'] assert trade.amount == trade.orders[0].amount + trade.orders[1].amount - assert trade.nr_of_successful_buys == 2 # Sell