Generate code in 3 minutes
Enter your idea and AI generates runnable code.
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.
QuantConnect has updated its Python API to follow PEP8 standards. This involves:
Resolution.Minute $\rightarrow$ Resolution.MINUTE).self.AddEquity $\rightarrow$ self.add_equity).self.Portfolio $\rightarrow$ self.portfolio).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.
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.
Besides constants, ensure that:
self.SetCash() becomes self.set_cash()).self.Securities becomes self.securities).def OnData(self, data): becomes def on_data(self, data):).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.