From 8d74e8b8dd4f1a3f45dae8baf707ea5d2585155e Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Feb 2025 06:55:54 +0100 Subject: [PATCH] feat: add adjust_order_price callback --- freqtrade/strategy/interface.py | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 77fe2a84a..d43057b32 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -690,6 +690,103 @@ class IStrategy(ABC, HyperStrategyMixin): """ return current_order_rate + def adjust_exit_price( + self, + trade: Trade, + order: Order | None, + pair: str, + current_time: datetime, + proposed_rate: float, + current_order_rate: float, + entry_tag: str | None, + side: str, + **kwargs, + ) -> float: + """ + Exit price re-adjustment logic, returning the user desired limit price. + This only executes when a order was already placed, still open (unfilled fully or partially) + and not timed out on subsequent candles after entry trigger. + + For full documentation please go to https://www.freqtrade.io/en/latest/strategy-callbacks/ + + When not implemented by a strategy, returns current_order_rate as default. + If current_order_rate is returned then the existing order is maintained. + If None is returned then order gets canceled but not replaced by a new one. + + :param pair: Pair that's currently analyzed + :param trade: Trade object. + :param order: Order object + :param current_time: datetime object, containing the current datetime + :param proposed_rate: Rate, calculated based on pricing settings in entry_pricing. + :param current_order_rate: Rate of the existing order in place. + :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal. + :param side: 'long' or 'short' - indicating the direction of the proposed trade + :param **kwargs: Ensure to keep this here so updates to this won't break your strategy. + :return float: New entry price value if provided + + """ + return current_order_rate + + def adjust_order_price( + self, + trade: Trade, + order: Order | None, + pair: str, + current_time: datetime, + proposed_rate: float, + current_order_rate: float, + entry_tag: str | None, + side: str, + **kwargs, + ) -> float: + """ + Exit and entry order price re-adjustment logic, returning the user desired limit price. + This only executes when a order was already placed, still open (unfilled fully or partially) + and not timed out on subsequent candles after entry trigger. + + For full documentation please go to https://www.freqtrade.io/en/latest/strategy-callbacks/ + + When not implemented by a strategy, returns current_order_rate as default. + If current_order_rate is returned then the existing order is maintained. + If None is returned then order gets canceled but not replaced by a new one. + + :param pair: Pair that's currently analyzed + :param trade: Trade object. + :param order: Order object + :param current_time: datetime object, containing the current datetime + :param proposed_rate: Rate, calculated based on pricing settings in entry_pricing. + :param current_order_rate: Rate of the existing order in place. + :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal. + :param side: 'long' or 'short' - indicating the direction of the proposed trade + :param **kwargs: Ensure to keep this here so updates to this won't break your strategy. + :return float: New entry price value if provided + + """ + if order.side == trade.entry_side: + return self.adjust_entry_price( + trade=trade, + order=order, + pair=pair, + current_time=current_time, + proposed_rate=proposed_rate, + current_order_rate=current_order_rate, + entry_tag=entry_tag, + side=side, + **kwargs, + ) + else: + return self.adjust_exit_price( + trade=trade, + order=order, + pair=pair, + current_time=current_time, + proposed_rate=proposed_rate, + current_order_rate=current_order_rate, + entry_tag=entry_tag, + side=side, + **kwargs, + ) + def leverage( self, pair: str,