Convert limit orders to market orders if they cross a threshold
closes #7786
This commit is contained in:
@@ -1248,18 +1248,20 @@ def test_create_dry_run_order_fees(
|
||||
assert order1['fee']['rate'] == fee
|
||||
|
||||
|
||||
@pytest.mark.parametrize("side,price,filled", [
|
||||
@pytest.mark.parametrize("side,price,filled,converted", [
|
||||
# order_book_l2_usd spread:
|
||||
# best ask: 25.566
|
||||
# best bid: 25.563
|
||||
("buy", 25.563, False),
|
||||
("buy", 25.566, True),
|
||||
("sell", 25.566, False),
|
||||
("sell", 25.563, True),
|
||||
("buy", 25.563, False, False),
|
||||
("buy", 25.566, True, False),
|
||||
("sell", 25.566, False, False),
|
||||
("sell", 25.563, True, False),
|
||||
("buy", 29.563, True, True),
|
||||
("sell", 21.563, True, True),
|
||||
])
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
def test_create_dry_run_order_limit_fill(default_conf, mocker, side, price, filled,
|
||||
exchange_name, order_book_l2_usd):
|
||||
def test_create_dry_run_order_limit_fill(default_conf, mocker, side, price, filled, caplog,
|
||||
exchange_name, order_book_l2_usd, converted):
|
||||
default_conf['dry_run'] = True
|
||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||
@@ -1279,9 +1281,16 @@ def test_create_dry_run_order_limit_fill(default_conf, mocker, side, price, fill
|
||||
assert 'id' in order
|
||||
assert f'dry_run_{side}_' in order["id"]
|
||||
assert order["side"] == side
|
||||
assert order["type"] == "limit"
|
||||
if not converted:
|
||||
assert order["average"] == price
|
||||
assert order["type"] == "limit"
|
||||
else:
|
||||
# Converted to market order
|
||||
assert order["type"] == "market"
|
||||
assert 25.5 < order["average"] < 25.6
|
||||
assert log_has_re(r"Converted .* to market order.*", caplog)
|
||||
|
||||
assert order["symbol"] == "LTC/USDT"
|
||||
assert order["average"] == price
|
||||
assert order['status'] == 'open' if not filled else 'closed'
|
||||
order_book_l2_usd.reset_mock()
|
||||
|
||||
|
Reference in New Issue
Block a user