Merge pull request #6279 from xataxxx/develop

Fix position adjustment not counting older orders because of missing average field value
This commit is contained in:
Matthias
2022-01-23 17:42:51 +01:00
committed by GitHub
3 changed files with 39 additions and 10 deletions

View File

@@ -243,6 +243,8 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
freqtrade.process()
trade = Trade.get_trades().first()
assert len(trade.orders) == 2
for o in trade.orders:
assert o.status == "closed"
assert trade.stake_amount == 120
# Open-rate averaged between 2.0 and 2.0 * 0.995
@@ -258,7 +260,6 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
assert trade.orders[1].amount == 60 / ticker_usdt_modif['bid']
assert trade.amount == trade.orders[0].amount + trade.orders[1].amount
assert trade.nr_of_successful_buys == 2
# Sell

View File

@@ -1661,6 +1661,33 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee):
assert trade.fee_open_cost == 2 * o1_fee_cost
assert trade.open_trade_value == 2 * o1_trade_val
assert trade.nr_of_successful_buys == 2
# Check with 1 order
order_noavg = Order(
ft_order_side='buy',
ft_pair=trade.pair,
ft_is_open=False,
status="closed",
symbol=trade.pair,
order_type="market",
side="buy",
price=o1_rate,
average=None,
filled=o1_amount,
remaining=0,
cost=o1_amount,
order_date=trade.open_date,
order_filled_date=trade.open_date,
)
trade.orders.append(order_noavg)
trade.recalc_trade_from_orders()
# Calling recalc with single initial order should not change anything
assert trade.amount == 3 * o1_amount
assert trade.stake_amount == 3 * o1_amount
assert trade.open_rate == o1_rate
assert trade.fee_open_cost == 3 * o1_fee_cost
assert trade.open_trade_value == 3 * o1_trade_val
assert trade.nr_of_successful_buys == 3
@pytest.mark.usefixtures("init_persistence")