QuantConnect Stubs (Lean)
raw JSON → 17685 verified Mon Apr 27 auth: no python
Type stubs for QuantConnect's Lean algorithmic trading engine, enabling type hints and static analysis in Python. Current version 17685 (based on a build number; no standard semver). Released frequently as Lean evolves.
pip install quantconnect-stubs Common errors
error Cannot find reference 'QCAlgorithm' in '__init__.py' ↓
cause IDE cannot locate the stubs because the package is not installed or the interpreter path is wrong.
fix
Install quantconnect-stubs in the same Python environment as your IDE: pip install quantconnect-stubs
error TypeError: 'type' object is not subscriptable ↓
cause Using generic type annotations with built-in types in Python 3.8 or earlier (e.g., list[int]) without importing from __future__.
fix
Add 'from __future__ import annotations' at the top of your file, or upgrade to Python 3.9+.
Warnings
breaking Stubs version numbers are build-based, not semver. Upgrading may introduce incompatible type signatures without a major version bump. ↓
fix Pin to a specific version and test after upgrade: pip install quantconnect-stubs==17685
gotcha The stubs are generated and may contain incomplete or incorrect type annotations. Do not rely on them for runtime behavior. ↓
fix Validate against official QuantConnect documentation for APIs used.
deprecated Old import paths like 'from QuantConnect.Algorithm import QCAlgorithm' may work but are deprecated in favor of 'from Algorithm import QCAlgorithm'. ↓
fix Use the new import path: from Algorithm import QCAlgorithm
Imports
- QCAlgorithm
from Algorithm import QCAlgorithm - OrderType
from QuantConnect.Orders import OrderType - Symbol
from QuantConnect import Symbol
Quickstart
from Algorithm import QCAlgorithm
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2020, 12, 31)
self.SetCash(100000)
self.AddEquity("SPY", Resolution.Minute)
def OnData(self, data):
if not self.Portfolio.Invested:
self.SetHoldings("SPY", 1.0)