From b90aa6ea0bae1342f99c37ff48e9f08d40ba94cf Mon Sep 17 00:00:00 2001 From: ZerGo0 <18653821+ZerGo0@users.noreply.github.com> Date: Fri, 20 Aug 2021 22:07:35 +0200 Subject: [PATCH] Added buy_tag to sell signal outputs --- freqtrade/strategy/interface.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index c51860011..c5339adca 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -655,12 +655,20 @@ class IStrategy(ABC, HyperStrategyMixin): # Stoploss if roi_reached and stoplossflag.sell_type != SellType.STOP_LOSS: logger.debug(f"{trade.pair} - Required profit reached. sell_type=SellType.ROI") + if hasattr(trade, 'buy_tag') and trade.buy_tag is not None: + sell_reason = f'{SellType.ROI} ({trade.buy_tag})' + return SellCheckTuple(sell_type=SellType.ROI, sell_reason=sell_reason) return SellCheckTuple(sell_type=SellType.ROI) if sell_signal != SellType.NONE: logger.debug(f"{trade.pair} - Sell signal received. " f"sell_type=SellType.{sell_signal.name}" + (f", custom_reason={custom_reason}" if custom_reason else "")) + if hasattr(trade, 'buy_tag') and trade.buy_tag is not None: + if custom_reason: + custom_reason += f' ({trade.buy_tag})' + else: + custom_reason = f'{sell_signal} ({trade.buy_tag})' return SellCheckTuple(sell_type=sell_signal, sell_reason=custom_reason) if stoplossflag.sell_flag: @@ -725,10 +733,15 @@ class IStrategy(ABC, HyperStrategyMixin): (not self.order_types.get('stoploss_on_exchange') or self.config['dry_run'])): sell_type = SellType.STOP_LOSS + sell_reason = None + if hasattr(trade, 'buy_tag') and trade.buy_tag is not None: + sell_reason = f'{sell_type} ({trade.buy_tag})' # If initial stoploss is not the same as current one then it is trailing. if trade.initial_stop_loss != trade.stop_loss: sell_type = SellType.TRAILING_STOP_LOSS + if hasattr(trade, 'buy_tag') and trade.buy_tag is not None: + sell_reason = f'{sell_type} ({trade.buy_tag})' logger.debug( f"{trade.pair} - HIT STOP: current price at {(low or current_rate):.6f}, " f"stoploss is {trade.stop_loss:.6f}, " @@ -737,6 +750,9 @@ class IStrategy(ABC, HyperStrategyMixin): logger.debug(f"{trade.pair} - Trailing stop saved " f"{trade.stop_loss - trade.initial_stop_loss:.6f}") + if sell_reason is not None: + return SellCheckTuple(sell_type=sell_type, sell_reason=sell_reason) + return SellCheckTuple(sell_type=sell_type) return SellCheckTuple(sell_type=SellType.NONE)