diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index 6e9c2970d..bb6837792 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -1302,6 +1302,9 @@ class Trade(ModelBase, LocalTrade): super().__init__(**kwargs) self.realized_profit = 0 self.recalc_open_trade_value() + if 'realized_profit' in kwargs: + # reset realized profit for from_json calls + self.realized_profit = kwargs['realized_profit'] @validates('enter_tag', 'exit_reason') def validate_string_len(self, key, value): diff --git a/tests/persistence/test_trade_fromjson.py b/tests/persistence/test_trade_fromjson.py index 2edfd18b8..24522e744 100644 --- a/tests/persistence/test_trade_fromjson.py +++ b/tests/persistence/test_trade_fromjson.py @@ -179,6 +179,7 @@ def test_trade_fromjson(): assert trade.open_date_utc == datetime(2022, 10, 18, 9, 12, 42, tzinfo=timezone.utc) assert isinstance(trade.open_date, datetime) assert trade.exit_reason == 'no longer good' + assert trade.realized_profit == 2.76315361 assert len(trade.orders) == 5 last_o = trade.orders[-1]