diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index e840387a9..eb2d324c5 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -206,6 +206,7 @@ def get_balance(currency: str) -> float: return balances[currency]['free'] +@retrier def get_balances() -> dict: if _CONF['dry_run']: return {} @@ -274,6 +275,7 @@ def get_ticker_history(pair: str, tick_interval: str) -> List[Dict]: raise OperationalException('Could not fetch ticker data. Msg: {}'.format(e)) +@retrier def cancel_order(order_id: str, pair: str) -> None: if _CONF['dry_run']: return @@ -288,6 +290,7 @@ def cancel_order(order_id: str, pair: str) -> None: raise OperationalException(e) +@retrier def get_order(order_id: str, pair: str) -> Dict: if _CONF['dry_run']: order = _DRY_RUN_OPEN_ORDERS[order_id] @@ -309,6 +312,7 @@ def get_order(order_id: str, pair: str) -> Dict: raise OperationalException(e) +@retrier def get_pair_detail_url(pair: str) -> str: try: url_base = _API.urls.get('www') @@ -320,6 +324,7 @@ def get_pair_detail_url(pair: str) -> str: return "" +@retrier def get_markets() -> List[dict]: try: return _API.fetch_markets() @@ -339,6 +344,7 @@ def get_id() -> str: return _API.id +@retrier def get_fee(symbol='ETH/BTC', type='', side='', amount=1, price=1, taker_or_maker='maker') -> float: try: diff --git a/freqtrade/tests/exchange/test_exchange.py b/freqtrade/tests/exchange/test_exchange.py index 0f74b161a..8efbcc201 100644 --- a/freqtrade/tests/exchange/test_exchange.py +++ b/freqtrade/tests/exchange/test_exchange.py @@ -262,15 +262,17 @@ 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(TemporaryError): + with pytest.raises(OperationalException): api_mock.fetch_balance = MagicMock(side_effect=ccxt.NetworkError) mocker.patch('freqtrade.exchange._API', api_mock) get_balances() + assert api_mock.fetch_balance.call_count == exchange.API_RETRY_COUNT + 1 with pytest.raises(OperationalException): api_mock.fetch_balance = MagicMock(side_effect=ccxt.BaseError) mocker.patch('freqtrade.exchange._API', api_mock) get_balances() + assert api_mock.fetch_balance.call_count == 1 # This test is somewhat redundant with @@ -397,20 +399,23 @@ 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(TemporaryError): + with pytest.raises(OperationalException): 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(TemporaryError): + with pytest.raises(OperationalException): api_mock.cancel_order = MagicMock(side_effect=ccxt.InvalidOrder) 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): api_mock.cancel_order = MagicMock(side_effect=ccxt.BaseError) mocker.patch('freqtrade.exchange._API', api_mock) cancel_order(order_id='_', pair='TKN/BTC') + assert api_mock.cancel_order.call_count == 1 def test_get_order(default_conf, mocker): @@ -429,20 +434,23 @@ 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(TemporaryError): + with pytest.raises(OperationalException): 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(DependencyException): + with pytest.raises(OperationalException): api_mock.fetch_order = MagicMock(side_effect=ccxt.InvalidOrder) 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): api_mock.fetch_order = MagicMock(side_effect=ccxt.BaseError) mocker.patch('freqtrade.exchange._API', api_mock) exchange.get_order(order_id='_', pair='TKN/BTC') + assert api_mock.fetch_order.call_count == 1 def test_get_name(default_conf, mocker):