Fix from_json with new attributes

This commit is contained in:
Matthias 2023-07-10 06:38:18 +02:00
parent 8c0e66008a
commit 5bc84dca56
2 changed files with 9 additions and 2 deletions

View File

@ -1708,6 +1708,7 @@ class Trade(ModelBase, LocalTrade):
order_obj = Order( order_obj = Order(
amount=order["amount"], amount=order["amount"],
ft_amount=order["amount"],
ft_order_side=order["ft_order_side"], ft_order_side=order["ft_order_side"],
ft_pair=order["pair"], ft_pair=order["pair"],
ft_is_open=order["is_open"], ft_is_open=order["is_open"],
@ -1722,6 +1723,7 @@ class Trade(ModelBase, LocalTrade):
if order["order_filled_timestamp"] else None), if order["order_filled_timestamp"] else None),
order_type=order["order_type"], order_type=order["order_type"],
price=order["price"], price=order["price"],
ft_price=order["price"],
remaining=order["remaining"], remaining=order["remaining"],
) )
trade.orders.append(order_obj) trade.orders.append(order_obj)

View File

@ -1,8 +1,11 @@
from datetime import datetime, timezone from datetime import datetime, timezone
import pytest
from freqtrade.persistence.trade_model import Trade from freqtrade.persistence.trade_model import Trade
@pytest.mark.usefixtures("init_persistence")
def test_trade_fromjson(): def test_trade_fromjson():
"""Test the Trade.from_json() method.""" """Test the Trade.from_json() method."""
trade_string = """{ trade_string = """{
@ -168,14 +171,16 @@ def test_trade_fromjson():
] ]
}""" }"""
trade = Trade.from_json(trade_string) trade = Trade.from_json(trade_string)
Trade.session.add(trade)
Trade.commit()
assert trade.id == 25 assert trade.id == 25
assert trade.pair == 'ETH/USDT' assert trade.pair == 'ETH/USDT'
assert trade.open_date == datetime(2022, 10, 18, 9, 12, 42, tzinfo=timezone.utc) assert trade.open_date_utc == datetime(2022, 10, 18, 9, 12, 42, tzinfo=timezone.utc)
assert isinstance(trade.open_date, datetime) assert isinstance(trade.open_date, datetime)
assert trade.exit_reason == 'no longer good' assert trade.exit_reason == 'no longer good'
assert len(trade.orders) == 5 assert len(trade.orders) == 5
last_o = trade.orders[-1] last_o = trade.orders[-1]
assert last_o.order_filled_date == datetime(2022, 10, 18, 9, 45, 22, tzinfo=timezone.utc) assert last_o.order_filled_utc == datetime(2022, 10, 18, 9, 45, 22, tzinfo=timezone.utc)
assert isinstance(last_o.order_date, datetime) assert isinstance(last_o.order_date, datetime)