From 6941953a8be6bd52dc701d3af905166f2988721e Mon Sep 17 00:00:00 2001 From: Axel-CH Date: Mon, 18 Mar 2024 21:38:58 -0400 Subject: [PATCH] update doc details about order_filled callback details --- docs/bot-basics.md | 4 ++++ docs/strategy-callbacks.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/docs/bot-basics.md b/docs/bot-basics.md index a19f005db..424a26269 100644 --- a/docs/bot-basics.md +++ b/docs/bot-basics.md @@ -42,6 +42,8 @@ This will also run the `bot_start()` callback. By default, the bot loop runs every few seconds (`internals.process_throttle_secs`) and performs the following actions: * Fetch open trades from persistence. + * Update trades open order state from exchange + * Call `order_filled()` stategy callback for filled orders. * Calculate current list of tradable pairs. * Download OHLCV data for the pairlist including all [informative pairs](strategy-customization.md#get-data-for-non-tradeable-pairs) This step is only executed once per Candle to avoid unnecessary network traffic. @@ -86,8 +88,10 @@ This loop will be repeated again and again until the bot is stopped. * In Margin and Futures mode, `leverage()` strategy callback is called to determine the desired leverage. * Determine stake size by calling the `custom_stake_amount()` callback. * Check position adjustments for open trades if enabled and call `adjust_trade_position()` to determine if an additional order is requested. + * Call `order_filled()` stategy callback for filled entry orders. * Call `custom_stoploss()` and `custom_exit()` to find custom exit points. * For exits based on exit-signal, custom-exit and partial exits: Call `custom_exit_price()` to determine exit price (Prices are moved to be within the closing candle). + * Call `order_filled()` stategy callback for filled exit orders. * Generate backtest report output !!! Note diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index 2f04e906e..bc5ad3cad 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -19,6 +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) !!! Tip "Callback calling sequence" You can find the callback calling sequence in [bot-basics](bot-basics.md#bot-execution-logic) @@ -1022,3 +1023,30 @@ class AwesomeStrategy(IStrategy): All profit calculations include leverage. Stoploss / ROI also include leverage in their calculation. Defining a stoploss of 10% at 10x leverage would trigger the stoploss with a 1% move to the downside. + +## 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. + +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 exemple 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. + :param trade: trade 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. + """ + # Obtain pair dataframe (just to show how to access it) + dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe) + last_candle = dataframe.iloc[-1].squeeze() + + if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side): + trade.set_custom_data(key='entry_candle_high', value=last_candle['high']) + + return None + +```