Update trade_close test to include orders

This commit is contained in:
Matthias 2022-07-23 15:27:52 +02:00
parent 24a786bedd
commit 7682c9ace7

View File

@ -628,14 +628,41 @@ def test_trade_close(limit_buy_order_usdt, limit_sell_order_usdt, fee):
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=10), open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=10),
interest_rate=0.0005, interest_rate=0.0005,
exchange='binance', exchange='binance',
trading_mode=margin trading_mode=margin,
leverage=1.0,
) )
trade.orders.append(Order(
ft_order_side=trade.entry_side,
order_id=f'{trade.pair}-{trade.entry_side}-{trade.open_date}',
ft_pair=trade.pair,
amount=trade.amount,
filled=trade.amount,
remaining=0,
price=trade.open_rate,
average=trade.open_rate,
status="closed",
order_type="limit",
side=trade.entry_side,
))
trade.orders.append(Order(
ft_order_side=trade.exit_side,
order_id=f'{trade.pair}-{trade.exit_side}-{trade.open_date}',
ft_pair=trade.pair,
amount=trade.amount,
filled=trade.amount,
remaining=0,
price=2.2,
average=2.2,
status="closed",
order_type="limit",
side=trade.exit_side,
))
assert trade.close_profit is None assert trade.close_profit is None
assert trade.close_date is None assert trade.close_date is None
assert trade.is_open is True assert trade.is_open is True
trade.close(2.2) trade.close(2.2)
assert trade.is_open is False assert trade.is_open is False
assert trade.close_profit == round(0.0945137157107232, 8) assert pytest.approx(trade.close_profit) == 0.094513715
assert trade.close_date is not None assert trade.close_date is not None
new_date = arrow.Arrow(2020, 2, 2, 15, 6, 1).datetime, new_date = arrow.Arrow(2020, 2, 2, 15, 6, 1).datetime,