Adapt Tests for new mandatory columns

This commit is contained in:
Matthias 2023-01-08 13:55:52 +01:00
parent 305b067e48
commit ad49541947
5 changed files with 27 additions and 5 deletions

View File

@ -2606,6 +2606,8 @@ def open_trade():
ft_order_side='buy', ft_order_side='buy',
ft_pair=trade.pair, ft_pair=trade.pair,
ft_is_open=False, ft_is_open=False,
ft_amount=trade.amount,
ft_price=trade.open_rate,
order_id='123456789', order_id='123456789',
status="closed", status="closed",
symbol=trade.pair, symbol=trade.pair,
@ -2642,6 +2644,8 @@ def open_trade_usdt():
ft_order_side='buy', ft_order_side='buy',
ft_pair=trade.pair, ft_pair=trade.pair,
ft_is_open=False, ft_is_open=False,
ft_amount=trade.amount,
ft_price=trade.open_rate,
order_id='123456789', order_id='123456789',
status="closed", status="closed",
symbol=trade.pair, symbol=trade.pair,
@ -2659,6 +2663,8 @@ def open_trade_usdt():
ft_order_side='exit', ft_order_side='exit',
ft_pair=trade.pair, ft_pair=trade.pair,
ft_is_open=True, ft_is_open=True,
ft_amount=trade.amount,
ft_price=trade.open_rate,
order_id='123456789_exit', order_id='123456789_exit',
status="open", status="open",
symbol=trade.pair, symbol=trade.pair,

View File

@ -1870,11 +1870,13 @@ def test_get_exit_order_count(fee, is_short):
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
def test_update_order_from_ccxt(caplog): def test_update_order_from_ccxt(caplog):
# Most basic order return (only has orderid) # Most basic order return (only has orderid)
o = Order.parse_from_ccxt_object({'id': '1234'}, 'ADA/USDT', 'buy') o = Order.parse_from_ccxt_object({'id': '1234'}, 'ADA/USDT', 'buy', 20.01, 1234.6)
assert isinstance(o, Order) assert isinstance(o, Order)
assert o.ft_pair == 'ADA/USDT' assert o.ft_pair == 'ADA/USDT'
assert o.ft_order_side == 'buy' assert o.ft_order_side == 'buy'
assert o.order_id == '1234' assert o.order_id == '1234'
assert o.ft_price == 1234.6
assert o.ft_amount == 20.01
assert o.ft_is_open assert o.ft_is_open
ccxt_order = { ccxt_order = {
'id': '1234', 'id': '1234',
@ -1888,13 +1890,15 @@ def test_update_order_from_ccxt(caplog):
'status': 'open', 'status': 'open',
'timestamp': 1599394315123 'timestamp': 1599394315123
} }
o = Order.parse_from_ccxt_object(ccxt_order, 'ADA/USDT', 'buy') o = Order.parse_from_ccxt_object(ccxt_order, 'ADA/USDT', 'buy', 20.01, 1234.6)
assert isinstance(o, Order) assert isinstance(o, Order)
assert o.ft_pair == 'ADA/USDT' assert o.ft_pair == 'ADA/USDT'
assert o.ft_order_side == 'buy' assert o.ft_order_side == 'buy'
assert o.order_id == '1234' assert o.order_id == '1234'
assert o.order_type == 'limit' assert o.order_type == 'limit'
assert o.price == 1234.5 assert o.price == 1234.5
assert o.ft_price == 1234.6
assert o.ft_amount == 20.01
assert o.filled == 9 assert o.filled == 9
assert o.remaining == 11 assert o.remaining == 11
assert o.order_date is not None assert o.order_date is not None
@ -2539,6 +2543,8 @@ def test_recalc_trade_from_orders_dca(data) -> None:
ft_pair=trade.pair, ft_pair=trade.pair,
order_id=f"order_{order[0]}_{idx}", order_id=f"order_{order[0]}_{idx}",
ft_is_open=False, ft_is_open=False,
ft_amount=amount,
ft_price=price,
status="closed", status="closed",
symbol=trade.pair, symbol=trade.pair,
order_type="market", order_type="market",

View File

@ -39,6 +39,8 @@ def generate_mock_trade(pair: str, fee: float, is_open: bool,
order_id=f'{pair}-{trade.entry_side}-{trade.open_date}', order_id=f'{pair}-{trade.entry_side}-{trade.open_date}',
ft_is_open=False, ft_is_open=False,
ft_pair=pair, ft_pair=pair,
ft_amount=trade.amount,
ft_price=trade.open_rate,
amount=trade.amount, amount=trade.amount,
filled=trade.amount, filled=trade.amount,
remaining=0, remaining=0,
@ -49,16 +51,19 @@ def generate_mock_trade(pair: str, fee: float, is_open: bool,
side=trade.entry_side, side=trade.entry_side,
)) ))
if not is_open: if not is_open:
close_price = open_rate * (2 - profit_rate if is_short else profit_rate)
trade.orders.append(Order( trade.orders.append(Order(
ft_order_side=trade.exit_side, ft_order_side=trade.exit_side,
order_id=f'{pair}-{trade.exit_side}-{trade.close_date}', order_id=f'{pair}-{trade.exit_side}-{trade.close_date}',
ft_is_open=False, ft_is_open=False,
ft_pair=pair, ft_pair=pair,
ft_amount=trade.amount,
ft_price=trade.open_rate,
amount=trade.amount, amount=trade.amount,
filled=trade.amount, filled=trade.amount,
remaining=0, remaining=0,
price=open_rate * (2 - profit_rate if is_short else profit_rate), price=close_price,
average=open_rate * (2 - profit_rate if is_short else profit_rate), average=close_price,
status="closed", status="closed",
order_type="market", order_type="market",
side=trade.exit_side, side=trade.exit_side,
@ -66,7 +71,7 @@ def generate_mock_trade(pair: str, fee: float, is_open: bool,
trade.recalc_open_trade_value() trade.recalc_open_trade_value()
if not is_open: if not is_open:
trade.close(open_rate * (2 - profit_rate if is_short else profit_rate)) trade.close(close_price)
trade.exit_reason = exit_reason trade.exit_reason = exit_reason
Trade.query.session.add(trade) Trade.query.session.add(trade)

View File

@ -253,6 +253,8 @@ def test_telegram_status_multi_entry(default_conf, update, mocker, fee) -> None:
ft_order_side='buy', ft_order_side='buy',
ft_pair=trade.pair, ft_pair=trade.pair,
ft_is_open=False, ft_is_open=False,
ft_amount=trade.amount,
ft_price=trade.open_rate,
status="closed", status="closed",
symbol=trade.pair, symbol=trade.pair,
order_type="market", order_type="market",

View File

@ -1168,6 +1168,8 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
order_id='100', order_id='100',
ft_pair=trade.pair, ft_pair=trade.pair,
ft_is_open=True, ft_is_open=True,
ft_amount=trade.amount,
ft_price=0.0,
)) ))
assert trade assert trade
@ -4615,6 +4617,7 @@ def test_get_real_amount_open_trade_usdt(default_conf_usdt, fee, mocker):
'amount': amount, 'amount': amount,
'status': 'open', 'status': 'open',
'side': 'buy', 'side': 'buy',
'price': 0.245441,
} }
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt) freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
order_obj = Order.parse_from_ccxt_object(order, 'LTC/ETH', 'buy') order_obj = Order.parse_from_ccxt_object(order, 'LTC/ETH', 'buy')