From 7f0e1c27c6bc64b7dfe478535e6fc03c32f373c5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 14 Jul 2023 07:35:58 +0200 Subject: [PATCH] Fix realized_profit for trade from_json --- freqtrade/persistence/trade_model.py | 3 +++ tests/persistence/test_trade_fromjson.py | 1 + 2 files changed, 4 insertions(+) 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]