diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 7d83e971b..35f427c34 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -107,6 +107,7 @@ class Binance(Exchange): rate = self.price_to_precision(pair, rate) + self._lev_prep(pair, leverage) order = self._api.create_order(symbol=pair, type=ordertype, side=side, amount=amount, price=rate, params=params) logger.info('stoploss limit order added for %s. ' diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 4021e7d02..4617fd4c2 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -773,10 +773,11 @@ class Exchange: # Order handling def _lev_prep(self, pair: str, leverage: float): - self.set_margin_mode(pair, self.collateral) - self._set_leverage(leverage, pair) + if self.trading_mode != TradingMode.SPOT: + self.set_margin_mode(pair, self.collateral) + self._set_leverage(leverage, pair) - def _get_params(self, time_in_force: str, ordertype: str, leverage: float) -> Dict: + def _get_params(self, ordertype: str, leverage: float, time_in_force: str = 'gtc') -> Dict: params = self._params.copy() if time_in_force != 'gtc' and ordertype != 'market': param = self._ft_has.get('time_in_force_parameter', '') @@ -790,10 +791,7 @@ class Exchange: dry_order = self.create_dry_run_order(pair, ordertype, side, amount, rate, leverage) return dry_order - if self.trading_mode != TradingMode.SPOT: - self._lev_prep(pair, leverage) - - params = self._get_params(time_in_force, ordertype, leverage) + params = self._get_params(ordertype, leverage, time_in_force) try: # Set the precision for amount and price(rate) as accepted by the exchange @@ -802,6 +800,7 @@ class Exchange: or self._api.options.get("createMarketBuyOrderRequiresPrice", False)) rate_for_order = self.price_to_precision(pair, rate) if needs_price else None + self._lev_prep(pair, leverage) order = self._api.create_order(pair, ordertype, side, amount, rate_for_order, params) self._log_exchange_response('create_order', order) diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index 0f572dee9..62adea04c 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -81,6 +81,7 @@ class Ftx(Exchange): params['stopPrice'] = stop_price amount = self.amount_to_precision(pair, amount) + self._lev_prep(pair, leverage) order = self._api.create_order(symbol=pair, type=ordertype, side=side, amount=amount, params=params) self._log_exchange_response('create_stoploss_order', order) diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index ec49c963f..19d0a4967 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -184,8 +184,8 @@ class Kraken(Exchange): """ return - def _get_params(self, time_in_force: str, ordertype: str, leverage: float) -> Dict: - params = super()._get_params(time_in_force, ordertype, leverage) + def _get_params(self, ordertype: str, leverage: float, time_in_force: str = 'gtc') -> Dict: + params = super()._get_params(ordertype, leverage, time_in_force) if leverage > 1.0: params['leverage'] = leverage return params