From 821e299afb77181dcaf9c66c95beccbbaf3529e6 Mon Sep 17 00:00:00 2001 From: misagh Date: Sun, 6 Jan 2019 14:45:29 +0100 Subject: [PATCH] adjusting trailing stoploss on exchange --- freqtrade/freqtradebot.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 4febe9dd0..6d3f7db07 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -648,7 +648,17 @@ class FreqtradeBot(object): trade.update(order) result = True else: - result = False + # check if trailing stoploss is enabled and stoploss value has changed + # in which case we cancel stoploss order and put another one with new + # value immediately + if self.config.get('trailing_stop', False) and trade.stop_loss > order['price']: + if self.exchange.cancel_order(order['id'], trade.pair): + stoploss_order_id = self.exchange.stoploss_limit( + pair=trade.pair, amount=trade.amount, + stop_price=stop_price, rate=limit_price + )['id'] + trade.stoploss_order_id = str(stoploss_order_id) + return result def check_sell(self, trade: Trade, sell_rate: float, buy: bool, sell: bool) -> bool: