Add test verifying correct price reduction on limit stoploss orders
This commit is contained in:
parent
92b6d3e2fa
commit
a7b469e83d
@ -9,7 +9,12 @@ from freqtrade.exceptions import (DependencyException, InvalidOrderException,
|
|||||||
from tests.conftest import get_patched_exchange
|
from tests.conftest import get_patched_exchange
|
||||||
|
|
||||||
|
|
||||||
def test_stoploss_order_binance(default_conf, mocker):
|
@pytest.mark.parametrize('limitratio,expected', [
|
||||||
|
(None, 220 * 0.99),
|
||||||
|
(0.99, 220 * 0.99),
|
||||||
|
(0.98, 220 * 0.98),
|
||||||
|
])
|
||||||
|
def test_stoploss_order_binance(default_conf, mocker, limitratio, expected):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
order_id = 'test_prod_buy_{}'.format(randint(0, 10 ** 6))
|
order_id = 'test_prod_buy_{}'.format(randint(0, 10 ** 6))
|
||||||
order_type = 'stop_loss_limit'
|
order_type = 'stop_loss_limit'
|
||||||
@ -20,7 +25,6 @@ def test_stoploss_order_binance(default_conf, mocker):
|
|||||||
'foo': 'bar'
|
'foo': 'bar'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
||||||
@ -32,8 +36,8 @@ def test_stoploss_order_binance(default_conf, mocker):
|
|||||||
order_types={'stoploss_on_exchange_limit_ratio': 1.05})
|
order_types={'stoploss_on_exchange_limit_ratio': 1.05})
|
||||||
|
|
||||||
api_mock.create_order.reset_mock()
|
api_mock.create_order.reset_mock()
|
||||||
|
order_types = {} if limitratio is None else {'stoploss_on_exchange_limit_ratio': limitratio}
|
||||||
order = exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
|
order = exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types=order_types)
|
||||||
|
|
||||||
assert 'id' in order
|
assert 'id' in order
|
||||||
assert 'info' in order
|
assert 'info' in order
|
||||||
@ -43,7 +47,7 @@ def test_stoploss_order_binance(default_conf, mocker):
|
|||||||
assert api_mock.create_order.call_args_list[0][1]['side'] == 'sell'
|
assert api_mock.create_order.call_args_list[0][1]['side'] == 'sell'
|
||||||
assert api_mock.create_order.call_args_list[0][1]['amount'] == 1
|
assert api_mock.create_order.call_args_list[0][1]['amount'] == 1
|
||||||
# Price should be 1% below stopprice
|
# Price should be 1% below stopprice
|
||||||
assert api_mock.create_order.call_args_list[0][1]['price'] == 220 * 0.99
|
assert api_mock.create_order.call_args_list[0][1]['price'] == expected
|
||||||
assert api_mock.create_order.call_args_list[0][1]['params'] == {'stopPrice': 220}
|
assert api_mock.create_order.call_args_list[0][1]['params'] == {'stopPrice': 220}
|
||||||
|
|
||||||
# test exception handling
|
# test exception handling
|
||||||
|
Loading…
Reference in New Issue
Block a user