From 782f4112cd33b1ae4a86eac58fd57bf1d8db1c5d Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 22 Aug 2019 19:49:30 +0200 Subject: [PATCH 1/3] Add test checking stoploss == 0 values --- freqtrade/tests/test_configuration.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index a2a87c2cf..838f0372f 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -648,6 +648,12 @@ def test_create_userdata_dir_exists_exception(mocker, default_conf, caplog) -> N def test_validate_tsl(default_conf): + default_conf['stoploss'] = 0.0 + with pytest.raises(OperationalException, match='The config stoploss needs to be more ' + 'than 0 to avoid problems with sell orders.'): + validate_config_consistency(default_conf) + default_conf['stoploss'] = -0.10 + default_conf['trailing_stop'] = True default_conf['trailing_stop_positive'] = 0 default_conf['trailing_stop_positive_offset'] = 0 @@ -669,6 +675,15 @@ def test_validate_tsl(default_conf): default_conf['trailing_stop_positive_offset'] = 0.015 validate_config_consistency(default_conf) + # 0 trailing stop positive - results in "Order would trigger immediately" + default_conf['trailing_stop_positive'] = 0 + default_conf['trailing_stop_positive_offset'] = 0.02 + default_conf['trailing_only_offset_is_reached'] = False + with pytest.raises(OperationalException, + match='The config trailing_stop_positive needs to be more than 0' + 'to avoid problems with sell orders'): + validate_config_consistency(default_conf) + def test_validate_edge(edge_conf): edge_conf.update({"pairlist": { From 70ebd09de4ac628bed224fcadc7a52c4bd9898d6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 22 Aug 2019 19:49:50 +0200 Subject: [PATCH 2/3] Add checks verifying that stoploss is not 0 (and positive-stoploss is also not 0). --- freqtrade/configuration/config_validation.py | 15 +++++++++++++-- freqtrade/tests/test_configuration.py | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/freqtrade/configuration/config_validation.py b/freqtrade/configuration/config_validation.py index 92846b704..338b8959a 100644 --- a/freqtrade/configuration/config_validation.py +++ b/freqtrade/configuration/config_validation.py @@ -68,6 +68,10 @@ def validate_config_consistency(conf: Dict[str, Any]) -> None: def _validate_trailing_stoploss(conf: Dict[str, Any]) -> None: + if conf.get('stoploss') == 0.0: + raise OperationalException( + 'The config stoploss needs to be different from 0 to avoid problems with sell orders.' + ) # Skip if trailing stoploss is not activated if not conf.get('trailing_stop', False): return @@ -79,13 +83,20 @@ def _validate_trailing_stoploss(conf: Dict[str, Any]) -> None: if tsl_only_offset: if tsl_positive == 0.0: raise OperationalException( - f'The config trailing_only_offset_is_reached needs ' + 'The config trailing_only_offset_is_reached needs ' '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 needs ' + 'The config trailing_stop_positive_offset needs ' 'to be greater than trailing_stop_positive_offset in your config.') + # Fetch again without default + if 'trailing_stop_positive' in conf and float(conf['trailing_stop_positive']) == 0.0: + raise OperationalException( + 'The config trailing_stop_positive needs to be different from 0 ' + 'to avoid problems with sell orders.' + ) + def _validate_edge(conf: Dict[str, Any]) -> None: """ diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index 838f0372f..618bd69cf 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -649,8 +649,8 @@ def test_create_userdata_dir_exists_exception(mocker, default_conf, caplog) -> N def test_validate_tsl(default_conf): default_conf['stoploss'] = 0.0 - with pytest.raises(OperationalException, match='The config stoploss needs to be more ' - 'than 0 to avoid problems with sell orders.'): + with pytest.raises(OperationalException, match='The config stoploss needs to be different ' + 'from 0 to avoid problems with sell orders.'): validate_config_consistency(default_conf) default_conf['stoploss'] = -0.10 @@ -680,7 +680,7 @@ def test_validate_tsl(default_conf): default_conf['trailing_stop_positive_offset'] = 0.02 default_conf['trailing_only_offset_is_reached'] = False with pytest.raises(OperationalException, - match='The config trailing_stop_positive needs to be more than 0' + match='The config trailing_stop_positive needs to be different from 0 ' 'to avoid problems with sell orders'): validate_config_consistency(default_conf) From a8842f38ca12f6ebc59f6039206e91079297e13d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 24 Aug 2019 09:08:08 +0200 Subject: [PATCH 3/3] Fix wrong exception message --- freqtrade/configuration/config_validation.py | 2 +- freqtrade/tests/test_configuration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/configuration/config_validation.py b/freqtrade/configuration/config_validation.py index 338b8959a..6a8374e6d 100644 --- a/freqtrade/configuration/config_validation.py +++ b/freqtrade/configuration/config_validation.py @@ -88,7 +88,7 @@ def _validate_trailing_stoploss(conf: Dict[str, Any]) -> None: if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive: raise OperationalException( 'The config trailing_stop_positive_offset needs ' - 'to be greater than trailing_stop_positive_offset in your config.') + 'to be greater than trailing_stop_positive in your config.') # Fetch again without default if 'trailing_stop_positive' in conf and float(conf['trailing_stop_positive']) == 0.0: diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index 618bd69cf..10ce7e8cf 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -668,7 +668,7 @@ def test_validate_tsl(default_conf): default_conf['trailing_stop_positive'] = 0.015 with pytest.raises(OperationalException, match=r'The config trailing_stop_positive_offset needs ' - 'to be greater than trailing_stop_positive_offset in your config.'): + 'to be greater than trailing_stop_positive in your config.'): validate_config_consistency(default_conf) default_conf['trailing_stop_positive'] = 0.01