Changesets · Branches · Tags · Compare
| Changeset | 6dcb64c30cd2ce893ab36aef1ca073f2408cf3de62801d900852e0aafa9fa10f |
|---|---|
| Author | Matthias <xmatthias@outlook.com> · 2021-04-20 21:41 +02:00 |
| Committer | Matthias <xmatthias@outlook.com> · 2021-04-20 21:41 +02:00 |
| Parents | 35f65cdea290 |
2 files changed
modified freqtrade/persistence/models.py +2 −0
| @@ -547,6 +547,8 @@ | ||
| 547 | 547 | rate=(rate or self.close_rate), |
| 548 | 548 | fee=(fee or self.fee_close) |
| 549 | 549 | ) |
| 550 | + if self.open_trade_value == 0.0: | |
| 551 | + return 0.0 | |
| 550 | 552 | profit_ratio = (close_trade_value / self.open_trade_value) - 1 |
| 551 | 553 | return float(f"{profit_ratio:.8f}") |
| 552 | 554 |
modified tests/test_persistence.py +3 −0
| @@ -388,6 +388,9 @@ | ||
| 388 | 388 | # Test with a custom fee rate on the close trade |
| 389 | 389 | assert trade.calc_profit_ratio(fee=0.003) == 0.06147824 |
| 390 | 390 | |
| 391 | + trade.open_trade_value = 0.0 | |
| 392 | + assert trade.calc_profit_ratio(fee=0.003) == 0.0 | |
| 393 | + | |
| 391 | 394 | |
| 392 | 395 | @pytest.mark.usefixtures("init_persistence") |
| 393 | 396 | def test_clean_dry_run_db(default_conf, fee): |