Elffuss BraidHub

kikocis/freqtrade public

Address ZeroDivisionExceptiond

closes #4764 closes #4617
Changeset6dcb64c30cd2ce893ab36aef1ca073f2408cf3de62801d900852e0aafa9fa10f
AuthorMatthias <xmatthias@outlook.com> · 2021-04-20 21:41 +02:00
CommitterMatthias <xmatthias@outlook.com> · 2021-04-20 21:41 +02:00
Parents35f65cdea290

Browse the files at this changeset

2 files changed

modified freqtrade/persistence/models.py +2 −0
@@ -547,6 +547,8 @@
547547 rate=(rate or self.close_rate),
548548 fee=(fee or self.fee_close)
549549 )
550+ if self.open_trade_value == 0.0:
551+ return 0.0
550552 profit_ratio = (close_trade_value / self.open_trade_value) - 1
551553 return float(f"{profit_ratio:.8f}")
552554
modified tests/test_persistence.py +3 −0
@@ -388,6 +388,9 @@
388388 # Test with a custom fee rate on the close trade
389389 assert trade.calc_profit_ratio(fee=0.003) == 0.06147824
390390
391+ trade.open_trade_value = 0.0
392+ assert trade.calc_profit_ratio(fee=0.003) == 0.0
393+
391394
392395 @pytest.mark.usefixtures("init_persistence")
393396 def test_clean_dry_run_db(default_conf, fee):