From 9f6f3e0862b27693706ecbb44be0856834d05717 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 20 Apr 2021 21:41:18 +0200 Subject: [PATCH] Address ZeroDivisionExceptiond closes #4764 closes #4617 --- freqtrade/persistence/models.py | 2 ++ tests/test_persistence.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 49d3e2d62..e7fd488c7 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -547,6 +547,8 @@ class LocalTrade(): rate=(rate or self.close_rate), fee=(fee or self.fee_close) ) + if self.open_trade_value == 0.0: + return 0.0 profit_ratio = (close_trade_value / self.open_trade_value) - 1 return float(f"{profit_ratio:.8f}") diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 3b90f368f..dad0e275e 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -388,6 +388,9 @@ def test_calc_profit_ratio(limit_buy_order, limit_sell_order, fee): # Test with a custom fee rate on the close trade assert trade.calc_profit_ratio(fee=0.003) == 0.06147824 + trade.open_trade_value = 0.0 + assert trade.calc_profit_ratio(fee=0.003) == 0.0 + @pytest.mark.usefixtures("init_persistence") def test_clean_dry_run_db(default_conf, fee):