From a514b92dcf72446d417924f0fa4ca9e82a0b1597 Mon Sep 17 00:00:00 2001 From: Michael Egger Date: Tue, 26 Dec 2017 09:39:29 +0100 Subject: [PATCH] catch MIN_TRADE_REQUIREMENT_NOT_MET as non-critical exception (#237) * add MIN_TRADE_REQUIREMENT_NOT_MET to response validation * implement test --- freqtrade/exchange/bittrex.py | 8 ++++-- freqtrade/tests/test_exchange_bittrex.py | 32 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 freqtrade/tests/test_exchange_bittrex.py diff --git a/freqtrade/exchange/bittrex.py b/freqtrade/exchange/bittrex.py index ca7fce262..3714de070 100644 --- a/freqtrade/exchange/bittrex.py +++ b/freqtrade/exchange/bittrex.py @@ -45,8 +45,12 @@ class Bittrex(Exchange): Validates the given bittrex response and raises a ContentDecodingError if a non-fatal issue happened. """ - if response['message'] == 'NO_API_RESPONSE': - raise ContentDecodingError('Unable to decode bittrex response') + temp_error_messages = [ + 'NO_API_RESPONSE', + 'MIN_TRADE_REQUIREMENT_NOT_MET', + ] + if response['message'] in temp_error_messages: + raise ContentDecodingError('Got {}'.format(response['message'])) @property def fee(self) -> float: diff --git a/freqtrade/tests/test_exchange_bittrex.py b/freqtrade/tests/test_exchange_bittrex.py new file mode 100644 index 000000000..53ca71a83 --- /dev/null +++ b/freqtrade/tests/test_exchange_bittrex.py @@ -0,0 +1,32 @@ +# pragma pylint: disable=missing-docstring,C0103 + +import pytest +from requests.exceptions import ContentDecodingError + +from freqtrade.exchange import Bittrex + + +def test_validate_response_success(): + response = { + 'message': '', + 'result': [], + } + Bittrex._validate_response(response) + + +def test_validate_response_no_api_response(): + response = { + 'message': 'NO_API_RESPONSE', + 'result': None, + } + with pytest.raises(ContentDecodingError, match=r'.*NO_API_RESPONSE.*'): + Bittrex._validate_response(response) + + +def test_validate_response_min_trade_requirement_not_met(): + response = { + 'message': 'MIN_TRADE_REQUIREMENT_NOT_MET', + 'result': None, + } + with pytest.raises(ContentDecodingError, match=r'.*MIN_TRADE_REQUIREMENT_NOT_MET.*'): + Bittrex._validate_response(response)