Address ZeroDivisionExceptiond

closes #4764 closes #4617
This commit is contained in:
Matthias 2021-04-20 21:41:18 +02:00
parent b230558294
commit 9f6f3e0862
2 changed files with 5 additions and 0 deletions

View File

@ -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}")

View File

@ -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):