diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 12326f083..15796bdcb 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -32,13 +32,17 @@ class Binance(Exchange): return super().get_order_book(pair, limit) - def stoploss_limit(self, pair: str, amount: float, stop_price: float, rate: float) -> Dict: + def stoploss_limit(self, pair: str, amount: float, stop_price: float, + order_types: Dict) -> Dict: """ creates a stoploss limit order. this stoploss-limit is binance-specific. It may work with a limited number of other exchanges, but this has not been tested yet. - """ + # Limit price threshold: As limit price should always be below stop-price + LIMIT_PRICE_PCT = order_types.get('stoploss_on_exchange_limit_ratio', 0.99) + rate = stop_price * LIMIT_PRICE_PCT + ordertype = "stop_loss_limit" stop_price = self.price_to_precision(pair, stop_price) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 87c189457..4c5ef823b 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -519,7 +519,8 @@ class Exchange: return self.create_order(pair, ordertype, 'sell', amount, rate, params) - def stoploss_limit(self, pair: str, amount: float, stop_price: float, rate: float) -> Dict: + def stoploss_limit(self, pair: str, amount: float, stop_price: float, + order_types: Dict) -> Dict: """ creates a stoploss limit order. Since ccxt does not unify stoploss-limit orders yet, this needs to be implemented in each diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index e712892f1..1a3097c25 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -636,13 +636,10 @@ class FreqtradeBot: Force-sells the pair (using EmergencySell reason) in case of Problems creating the order. :return: True if the order succeeded, and False in case of problems. """ - # Limit price threshold: As limit price should always be below stop-price - LIMIT_PRICE_PCT = self.strategy.order_types.get('stoploss_on_exchange_limit_ratio', 0.99) - try: stoploss_order = self.exchange.stoploss_limit(pair=trade.pair, amount=trade.amount, stop_price=stop_price, - rate=rate * LIMIT_PRICE_PCT) + order_types=self.strategy.order_types) trade.stoploss_order_id = str(stoploss_order['id']) return True except InvalidOrderException as e: