def before_market_opens#

This lifecycle method is executed each day before market opens. If the strategy is first run when the market is already open, this method will be skipped the first day. Use this lifecycle methods to execute business logic before starting trading like canceling all open orders.

class MyStrategy(Strategy):
    def before_market_opens(self):
def before_starting_trading()

This lifecycle method is similar to before_market_opens. However, unlike before_market_opens, this method will always be executed before starting trading even if the market is already open when the strategy was first launched. After the first execution, both methods will be executed in the following order



Use this lifecycle method to execude code self.minutes_before_opening minutes before opening.

Return type:



>>> # Get the data for SPY and TLT for the last 2 days
>>> def before_market_opens(self):
>>>     bars_list =  self.get_historical_prices_for_assets(["SPY", "TLT"], 2, "day")
>>>     for asset_bars in bars_list:
>>>         self.log_message(asset_bars.df)