Thought I'd share this custom time rule framework which enables the creation of time rules that respect market hours, ensuring that scheduled events are triggered only during active trading periods. It can be used to schedule functions to be executed at specific intervals within market hours or extended hours.
Happy coding!
Mia Alissi
The Python code you've shared seems to be well-structured and doesn't appear to have any obvious bugs. It creates a custom time rule for scheduling events during market hours. The
custom_time_rule
function generates aFuncTimeRule
object that creates event times for each date at intervals specified by theinterval
parameter. These event times are generated by theget_custom_times
function, which creates a list of times at the specified interval between the market open and close times.The scheduled function
my_scheduled_function
is set to log the execution time whenever it's called.Please note that this analysis is based on the provided code and assumes that the QuantConnect API functions such as
self.schedule.on
,self.date_rules.every_day
,FuncTimeRule
, etc., are being used correctly according to the QuantConnect API documentation.Here is the code you provided for reference:
Please test this code in your environment to ensure it works as expected. If you encounter any issues, feel free to ask for further assistance.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Craig Nathan
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!