From e49ab2593cc2fbfc65e4c95d519256d24c601578 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 28 Mar 2024 06:49:02 +0100 Subject: [PATCH] Update / improve docs --- docs/strategy-callbacks.md | 13 ++++++++----- freqtrade/strategy/interface.py | 5 +++-- .../strategy_methods_advanced.j2 | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index cd84bc2ba..b4eb4e395 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -19,7 +19,7 @@ Currently available callbacks: * [`adjust_trade_position()`](#adjust-trade-position) * [`adjust_entry_price()`](#adjust-entry-price) * [`leverage()`](#leverage-callback) -* [`order_filled()`](#oder-filled-callback) +* [`order_filled()`](#order-filled-callback) !!! Tip "Callback calling sequence" You can find the callback calling sequence in [bot-basics](bot-basics.md#bot-execution-logic) @@ -1026,17 +1026,20 @@ Defining a stoploss of 10% at 10x leverage would trigger the stoploss with a 1% ## Order filled Callback -The `order_filled()` callback may be used by strategy developer to perform specific actions based on current trade state after an order is filled. +The `order_filled()` callback may be used to perform specific actions based on the current trade state after an order is filled. +It will be called independently of the order type (entry, exit, stoploss or position adjustment). -Assuming that your strategy need to store the high value of the candle at trade entry, this is possible with this callback as the following example show. +Assuming that your strategy needs to store the high value of the candle at trade entry, this is possible with this callback as the following example show. ``` python class AwesomeStrategy(IStrategy): def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None: """ - Called just ofter order filling - :param pair: Pair for trade that's just exited. + Called right after an order fills. + Will be called for all order types (entry, exit, stoploss, position adjustment). + :param pair: Pair for trade :param trade: trade object. + :param order: Order object. :param current_time: datetime object, containing the current datetime :param **kwargs: Ensure to keep this here so updates to this won't break your strategy. """ diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index b3c6648e3..f8a890d5d 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -375,8 +375,9 @@ class IStrategy(ABC, HyperStrategyMixin): def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None: """ - Called just ofter order filling - :param pair: Pair for trade that's just exited. + Called right after an order fills. + Will be called for all order types (entry, exit, stoploss, position adjustment). + :param pair: Pair for trade :param trade: trade object. :param order: Order object. :param current_time: datetime object, containing the current datetime diff --git a/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 b/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 index 6fad129c7..541c26e87 100644 --- a/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 +++ b/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 @@ -300,3 +300,17 @@ def leverage(self, pair: str, current_time: datetime, current_rate: float, :return: A leverage amount, which is between 1.0 and max_leverage. """ return 1.0 + + +def order_filled(self, pair: str, trade: 'Trade', order: 'Order', + current_time: datetime, **kwargs) -> None: + """ + Called right after an order fills. + Will be called for all order types (entry, exit, stoploss, position adjustment). + :param pair: Pair for trade + :param trade: trade object. + :param order: Order object. + :param current_time: datetime object, containing the current datetime + :param **kwargs: Ensure to keep this here so updates to this won't break your strategy. + """ + pass