mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 04:03:55 +00:00
Fix from_json with new attributes
This commit is contained in:
parent
8c0e66008a
commit
5bc84dca56
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user