From bfbdddff26bd9296da0b046f260db1ce5778b703 Mon Sep 17 00:00:00 2001 From: misagh Date: Thu, 22 Nov 2018 16:24:40 +0100 Subject: [PATCH] stoploss limit order added to exchange --- freqtrade/exchange/__init__.py | 18 ++++++++++++++++++ freqtrade/strategy/interface.py | 2 ++ 2 files changed, 20 insertions(+) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index ae07e36e9..59a5da23e 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -333,6 +333,24 @@ class Exchange(object): except ccxt.BaseError as e: raise OperationalException(e) + def stoploss_limit(self, pair: str, amount: float, stop_price: float, rate: float) -> Dict: + # Only binance is supported + if not self._api.name == 'Binance': + raise NotImplementedError( + 'Stoploss limit orders are implemented only for binance as of now.') + + # Set the precision for amount and price(rate) as accepted by the exchange + amount = self.symbol_amount_prec(pair, amount) + rate = self.symbol_price_prec(pair, rate) + stop_price = self.symbol_price_prec(pair, stop_price) + + # Ensure rate is less than stop price + if stop_price >= rate: + raise OperationalException( + 'In stoploss limit order, stop price should be more than limit price') + + return self._api.create_order(pair, 'stop_loss', 'sell', amount, rate, {'stopPrice': stop_price}) + @retrier def get_balance(self, currency: str) -> float: if self._conf['dry_run']: diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 9b7b180cc..df0e3cf72 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -233,8 +233,10 @@ class IStrategy(ABC): stoplossflag = self.stop_loss_reached(current_rate=current_rate, trade=trade, current_time=date, current_profit=current_profit, force_stoploss=force_stoploss) + if stoplossflag.sell_flag: return stoplossflag + # Set current rate to low for backtesting sell current_rate = high or rate current_profit = trade.calc_profit_percent(current_rate)