📘Get Ahead! Freqtrade Strategy “Startup + Loop” Dual Core, Trading Bot Mastery Guide!

This article was produced by the Quantitative Trading Lab at https://www.itrade.icu. Visit for more benefits. In the Freqtrade strategy framework, bot_start() and bot_loop_start() are two important lifecycle callback functions. They allow developers to insert custom logic at the bot’s startup and at the start of each main loop. Understanding and properly using these two functions can help you control the trading bot more flexibly, improving strategy performance and extensibility.


⚙️ bot_start() - Bot Startup

Purpose

  • Called once after the bot starts and completes initialization.

  • Suitable for placing logic that needs to run at startup, such as:

    • Preloading data

    • Initializing custom resources or services

    • Sending startup notifications

    • Printing welcome messages or logs

Notes

  • Triggered only once at startup

  • Should not block for too long to avoid affecting startup efficiency

Example Code

def bot_start(self, **kwargs):
    """
    Called once when the bot starts.
    """
    print("[bot_start] Bot starting, initializing resources...")
    # Example: load additional data
    self.custom_data = self.load_custom_data()
    print("[bot_start] Custom data loaded.")

def load_custom_data(self):
    # Example custom data loading function
    return {"key": "value"}

⚙️ bot_loop_start() - Bot Loop Execution

Purpose

  • Called at the start of each main trading loop (i.e., at the beginning of each new event loop iteration)

  • Suitable for:

    • Refreshing status at the start of each loop

    • Monitoring or logging

    • Dynamically adjusting parameters

    • Periodically calling external APIs

Notes

  • May be called multiple times, so logic should be lightweight to avoid blocking

  • Can be used to dynamically adjust strategy configuration at runtime

Example Code


🔍 Combined Example: Practical Use Case


🧠 Summary

Callback Function
Trigger Timing
Typical Use Case
Notes

bot_start()

Called once after bot startup

Initialize data, custom resources, send notifications

Should be quick, non-blocking

bot_loop_start()

Called at the start of each main loop

Refresh state dynamically, logging, fetch external data

Called multiple times, keep lightweight


By properly using bot_start() and bot_loop_start(), you can insert custom logic at key lifecycle points of a Freqtrade trading bot, enhancing strategy flexibility and runtime efficiency. These two functions are core components of the strategy callback interface, and mastering them can effectively support the development and debugging of complex trading strategies.

Last updated