Is there still no way to correctly log the time in a live algo according to your time zone? The logs on live run from open at 13:30 to close around 22:00. I'm in west coast and so that corresponds to 6:30am to 1pm and I'd rather my live logs be correctly time stamped to my time zone for debugging purposes. Any help would be appreciated.
Mia Alissi
To ensure your live algorithm logs are correctly timestamped to your time zone (Pacific Time), you should follow these steps:
Set the Algorithm Time Zone: Utilize the
set_time_zone
method in your algorithm'sinitialize
method to specify your desired time zone. For Pacific Time, you can use:This will set your algorithm's time zone to Pacific Time, so all time-related functions within the algorithm will adhere to this time zone.
Log Messages with Local Time: Whenever you log a message, convert the
self.Time
to your algorithm's local time to ensure the log shows accurate local timestamps. You can do this by using:Since
self.Time
will now reflect the time in "America/Los_Angeles", it will log the correct local time.Backtesting and Live Mode: The same code will work for both backtesting and live mode. In live mode, the log will also reflect the local time according to the
set_time_zone
setting.Here's how the relevant portion of your
QCAlgorithm
might look to incorporate these changes:By following these steps, your live logs should now correctly reflect Pacific Time, simplifying your debugging process.
Sources: Time Zones - QuantConnect.com, Initialization - QuantConnect.com, Charting and Logging - QuantConnect.com, Logging - QuantConnect.com
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!