Hey, thanks in advance. This has ran smoothly for years. All of a sudden, 2 weeks ago, when I check the current price on QQQ 1 min after open, it throws this error on 75% of my mornings. I noticed there has been a change in the initiation of the algo. I had to manually go back in and add two sources for data to include interactive brokers with Quantconnect. Maybe this has had an effect? Anyone having a similar issue?
Line of code:
qqqopenbar = self.algorithm.CurrentSlice['QQQ']
Error:
Runtime Error: 'QQQ' wasn't found in the Slice object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("QQQ")
at OpeningBarQQQ
qqqopenbar = self.algorithm.CurrentSlice['QQQ']
in event_handlers.py: line 13
Stack Trace: 'QQQ' wasn't found in the Slice object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("QQQ")
at OpeningBarQQQ
qqqopenbar = self.algorithm.CurrentSlice['QQQ']
in event_handlers.py: line 13Share a new discussion
Mia Alissi
The error message you're seeing is indicating that there is no data for 'QQQ' at the moment in time you're trying to access it. This could be due to a variety of reasons such as a delay in data feed or the market being closed at the time of access.
Before accessing the data, you should check if the data exists. You can do this by using the
ContainsKeymethod. Here's how you can modify your code:This code checks if 'QQQ' data is present in the current slice before trying to access it, which should prevent the
KeyNotFoundExceptionfrom being thrown.If you're still encountering issues, it might be helpful to add a warm-up period to your algorithm. This allows your algorithm to preload a specified period of data before starting operations, ensuring that the data is ready when you need it.
In the
OnDatamethod, you can then check if the warm-up period is over before accessing the data:These suggestions are based on the information provided in the knowledge sources. If the problem persists, it might be related to the changes you mentioned in the initiation of the algorithm or the data sources. In that case, you might want to review those changes or seek 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.
David E
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!