Add checks verifying that stoploss is not 0 (and positive-stoploss is
also not 0).
This commit is contained in:
parent
782f4112cd
commit
70ebd09de4
@ -68,6 +68,10 @@ def validate_config_consistency(conf: Dict[str, Any]) -> None:
|
|||||||
|
|
||||||
def _validate_trailing_stoploss(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
|
# Skip if trailing stoploss is not activated
|
||||||
if not conf.get('trailing_stop', False):
|
if not conf.get('trailing_stop', False):
|
||||||
return
|
return
|
||||||
@ -79,13 +83,20 @@ def _validate_trailing_stoploss(conf: Dict[str, Any]) -> None:
|
|||||||
if tsl_only_offset:
|
if tsl_only_offset:
|
||||||
if tsl_positive == 0.0:
|
if tsl_positive == 0.0:
|
||||||
raise OperationalException(
|
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.')
|
'trailing_stop_positive_offset to be more than 0 in your config.')
|
||||||
if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive:
|
if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive:
|
||||||
raise OperationalException(
|
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.')
|
'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:
|
def _validate_edge(conf: Dict[str, Any]) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -649,8 +649,8 @@ def test_create_userdata_dir_exists_exception(mocker, default_conf, caplog) -> N
|
|||||||
|
|
||||||
def test_validate_tsl(default_conf):
|
def test_validate_tsl(default_conf):
|
||||||
default_conf['stoploss'] = 0.0
|
default_conf['stoploss'] = 0.0
|
||||||
with pytest.raises(OperationalException, match='The config stoploss needs to be more '
|
with pytest.raises(OperationalException, match='The config stoploss needs to be different '
|
||||||
'than 0 to avoid problems with sell orders.'):
|
'from 0 to avoid problems with sell orders.'):
|
||||||
validate_config_consistency(default_conf)
|
validate_config_consistency(default_conf)
|
||||||
default_conf['stoploss'] = -0.10
|
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_stop_positive_offset'] = 0.02
|
||||||
default_conf['trailing_only_offset_is_reached'] = False
|
default_conf['trailing_only_offset_is_reached'] = False
|
||||||
with pytest.raises(OperationalException,
|
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'):
|
'to avoid problems with sell orders'):
|
||||||
validate_config_consistency(default_conf)
|
validate_config_consistency(default_conf)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user