From aa213a364032df34131aeb3f4f6bb78fd1044fdd Mon Sep 17 00:00:00 2001 From: gcarq Date: Mon, 23 Apr 2018 16:58:32 +0200 Subject: [PATCH] cancel_order: handle InvalidOrder exception --- freqtrade/exchange/__init__.py | 4 ++++ freqtrade/tests/exchange/test_exchange.py | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 8f9b737dd..f2c08ff7d 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -289,6 +289,10 @@ def cancel_order(order_id: str, pair: str) -> None: try: return _API.cancel_order(order_id, pair) + except ccxt.InvalidOrder as e: + raise DependencyException( + 'Could not cancel order. Message: {}'.format(e) + ) except (ccxt.NetworkError, ccxt.ExchangeError) as e: raise TemporaryError( 'Could not cancel order due to {}. Message: {}'.format( diff --git a/freqtrade/tests/exchange/test_exchange.py b/freqtrade/tests/exchange/test_exchange.py index 8efbcc201..d626340a3 100644 --- a/freqtrade/tests/exchange/test_exchange.py +++ b/freqtrade/tests/exchange/test_exchange.py @@ -262,7 +262,7 @@ def test_get_balances_prod(default_conf, mocker): assert get_balances()['1ST']['total'] == 10.0 assert get_balances()['1ST']['used'] == 0.0 - with pytest.raises(OperationalException): + with pytest.raises(TemporaryError): api_mock.fetch_balance = MagicMock(side_effect=ccxt.NetworkError) mocker.patch('freqtrade.exchange._API', api_mock) get_balances() @@ -312,7 +312,7 @@ def test_get_ticker(default_conf, mocker): assert ticker['bid'] == 0.5 assert ticker['ask'] == 1 - with pytest.raises(OperationalException): # test retrier + with pytest.raises(TemporaryError): # test retrier api_mock.fetch_ticker = MagicMock(side_effect=ccxt.NetworkError) mocker.patch('freqtrade.exchange._API', api_mock) get_ticker(pair='ETH/BTC', refresh=True) @@ -370,7 +370,7 @@ def test_get_ticker_history(default_conf, mocker): assert ticks[0][4] == 9 assert ticks[0][5] == 10 - with pytest.raises(OperationalException): # test retrier + with pytest.raises(TemporaryError): # test retrier api_mock.fetch_ohlcv = MagicMock(side_effect=ccxt.NetworkError) mocker.patch('freqtrade.exchange._API', api_mock) # new symbol to get around cache @@ -399,13 +399,13 @@ def test_cancel_order(default_conf, mocker): mocker.patch('freqtrade.exchange._API', api_mock) assert cancel_order(order_id='_', pair='TKN/BTC') == 123 - with pytest.raises(OperationalException): + with pytest.raises(TemporaryError): api_mock.cancel_order = MagicMock(side_effect=ccxt.NetworkError) mocker.patch('freqtrade.exchange._API', api_mock) cancel_order(order_id='_', pair='TKN/BTC') assert api_mock.cancel_order.call_count == exchange.API_RETRY_COUNT + 1 - with pytest.raises(OperationalException): + with pytest.raises(DependencyException): api_mock.cancel_order = MagicMock(side_effect=ccxt.InvalidOrder) mocker.patch('freqtrade.exchange._API', api_mock) cancel_order(order_id='_', pair='TKN/BTC') @@ -434,13 +434,13 @@ def test_get_order(default_conf, mocker): mocker.patch('freqtrade.exchange._API', api_mock) assert exchange.get_order('X', 'TKN/BTC') == 456 - with pytest.raises(OperationalException): + with pytest.raises(TemporaryError): api_mock.fetch_order = MagicMock(side_effect=ccxt.NetworkError) mocker.patch('freqtrade.exchange._API', api_mock) exchange.get_order(order_id='_', pair='TKN/BTC') assert api_mock.fetch_order.call_count == exchange.API_RETRY_COUNT + 1 - with pytest.raises(OperationalException): + with pytest.raises(DependencyException): api_mock.fetch_order = MagicMock(side_effect=ccxt.InvalidOrder) mocker.patch('freqtrade.exchange._API', api_mock) exchange.get_order(order_id='_', pair='TKN/BTC')