From f6fce2162c4238bdf279b92dc214566c6129bf7d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 17 Sep 2023 19:57:13 +0200 Subject: [PATCH] Add new parameter to strategy template --- docs/strategy-callbacks.md | 1 + freqtrade/freqtradebot.py | 3 +-- .../strategy_subtemplates/strategy_methods_advanced.j2 | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index d4950cfdd..e42aa39d2 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -512,6 +512,7 @@ Each of these methods are called right before placing an order on the exchange. !!! Note Using custom_entry_price, the Trade object will be available as soon as the first entry order associated with the trade is created, for the first entry, `trade` parameter value will be `None`. + ### Custom order entry and exit price example ``` python diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 1dd7884e0..983d5c826 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -937,8 +937,7 @@ class FreqtradeBot(LoggingMixin): # Don't call custom_entry_price in order-adjust scenario custom_entry_price = strategy_safe_wrapper(self.strategy.custom_entry_price, default_retval=enter_limit_requested)( - pair=pair, - trade=trade, + pair=pair, trade=trade, current_time=datetime.now(timezone.utc), proposed_rate=enter_limit_requested, entry_tag=entry_tag, side=trade_side, diff --git a/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 b/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 index 4e1875084..6fad129c7 100644 --- a/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 +++ b/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 @@ -13,7 +13,8 @@ def bot_loop_start(self, current_time: datetime, **kwargs) -> None: """ pass -def custom_entry_price(self, pair: str, current_time: 'datetime', proposed_rate: float, +def custom_entry_price(self, pair: str, trade: Optional['Trade'], + current_time: 'datetime', proposed_rate: float, entry_tag: 'Optional[str]', side: str, **kwargs) -> float: """ Custom entry price logic, returning the new entry price. @@ -23,6 +24,7 @@ def custom_entry_price(self, pair: str, current_time: 'datetime', proposed_rate: When not implemented by a strategy, returns None, orderbook is used to set entry price :param pair: Pair that's currently analyzed + :param trade: trade object (None for initial entries). :param current_time: datetime object, containing the current datetime :param proposed_rate: Rate, calculated based on pricing settings in exit_pricing. :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.