Simplify stoploss behavior by combining more commonalities

This commit is contained in:
Matthias 2022-10-26 07:14:33 +02:00
parent 6e0ca058f4
commit 255f38537e
4 changed files with 5 additions and 26 deletions

View File

@ -1079,8 +1079,11 @@ class Exchange:
if not self._ft_has.get('stoploss_on_exchange'): if not self._ft_has.get('stoploss_on_exchange'):
raise OperationalException(f"stoploss is not implemented for {self.name}.") raise OperationalException(f"stoploss is not implemented for {self.name}.")
return ((side == "sell" and stop_loss > float(order['stopPrice'])) or return (
order.get('stopPrice', None) is None
or ((side == "sell" and stop_loss > float(order['stopPrice'])) or
(side == "buy" and stop_loss < float(order['stopPrice']))) (side == "buy" and stop_loss < float(order['stopPrice'])))
)
def _get_stop_order_type(self, user_order_type) -> Tuple[str, str]: def _get_stop_order_type(self, user_order_type) -> Tuple[str, str]:

View File

@ -23,19 +23,6 @@ class Huobi(Exchange):
"l2_limit_range_required": False, "l2_limit_range_required": False,
} }
def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool:
"""
Verify stop_loss against stoploss-order value (limit or price)
Returns True if adjustment is necessary.
"""
return (
order.get('stopPrice', None) is None
or (
order['type'] == 'stop'
and stop_loss > float(order['stopPrice'])
)
)
def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict: def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict:
params = self._params.copy() params = self._params.copy()

View File

@ -28,16 +28,6 @@ class Kucoin(Exchange):
"ohlcv_candle_limit": 1500, "ohlcv_candle_limit": 1500,
} }
def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool:
"""
Verify stop_loss against stoploss-order value (limit or price)
Returns True if adjustment is necessary.
"""
return (
order.get('stopPrice', None) is None
or stop_loss > float(order['stopPrice'])
)
def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict: def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict:
params = self._params.copy() params = self._params.copy()

View File

@ -113,5 +113,4 @@ def test_stoploss_adjust_huobi(mocker, default_conf):
assert exchange.stoploss_adjust(1501, order, 'sell') assert exchange.stoploss_adjust(1501, order, 'sell')
assert not exchange.stoploss_adjust(1499, order, 'sell') assert not exchange.stoploss_adjust(1499, order, 'sell')
# Test with invalid order case # Test with invalid order case
order['type'] = 'stop_loss' assert exchange.stoploss_adjust(1501, order, 'sell')
assert not exchange.stoploss_adjust(1501, order, 'sell')