Improve logic for from_json special case
This commit is contained in:
@@ -1299,12 +1299,12 @@ class Trade(ModelBase, LocalTrade):
|
|||||||
Float(), nullable=True, default=None) # type: ignore
|
Float(), nullable=True, default=None) # type: ignore
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
from_json = kwargs.pop('__FROM_JSON', None)
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.realized_profit = 0
|
if not from_json:
|
||||||
self.recalc_open_trade_value()
|
# Skip recalculation when loading from json
|
||||||
if 'realized_profit' in kwargs:
|
self.realized_profit = 0
|
||||||
# reset realized profit for from_json calls
|
self.recalc_open_trade_value()
|
||||||
self.realized_profit = kwargs['realized_profit']
|
|
||||||
|
|
||||||
@validates('enter_tag', 'exit_reason')
|
@validates('enter_tag', 'exit_reason')
|
||||||
def validate_string_len(self, key, value):
|
def validate_string_len(self, key, value):
|
||||||
@@ -1658,6 +1658,7 @@ class Trade(ModelBase, LocalTrade):
|
|||||||
import rapidjson
|
import rapidjson
|
||||||
data = rapidjson.loads(json_str)
|
data = rapidjson.loads(json_str)
|
||||||
trade = cls(
|
trade = cls(
|
||||||
|
__FROM_JSON=True,
|
||||||
id=data["trade_id"],
|
id=data["trade_id"],
|
||||||
pair=data["pair"],
|
pair=data["pair"],
|
||||||
base_currency=data["base_currency"],
|
base_currency=data["base_currency"],
|
||||||
|
|||||||
Reference in New Issue
Block a user