Problem Description
Solution
Based on the QuantConnect PEP8 API migration, the issue is likely due to the change in naming conventions for constants. In the new API, constants like resolution are now fully uppercase.
To fix your code, you need to change Resolution.Minute to Resolution.MINUTE.
Explanation
QuantConnect has updated its Python API to follow PEP8 standards. This involves:
- Constants: Changed from CamelCase to UPPERCASE (e.g.,
Resolution.Minute$\rightarrow$Resolution.MINUTE). - Methods: Changed from PascalCase to snake_case (e.g.,
self.AddEquity$\rightarrow$self.add_equity). - Properties: Changed from PascalCase to snake_case (e.g.,
self.Portfolio$\rightarrow$self.portfolio).
Code Fix Example
Before (Old API):
# Old format
self.AddEquity("SPY", Resolution.Minute)
self.ema = self.EMA("SPY", 14, Resolution.Minute)
After (New PEP8 API):
# New format
self.add_equity("SPY", Resolution.MINUTE)
self.ema = self.ema("SPY", 14, Resolution.MINUTE)
If your entire algorithm was written in the old style, you may encounter other errors regarding method names (e.g., OnData vs on_data). You can either update the syntax manually or select the older LEAN engine version ("master v16356") in your project settings to keep using the old syntax temporarily.
Q&A
Why is Resolution.Minute throwing an error in QuantConnect?
QuantConnect migrated its Python API to PEP8 standards. As part of this migration, enumeration members and constants were renamed to use UPPERCASE. Therefore, Resolution.Minute must now be written as Resolution.MINUTE.
What other changes should I look for when migrating to the new API?
Besides constants, ensure that:
- Method calls are in snake_case (e.g.,
self.SetCash()becomesself.set_cash()). - Properties are in snake_case (e.g.,
self.Securitiesbecomesself.securities). - Event handlers are in snake_case (e.g.,
def OnData(self, data):becomesdef on_data(self, data):).
Can I still use the old API format?
Yes, temporarily. You can select the "master v16356" version of the LEAN engine in the "LEAN Engine" section of your project panel. However, new projects default to the PEP8 version, and migration is recommended for long-term support.