From 8f8d5dbff5175a8c411d90fb39d255733afc49a4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 16 May 2021 14:31:53 +0200 Subject: [PATCH] Add tests for sl_order_with_result --- tests/exchange/test_exchange.py | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 573f41bda..54ffabd4f 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -2084,6 +2084,47 @@ def test_cancel_stoploss_order(default_conf, mocker, exchange_name): order_id='_', pair='TKN/BTC') +@pytest.mark.parametrize("exchange_name", EXCHANGES) +def test_cancel_stoploss_order_with_result(default_conf, mocker, exchange_name): + default_conf['dry_run'] = False + mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', return_value={'for': 123}) + mocker.patch('freqtrade.exchange.Ftx.fetch_stoploss_order', return_value={'for': 123}) + exchange = get_patched_exchange(mocker, default_conf, id=exchange_name) + + mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', + return_value={'fee': {}, 'status': 'canceled', 'amount': 1234}) + mocker.patch('freqtrade.exchange.Ftx.cancel_stoploss_order', + return_value={'fee': {}, 'status': 'canceled', 'amount': 1234}) + co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555) + assert co == {'fee': {}, 'status': 'canceled', 'amount': 1234} + + mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', + return_value='canceled') + mocker.patch('freqtrade.exchange.Ftx.cancel_stoploss_order', + return_value='canceled') + # Fall back to fetch_stoploss_order + co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555) + assert co == {'for': 123} + + mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', + side_effect=InvalidOrderException("")) + mocker.patch('freqtrade.exchange.Ftx.fetch_stoploss_order', + side_effect=InvalidOrderException("")) + + co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555) + assert co['amount'] == 555 + assert co == {'fee': {}, 'status': 'canceled', 'amount': 555, 'info': {}} + + with pytest.raises(InvalidOrderException): + mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', + side_effect=InvalidOrderException("Did not find order")) + mocker.patch('freqtrade.exchange.Ftx.cancel_stoploss_order', + side_effect=InvalidOrderException("Did not find order")) + exchange = get_patched_exchange(mocker, default_conf, id=exchange_name) + exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=123) + + + @pytest.mark.parametrize("exchange_name", EXCHANGES) def test_fetch_order(default_conf, mocker, exchange_name): default_conf['dry_run'] = True