From f55d75e7fcb15f7a27c7cfd51981f63697019803 Mon Sep 17 00:00:00 2001 From: misagh Date: Tue, 12 Mar 2019 15:35:44 +0100 Subject: [PATCH] TSL validation tests added --- freqtrade/exchange/exchange.py | 8 +++---- freqtrade/tests/exchange/test_exchange.py | 27 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 13ab51226..88f255c85 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -274,12 +274,12 @@ class Exchange(object): if tsl_only_offset: if tsl_positive == 0.0: raise OperationalException( - f'The config trailing_only_offset_is_reached need ' - 'trailing_stop_positive_offset to be more than 0 in your config') + f'The config trailing_only_offset_is_reached need ' + 'trailing_stop_positive_offset to be more than 0 in your config.') if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive: raise OperationalException( - f'The config trailing_stop_positive_offset need ' - 'to be greater than trailing_stop_positive_offset in your config') + f'The config trailing_stop_positive_offset need ' + 'to be greater than trailing_stop_positive_offset in your config.') def exchange_has(self, endpoint: str) -> bool: """ diff --git a/freqtrade/tests/exchange/test_exchange.py b/freqtrade/tests/exchange/test_exchange.py index ff36ab91c..16e5e693b 100644 --- a/freqtrade/tests/exchange/test_exchange.py +++ b/freqtrade/tests/exchange/test_exchange.py @@ -432,6 +432,33 @@ def test_validate_order_types(default_conf, mocker): Exchange(default_conf) +def test_validate_tsl(default_conf, mocker): + api_mock = MagicMock() + mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock)) + mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={})) + mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock()) + mocker.patch('freqtrade.exchange.Exchange.name', 'Bittrex') + default_conf['trailing_stop'] = True + default_conf['trailing_stop_positive'] = 0 + default_conf['trailing_stop_positive_offset'] = 0 + default_conf['trailing_only_offset_is_reached'] = False + + Exchange(default_conf) + + default_conf['trailing_only_offset_is_reached'] = True + with pytest.raises(OperationalException, + match=r'The config trailing_only_offset_is_reached need ' + 'trailing_stop_positive_offset to be more than 0 in your config.'): + Exchange(default_conf) + + default_conf['trailing_stop_positive_offset'] = 0.01 + default_conf['trailing_stop_positive'] = 0.015 + with pytest.raises(OperationalException, + match=r'The config trailing_stop_positive_offset need ' + 'to be greater than trailing_stop_positive_offset in your config.'): + Exchange(default_conf) + + def test_validate_order_types_not_in_config(default_conf, mocker): api_mock = MagicMock() mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))