Fix realized_profit for trade from_json

This commit is contained in:
Matthias 2023-07-14 07:35:58 +02:00
parent bdff34017a
commit 7f0e1c27c6
2 changed files with 4 additions and 0 deletions

View File

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

View File

@ -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]