{"id":27323,"library":"quantconnect-stubs","title":"QuantConnect Stubs (Lean)","description":"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.","status":"active","version":"17685","language":"python","source_language":"en","source_url":"https://github.com/QuantConnect/quantconnect-stubs-generator","tags":["quantconnect","lean","stubs","type-hints","trading"],"install":[{"cmd":"pip install quantconnect-stubs","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"The stubs are for the QuantConnect Lean engine, which must be installed separately (not on PyPI; typically via Docker or local build).","package":"QuantConnect","optional":false}],"imports":[{"note":"This is the correct import for the base algorithm class.","symbol":"QCAlgorithm","correct":"from Algorithm import QCAlgorithm"},{"note":"Order types are in the Orders namespace.","symbol":"OrderType","correct":"from QuantConnect.Orders import OrderType"},{"note":"Core symbol type.","symbol":"Symbol","correct":"from QuantConnect import Symbol"}],"quickstart":{"code":"from Algorithm import QCAlgorithm\n\nclass MyAlgorithm(QCAlgorithm):\n    def Initialize(self):\n        self.SetStartDate(2020, 1, 1)\n        self.SetEndDate(2020, 12, 31)\n        self.SetCash(100000)\n        self.AddEquity(\"SPY\", Resolution.Minute)\n\n    def OnData(self, data):\n        if not self.Portfolio.Invested:\n            self.SetHoldings(\"SPY\", 1.0)","lang":"python","description":"Basic QuantConnect algorithm using stubs for type hints."},"warnings":[{"fix":"Pin to a specific version and test after upgrade: pip install quantconnect-stubs==17685","message":"Stubs version numbers are build-based, not semver. Upgrading may introduce incompatible type signatures without a major version bump.","severity":"breaking","affected_versions":"all"},{"fix":"Validate against official QuantConnect documentation for APIs used.","message":"The stubs are generated and may contain incomplete or incorrect type annotations. Do not rely on them for runtime behavior.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the new import path: from Algorithm import QCAlgorithm","message":"Old import paths like 'from QuantConnect.Algorithm import QCAlgorithm' may work but are deprecated in favor of 'from Algorithm import QCAlgorithm'.","severity":"deprecated","affected_versions":">=17685"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install quantconnect-stubs in the same Python environment as your IDE: pip install quantconnect-stubs","cause":"IDE cannot locate the stubs because the package is not installed or the interpreter path is wrong.","error":"Cannot find reference 'QCAlgorithm' in '__init__.py'"},{"fix":"Add 'from __future__ import annotations' at the top of your file, or upgrade to Python 3.9+.","cause":"Using generic type annotations with built-in types in Python 3.8 or earlier (e.g., list[int]) without importing from __future__.","error":"TypeError: 'type' object is not subscriptable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}