Add check to ensure close_profit_abs is filled on closed trades

Technically, this should not be possible, but #4554 shows it is.

closes #4554
This commit is contained in:
Matthias 2021-03-16 19:24:03 +01:00
parent dd5873ef24
commit 79d4585dad
2 changed files with 10 additions and 3 deletions

View File

@ -71,7 +71,8 @@ class Wallets:
# TODO: potentially remove the ._log workaround to determine backtest mode. # TODO: potentially remove the ._log workaround to determine backtest mode.
if self._log: if self._log:
closed_trades = Trade.get_trades_proxy(is_open=False) closed_trades = Trade.get_trades_proxy(is_open=False)
tot_profit = sum([trade.close_profit_abs for trade in closed_trades]) tot_profit = sum(
[trade.close_profit_abs for trade in closed_trades if trade.close_profit_abs])
else: else:
tot_profit = LocalTrade.total_profit tot_profit = LocalTrade.total_profit
tot_in_trades = sum([trade.stake_amount for trade in open_trades]) tot_in_trades = sum([trade.stake_amount for trade in open_trades])

View File

@ -1066,8 +1066,14 @@ def test_get_trades_proxy(fee, use_db):
assert isinstance(trades[0], Trade) assert isinstance(trades[0], Trade)
assert len(Trade.get_trades_proxy(is_open=True)) == 4 trades = Trade.get_trades_proxy(is_open=True)
assert len(Trade.get_trades_proxy(is_open=False)) == 2 assert len(trades) == 4
assert trades[0].is_open
trades = Trade.get_trades_proxy(is_open=False)
assert len(trades) == 2
assert not trades[0].is_open
opendate = datetime.now(tz=timezone.utc) - timedelta(minutes=15) opendate = datetime.now(tz=timezone.utc) - timedelta(minutes=15)
assert len(Trade.get_trades_proxy(open_date=opendate)) == 3 assert len(Trade.get_trades_proxy(open_date=opendate)) == 3