🚀 AI One-Click Generation of quantconnect Strategy Code

How to Update Constants like Resolution and OrderStatus for the QuantConnect PEP8 API

quantconnect | Published on: 2025/12/9
The following content is generated by EasyQuant .

Problem Description

My old trading code uses `Resolution.Minute` and is now broken, how do I fix it?

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:

  1. Constants: Changed from CamelCase to UPPERCASE (e.g., Resolution.Minute $\rightarrow$ Resolution.MINUTE).
  2. Methods: Changed from PascalCase to snake_case (e.g., self.AddEquity $\rightarrow$ self.add_equity).
  3. 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:

  1. Method calls are in snake_case (e.g., self.SetCash() becomes self.set_cash()).
  2. Properties are in snake_case (e.g., self.Securities becomes self.securities).
  3. Event handlers are in snake_case (e.g., def OnData(self, data): becomes def 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.