From 92a060c5b45f683009186c6a7169e5f8bfae9b55 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 3 Apr 2023 20:18:57 +0200 Subject: [PATCH] Make stop_price_parameter configurable by exchange --- freqtrade/exchange/exchange.py | 13 +++++++------ freqtrade/exchange/okx.py | 20 ++------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 6c236106f..4d7be8fdf 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -60,6 +60,7 @@ class Exchange: # or by specifying them in the configuration. _ft_has_default: Dict = { "stoploss_on_exchange": False, + "stop_price_param": "stopPrice", "order_time_in_force": ["GTC"], "ohlcv_params": {}, "ohlcv_candle_limit": 500, @@ -1115,11 +1116,11 @@ class Exchange: """ if not self._ft_has.get('stoploss_on_exchange'): raise OperationalException(f"stoploss is not implemented for {self.name}.") - + price_param = self._ft_has['stop_price_param'] 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']))) + order.get(price_param, None) is None + or ((side == "sell" and stop_loss > float(order[price_param])) or + (side == "buy" and stop_loss < float(order[price_param]))) ) def _get_stop_order_type(self, user_order_type) -> Tuple[str, str]: @@ -1159,8 +1160,8 @@ class Exchange: def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict: params = self._params.copy() - # Verify if stopPrice works for your exchange! - params.update({'stopPrice': stop_price}) + # Verify if stopPrice works for your exchange, else configure stop_price_param + params.update({self._ft_has['stop_price_param']: stop_price}) return params @retrier(retries=0) diff --git a/freqtrade/exchange/okx.py b/freqtrade/exchange/okx.py index a4fcaeca0..84b7deb7a 100644 --- a/freqtrade/exchange/okx.py +++ b/freqtrade/exchange/okx.py @@ -28,6 +28,7 @@ class Okx(Exchange): "funding_fee_timeframe": "8h", "stoploss_order_types": {"limit": "limit"}, "stoploss_on_exchange": True, + "stop_price_param": "stopLossPrice", } _ft_has_futures: Dict = { "tickers_have_quoteVolume": False, @@ -162,29 +163,12 @@ class Okx(Exchange): return pair_tiers[-1]['maxNotional'] / leverage def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict: - - params = self._params.copy() - # Verify if stopPrice works for your exchange! - params.update({'stopLossPrice': stop_price}) - + params = super()._get_stop_params(side, ordertype, stop_price) if self.trading_mode == TradingMode.FUTURES and self.margin_mode: params['tdMode'] = self.margin_mode.value params['posSide'] = self._get_posSide(side, True) return params - def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool: - """ - OKX uses non-default stoploss price naming. - """ - if not self._ft_has.get('stoploss_on_exchange'): - raise OperationalException(f"stoploss is not implemented for {self.name}.") - - return ( - order.get('stopLossPrice', None) is None - or ((side == "sell" and stop_loss > float(order['stopLossPrice'])) or - (side == "buy" and stop_loss < float(order['stopLossPrice']))) - ) - def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: if self._config['dry_run']: return self.fetch_dry_run_order(order_id)