### Install and Verify Lean CLI Source: https://context7.com/quantconnect/lean-cli/llms.txt Install the Lean CLI using pip and verify the installation by checking the version and available commands. ```bash pip install --upgrade lean ``` ```bash lean --version ``` ```bash lean --help ``` -------------------------------- ### Create Local Project Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Create a new project locally with some basic code to get started. This is the first step in a locally-focused workflow. ```bash lean create-project "Project Name" ``` -------------------------------- ### lean private-cloud start Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Starts a new private cloud environment. ```APIDOC ## lean private-cloud start ### Description Start a new private cloud. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Command Line Options - **--master** (BOOLEAN) - Run in master mode. - **--slave** (BOOLEAN) - Run in slave mode. - **--token** (TEXT) - The master server token. - **--master-domain, --master-ip** (TEXT) - The master server domain or IP address. - **--master-port** (INTEGER) - The master server port. - **--slave-domain, --slave-ip** (TEXT) - The slave server domain or IP address. - **--update** (BOOLEAN) - Pull the latest image before starting. - **--no-update** (BOOLEAN) - Do not update to the latest version. - **--compute** (TEXT) - Compute configuration to use. - **--extra-docker-config** (TEXT) - Extra docker configuration as a JSON string. - **--stop** (BOOLEAN) - Stop any existing deployment. - **--lean-config** (FILE) - The Lean configuration file that should be used (defaults to the nearest lean.json). - **--verbose** (BOOLEAN) - Enable debug logging. - **--help** (BOOLEAN) - Show this message and exit. ``` -------------------------------- ### Build and Install Lean CLI Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Builds the Lean CLI source distribution and wheel, then installs the wheel. This is typically done after making changes to the project. ```bash python setup.py sdist bdist_wheel ``` ```bash pip install --force-reinstall dist/lean-dev-py3-none-any.whl ``` -------------------------------- ### Interactive Live Deployment Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts an interactive wizard for deploying a trading strategy for live trading. ```bash lean live deploy "My Trading Strategy" ``` -------------------------------- ### List All Configuration Options Source: https://context7.com/quantconnect/lean-cli/llms.txt Displays all current configuration settings for the LEAN CLI. Useful for understanding the current setup. ```bash lean config list ``` -------------------------------- ### Install Lean CLI Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Install or upgrade the Lean CLI using pip. Ensure Docker is installed for many commands to function. ```bash pip install --upgrade lean ``` -------------------------------- ### Start Research Environment Source: https://context7.com/quantconnect/lean-cli/llms.txt Launches a Jupyter Lab environment for interactive research and analysis using the LEAN framework. ```bash lean research "My Trading Strategy" ``` -------------------------------- ### Start Private Cloud Slave Node Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts a slave node for a private cloud deployment, connecting it to the master node. Requires master domain, port, and a token. ```bash lean private-cloud start --slave \ --master-domain "master.example.com" \ --master-port 443 \ --token "your-token" ``` -------------------------------- ### Start Private Cloud Master Node Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts the master node for a private cloud deployment. Requires a token for authentication. ```bash lean private-cloud start --master --token "your-token" ``` -------------------------------- ### Install Lean CLI Dependencies Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Installs the required dependencies for the Lean CLI and installs the CLI in editable mode. This allows for immediate reflection of code changes. ```bash pip install -r requirements.txt ``` -------------------------------- ### Start Local Research Environment Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Start a Jupyter Lab session for local research and development within your project directory. This provides an interactive environment for strategy development. ```bash lean research "Project Name" ``` -------------------------------- ### lean live deploy Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Starts live trading a project locally using Docker. It supports interactive and non-interactive modes for configuration. ```APIDOC ## `lean live deploy` ### Description Start live trading a project locally using Docker. The command can execute algorithms from a specified project directory or file. ### Method CLI Command ### Endpoint N/A (Local execution) ### Parameters #### Path Parameters - **PROJECT** (string) - Required - The project directory or file containing the algorithm. #### Query Parameters - **--environment** (TEXT) - Optional - The name of the live environment to use from the Lean configuration. - **--output** (DIRECTORY) - Optional - Directory to store results in. Defaults to `PROJECT/live/TIMESTAMP`. - **-d, --detach** (boolean) - Optional - Run the live deployment in a detached Docker container and return immediately. - **--brokerage** (enum) - Optional - The brokerage to use. Options: `Paper Trading`, `Interactive Brokers`, `Tradier`, `Oanda`, `Bitfinex`, `Coinbase Advanced Trade`, `Binance`, `Zerodha`, `Samco`, `Terminal Link`, `Trading Technologies`, `Kraken`, `CharlesSchwab`, `Bybit`, `TradeStation`, `Alpaca`, `Tastytrade`, `Eze`, `dYdX`. - **--data-provider-live** (enum) - Optional - The live data provider to use. Options: `Interactive Brokers`, `Tradier`, `Oanda`, `Bitfinex`, `Coinbase Advanced Trade`, `Binance`, `Zerodha`, `Samco`, `Terminal Link`, `Trading Technologies`, `Kraken`, `CharlesSchwab`, `IQFeed`, `Polygon`, `CoinApi`, `ThetaData`, `Custom data only`, `Bybit`, `TradeStation`, `Alpaca`, `Tastytrade`, `Eze`, `dYdX`, `Databento`. - **--data-provider-historical** (enum) - Optional - Update the Lean configuration file to retrieve data from the given historical provider. Options: `Interactive Brokers`, `Oanda`, `Bitfinex`, `Coinbase Advanced Trade`, `Binance`, `Kraken`, `CharlesSchwab`, `IQFeed`, `Polygon`, `FactSet`, `AlphaVantage`, `CoinApi`, `ThetaData`, `QuantConnect`, `Local`, `Bybit`, `TradeStation`, `Alpaca`, `Tastytrade`, `Eze`, `dYdX`, `Databento`. - **--ib-user-name** (TEXT) - Optional - Your Interactive Brokers username. - **--ib-account** (TEXT) - Optional - Your Interactive Brokers account id. - **--ib-password** (TEXT) - Optional - Your Interactive Brokers password. - **--ib-weekly-restart-utc-time** (TEXT) - Optional - Weekly restart UTC time (hh:mm:ss). Required by Interactive Brokers for 2FA verification. - **--ib-financial-advisors-group-filter** (TEXT) - Optional - Filter data by a specific financial advisor group within your Interactive Brokers account. - **--tradier-account-id** (TEXT) - Optional - Your Tradier account id. - **--tradier-access-token** (TEXT) - Optional - Your Tradier access token. - **--tradier-environment** (enum) - Optional - Whether the developer sandbox should be used. Options: `live`, `paper`. - **--oanda-account-id** (TEXT) - Optional - Your OANDA account id. - **--oanda-access-token** (TEXT) - Optional - Your OANDA API token. - **--oanda-environment** (enum) - Optional - The environment to run in. Options: `Practice`, `Trade`. - **--bitfinex-api-key** (TEXT) - Optional - Your Bitfinex API key. - **--bitfinex-api-secret** (TEXT) - Optional - Your Bitfinex API secret. - **--coinbase-api-name** (TEXT) - Optional - Your Coinbase Advanced Trade API name from file. - **--coinbase-api-private-key** (TEXT) - Optional - Your Coinbase Advanced Trade API private key from file. - **--binance-exchange-name** (enum) - Optional - Binance exchange name. Options: `Binance`, `BinanceUS`, `Binance-USDM-Futures`, `Binance-COIN-Futures`. - **--binance-api-key** (TEXT) - Optional - Your Binance API key. - **--binanceus-api-key** (TEXT) - Optional - Your Binance API key. - **--binance-api-secret** (TEXT) - Optional - Your Binance API secret. - **--binanceus-api-secret** (TEXT) - Optional - Your Binance API secret. - **--binance-use-testnet** (enum) - Optional - Whether the testnet should be used. Options: `live`, `paper`. - **--zerodha-api-key** (TEXT) - Optional - Your Kite Connect API key. - **--zerodha-access-token** (TEXT) - Optional - Your Kite Connect access token. - **--zerodha-product-type** (enum) - Optional - Product type. Options: `mis`, `cnc`, `nrml`. ### Request Example ```bash lean live deploy "MyProject/Algorithm.py" --brokerage "Interactive Brokers" --ib-user-name "testuser" --ib-account "1234567" ``` ### Response #### Success Response (0) Indicates successful deployment and start of live trading. #### Response Example ``` Live trading started successfully. ``` #### Error Handling - Aborts if required brokerage/data provider options are missing or cannot be found in Lean config. - Docker must be installed and running. ``` -------------------------------- ### Get Specific Configuration Value Source: https://context7.com/quantconnect/lean-cli/llms.txt Retrieves the value of a specific configuration option. For example, to check the default programming language. ```bash lean config get default-language ``` -------------------------------- ### Research on Custom Port Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts the research environment on a specified port. ```bash lean research "My Trading Strategy" --port 8889 ``` -------------------------------- ### lean cloud live deploy Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Starts live trading for a project in the cloud. It can be run interactively or non-interactively with specified options. ```APIDOC ## `lean cloud live deploy` ### Description Start live trading for a project in the cloud. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Path Parameters - **PROJECT** (string) - Required - The name or the id of the project to start live trading for. #### Query Parameters - **--brokerage** (string) - Optional - The brokerage to use. Supported values: Paper Trading, Interactive Brokers, Tradier, Oanda, Bitfinex, Coinbase Advanced Trade, Binance, Zerodha, Samco, Terminal Link, Trading Technologies, Kraken, CharlesSchwab, Bybit, TradeStation, Alpaca, Tastytrade, Eze, dYdX. - **--data-provider-live** (string) - Optional - The live data provider to use. Supported values: QuantConnect, Interactive Brokers, Tradier, Oanda, Bitfinex, Coinbase Advanced Trade, Binance, Zerodha, Samco, Terminal Link, Trading Technologies, Kraken, CharlesSchwab, Polygon, CoinApi, Bybit, TradeStation, Alpaca, Tastytrade, Eze, dYdX. - **--ib-user-name** (TEXT) - Optional - Your Interactive Brokers username. - **--ib-account** (TEXT) - Optional - Your Interactive Brokers account id. - **--ib-password** (TEXT) - Optional - Your Interactive Brokers password. - **--ib-weekly-restart-utc-time** (TEXT) - Optional - Weekly restart UTC time (hh:mm:ss). Required by Interactive Brokers for 2FA verification. Example: "02:00:00". - **--ib-financial-advisors-group-filter** (TEXT) - Optional - Filter data by a specific financial advisor group within your Interactive Brokers account. Leave blank to include all groups. - **--tradier-account-id** (TEXT) - Optional - Your Tradier account id. - **--tradier-access-token** (TEXT) - Optional - Your Tradier access token. - **--tradier-environment** (string) - Optional - Whether the developer sandbox should be used. Supported values: live, paper. - **--oanda-account-id** (TEXT) - Optional - Your OANDA account id. - **--oanda-access-token** (TEXT) - Optional - Your OANDA API token. - **--oanda-environment** (string) - Optional - The environment to run in. Supported values: Practice, Trade. - **--bitfinex-api-key** (TEXT) - Optional - Your Bitfinex API key. - **--bitfinex-api-secret** (TEXT) - Optional - Your Bitfinex API secret. - **--coinbase-api-name** (TEXT) - Optional - Your Coinbase Advanced Trade API name from file. - **--coinbase-api-private-key** (TEXT) - Optional - Your Coinbase Advanced Trade API private key from file. - **--binance-exchange-name** (string) - Optional - Binance exchange name. Supported values: Binance, BinanceUS, Binance-USDM-Futures, Binance-COIN-Futures. - **--binance-api-key** (TEXT) - Optional - Your Binance API key. - **--binanceus-api-key** (TEXT) - Optional - Your Binance API key. - **--binance-api-secret** (TEXT) - Optional - Your Binance API secret. - **--binanceus-api-secret** (TEXT) - Optional - Your Binance API secret. - **--binance-use-testnet** (string) - Optional - Whether the testnet should be used. Supported values: live, paper. - **--zerodha-api-key** (TEXT) - Optional - Your Kite Connect API key. - **--zerodha-access-token** (TEXT) - Optional - Your Kite Connect access token. - **--zerodha-product-type** (string) - Optional - Product type for Zerodha. Supported values: mis, cnc, nrml. - **--zerodha-trading-segment** (string) - Optional - Trading segment for Zerodha. Supported values: equity, commodity. - **--zerodha-history-subscription** (string) - Optional - Whether you have a history API subscription for Zerodha. Supported values: true, false. - **--samco-client-id** (TEXT) - Optional - Your Samco account Client ID. - **--samco-client-password** (TEXT) - Optional - Your Samco account password. - **--samco-year-of-birth** (TEXT) - Optional - Your year of birth (YYYY) registered with Samco. - **--samco-product-type** (string) - Optional - Product type for Samco. Supported values: mis, cnc, nrml. - **--samco-trading-segment** (string) - Optional - Trading segment for Samco. Supported values: equity, commodity. - **--terminal-link-server-auth-id** (TEXT) - Optional - The Auth ID of the TerminalLink server. - **--terminal-link-environment** (string) - Optional - The environment for TerminalLink. Supported values: Production, Beta. #### Request Body Not applicable (CLI command) ### Request Example ```bash lean cloud live deploy "My Algorithm Project" --brokerage "Paper Trading" --data-provider-live "QuantConnect" ``` ### Response #### Success Response (200) Output indicating the deployment status and live trading initiation. #### Response Example ``` Starting live trading for project 'My Algorithm Project'... Deployment successful. Live trading has started. ``` #### Error Handling - If the project is not found, an error message will be displayed. - If brokerage or data provider options are invalid, an error message will be displayed. - Authentication errors with the brokerage will result in an error message. ``` -------------------------------- ### Install Python Tkinter Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Install tkinter for Python 3 or Python 2.7 on Debian-based Linux systems if required by the CLI. ```bash sudo apt-get install python3-tk ``` ```bash sudo apt-get install python-tk ``` -------------------------------- ### Interactive Parameter Optimization Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts an interactive optimization process for a trading strategy using a wizard mode. ```bash lean optimize "My Trading Strategy" ``` -------------------------------- ### lean object-store get Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Retrieves items from the local object store. ```APIDOC ## lean object-store get ### Description Opens the local storage directory in the file explorer. (Note: The provided description seems to be for a different command, assuming this command is for getting from object store based on the title). ### Method CLI Command ### Endpoint N/A (Local command) ### Parameters #### Query Parameters - **--verbose** - Optional - Enable debug logging. ### Request Example ```bash lean object-store get ``` ### Response N/A (Command execution output) ``` -------------------------------- ### Set Configuration Value Source: https://context7.com/quantconnect/lean-cli/llms.txt Modifies a configuration setting. This example sets the default language for new projects to Python. ```bash lean config set default-language python ``` -------------------------------- ### Detached Live Deployment Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts live trading in detached mode, allowing the command to run in the background. ```bash lean live deploy "My Trading Strategy" --detach ``` -------------------------------- ### Add Library to Project Command Usage Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Usage and examples for the `lean library add` command, used to add custom libraries to a project. It supports NuGet packages for C#, PyPI packages for Python, and local Lean CLI libraries. Specify the version or let it default to the latest compatible version. ```bash Usage: lean library add [OPTIONS] PROJECT NAME Add a custom library to a project. PROJECT must be the path to the project. NAME must be either the name of a NuGet package (for C# projects), a PyPI package (for Python projects), or a path to a Lean CLI library. If --version is not given, and the library is a NuGet or PyPI package the package, it is pinned to the latest compatible version. For C# projects, this is the latest available version. For Python projects, this is the latest version compatible with Python 3.8 (which is what the Docker images use). For Lean CLI library projects, this is ignored. Custom C# libraries are added to your project's .csproj file, which is then restored if dotnet is on your PATH and the --no-local flag has not been given. Custom Python libraries are added to your project's requirements.txt file and are installed in your local Python environment so you get local autocomplete for the library. The last step can be skipped with the --no-local flag. C# example usage: $ lean library add "My CSharp Project" Microsoft.ML $ lean library add "My CSharp Project" Microsoft.ML --version 1.5.5 $ lean library add "My CSharp Project" "Library/My CSharp Library" Python example usage: $ lean library add "My Python Project" tensorflow $ lean library add "My Python Project" tensorflow --version 2.5.0 $ lean library add "My Python Project" "Library/My Python Library" Options: --version TEXT The version of the library to add (defaults to latest compatible version) --no-local Skip making changes to your local environment --verbose Enable debug logging --help Show this message and exit. ``` -------------------------------- ### lean cloud object-store get Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Downloads an object store value to disk from the organization's cloud object store. Multiple keys can be provided. ```APIDOC ## lean cloud object-store get [KEY]... ### Description Download an object store value to disk from the organization's cloud object store. ### Method CLI Command ### Parameters #### Path Parameters - **KEY** (string) - Required - The desired key to fetch, multiple can be provided. #### Options - `--destination-folder TEXT`: The destination folder to download the object store values, if not provided will use to current directory. - `--verbose`: Enable debug logging. - `--help`: Show this message and exit. ``` -------------------------------- ### Research with QuantConnect Data Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts a research session with QuantConnect's data, automatically downloading specified data up to a purchase limit. Useful for quick analysis without manual data download. ```bash lean research "My Trading Strategy" --download-data --data-purchase-limit 50 ``` -------------------------------- ### Initialize Lean Project Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Initialize a new Lean project by downloading the latest configuration and sample data from the QuantConnect/Lean repository. ```bash lean init ``` -------------------------------- ### Live Deployment with Initial Cash Balance Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy with a specified initial cash balance for Paper Trading. ```bash lean live deploy "My Trading Strategy" \ --brokerage "Paper Trading" \ --data-provider-live "QuantConnect" \ --live-cash-balance "USD:100000,EUR:50000" ``` -------------------------------- ### Initialize Lean Workspace Source: https://context7.com/quantconnect/lean-cli/llms.txt Scaffold a new Lean project with configuration and sample data. Use interactive mode or specify organization and language. ```bash lean init ``` ```bash lean init --organization "My Organization" --language python ``` -------------------------------- ### Interactive Cloud Live Deployment Source: https://context7.com/quantconnect/lean-cli/llms.txt Initiates an interactive wizard for deploying a trading strategy to QuantConnect's cloud for live trading. ```bash lean cloud live deploy "My Trading Strategy" ``` -------------------------------- ### Live Deployment with Paper Trading Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy for live trading using Paper Trading with QuantConnect as the data provider. ```bash lean live deploy "My Trading Strategy" \ --brokerage "Paper Trading" \ --data-provider-live "QuantConnect" ``` -------------------------------- ### Add Library Without Local Installation Source: https://context7.com/quantconnect/lean-cli/llms.txt Adds a library to a project without installing it locally. This can be useful in containerized environments or when managing dependencies externally. ```bash lean library add "My Python Project" tensorflow --no-local ``` -------------------------------- ### Generate Minute Equity Data Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Generates minute-resolution market data for 100 equity symbols starting from January 1, 2015. Ensure the start date is specified in yyyyMMdd format. ```bash lean data generate --start=20150101 --symbol-count=100 ``` -------------------------------- ### Live Deployment with Initial Holdings Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy with specified initial holdings for Paper Trading. ```bash lean live deploy "My Trading Strategy" \ --brokerage "Paper Trading" \ --data-provider-live "QuantConnect" \ --live-holdings "AAPL:AAPL 2T:100:150.50,MSFT:MSFT 2T:50:300.25" ``` -------------------------------- ### Create and Push New Project to Cloud Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Create a new project with basic code and push it to the cloud. This is part of setting up a new project for cloud development. ```bash lean create-project "Project Name" ``` ```bash lean cloud push --project "Project Name" ``` -------------------------------- ### Initialize Project Command Usage Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Usage and options for the `lean init` command, which scaffolds a Lean configuration file and data directory. You can specify the organization and default language for new projects. ```bash Usage: lean init [OPTIONS] Scaffold a Lean configuration file and data directory. Options: --organization TEXT The name or id of the organization the Lean CLI will be scaffolded for -l, --language [python|csharp] The default language to use for new projects --verbose Enable debug logging --help Show this message and exit. ``` -------------------------------- ### Get Object Properties from Cloud Source: https://context7.com/quantconnect/lean-cli/llms.txt Retrieves the properties of a specific object stored in the cloud. ```bash lean cloud object-store properties "my-key" ``` -------------------------------- ### lean project-create Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Creates a new project with starter code. ```APIDOC ## lean project-create ### Description Create a new project containing starter code. If NAME is a path containing subdirectories those will be created automatically. The default language can be set using `lean config set default-language python/csharp`. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Command Line Arguments - **NAME** (string) - The name or path for the new project. #### Command Line Options - **-l, --language** (python|csharp) - The language of the project to create. - **--verbose** (BOOLEAN) - Enable debug logging. - **--help** (BOOLEAN) - Show this message and exit. ``` -------------------------------- ### Detached Optimization Source: https://context7.com/quantconnect/lean-cli/llms.txt Starts parameter optimization in detached mode, allowing the command to run in the background. ```bash lean optimize "My Trading Strategy" --detach ``` -------------------------------- ### lean init Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Scaffolds a Lean configuration file and data directory for a new project. ```APIDOC ## lean init ### Description Scaffold a Lean configuration file and data directory. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Query Parameters - **--organization** (TEXT) - Optional - The name or id of the organization the Lean CLI will be scaffolded for. - **-l, --language** (TEXT) - Optional - The default language to use for new projects (choices: python, csharp). - **--verbose** (boolean) - Optional - Enable debug logging. ### Request Example ```bash lean init --organization "MyOrg" -l python --verbose ``` ### Response #### Success Response (0) - Output indicating successful initialization of a new project structure. #### Response Example ``` Project scaffolded successfully. ``` ``` -------------------------------- ### Pull Cloud Projects Including Boot Camp Source: https://context7.com/quantconnect/lean-cli/llms.txt Fetches all cloud projects, including those from QuantConnect's Boot Camp. Use this to ensure all your learning materials are synchronized. ```bash lean cloud pull --pull-bootcamp ``` -------------------------------- ### Live Deployment with Interactive Brokers Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy for live trading with Interactive Brokers, requiring user credentials and account information. ```bash lean live deploy "My Trading Strategy" \ --brokerage "Interactive Brokers" \ --ib-user-name "your-username" \ --ib-account "your-account-id" \ --ib-password "your-password" \ --data-provider-live "Interactive Brokers" ``` -------------------------------- ### Cloud Backtesting with Lean CLI Source: https://context7.com/quantconnect/lean-cli/llms.txt Run backtests on QuantConnect's cloud infrastructure. Options include pushing code, opening the browser, and setting custom backtest names. ```bash lean cloud backtest "My Trading Strategy" ``` ```bash lean cloud backtest "My Trading Strategy" --push --open ``` ```bash lean cloud backtest "My Trading Strategy" --name "Momentum Test v2" ``` -------------------------------- ### Cloud Live Deployment with Brokerage and Options Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy to the cloud with specified brokerage, node, and auto-restart/notification settings. ```bash lean cloud live deploy "My Trading Strategy" \ --brokerage "Paper Trading" \ --node "L-MICRO" \ --auto-restart true \ --notify-order-events true \ --notify-insights false ``` -------------------------------- ### Add Python Library to Project Source: https://context7.com/quantconnect/lean-cli/llms.txt Adds a Python library to a specified project. The library will be installed locally or managed by the project's environment. ```bash lean library add "My Python Project" tensorflow ``` -------------------------------- ### Create New Trading Project Source: https://context7.com/quantconnect/lean-cli/llms.txt Generate a new algorithmic trading project with starter code for Python or C#. Projects include main algorithm files, research notebooks, and configuration files. ```bash lean create-project "My Trading Strategy" --language python ``` ```bash lean create-project "My CSharp Strategy" --language csharp ``` ```bash lean create-project "Strategies/Momentum/SPY Strategy" ``` -------------------------------- ### Get Object from Cloud Object Store Source: https://context7.com/quantconnect/lean-cli/llms.txt Retrieves an object from the cloud object store. You can specify a destination folder to save the downloaded object. ```bash lean cloud object-store get "my-key" ``` ```bash lean cloud object-store get "my-key" --destination-folder ./downloads ``` -------------------------------- ### Cloud Backtest with Parameters Source: https://context7.com/quantconnect/lean-cli/llms.txt Initiates a cloud backtest for a specified trading strategy, allowing for the configuration of strategy parameters. ```bash lean cloud backtest "My Trading Strategy" --parameter fast_period 10 --parameter slow_period 50 ``` -------------------------------- ### Run Local Backtest Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Run a backtest locally using a Docker container that mirrors the QuantConnect.com environment. This is used for testing strategies with your own data. ```bash lean backtest "Project Name" ``` -------------------------------- ### Unset Configuration Value Source: https://context7.com/quantconnect/lean-cli/llms.txt Removes a specific configuration setting, reverting it to its default value or state. This example unsets the custom engine image. ```bash lean config unset engine-image ``` -------------------------------- ### Add Specific Version of Python Library Source: https://context7.com/quantconnect/lean-cli/llms.txt Installs a specific version of a Python library for a project. Ensures compatibility with older codebases or specific requirements. ```bash lean library add "My Python Project" tensorflow --version 2.5.0 ``` -------------------------------- ### Update Lean CLI Readme Commands Reference Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Updates the commands reference section in the README file. This command should be run after installing a new version of the Lean CLI. ```bash python scripts/readme.py ``` -------------------------------- ### Project Creation Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Command for creating new Lean projects. ```APIDOC ## lean create-project ### Description Create a new project containing starter code. If NAME is a path containing subdirectories those will be created automatically. The default language can be set using `lean config set default-language python/csharp`. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **NAME** (string) - Required - The name or path for the new project. #### Query Parameters - **-l, --language** (string) - Optional - The language of the project to create (`python` or `csharp`). #### Request Body None ### Request Example ``` lean create-project MyAlgorithm -l python ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating project creation. #### Response Example ```json { "message": "Project 'MyAlgorithm' created successfully." } ``` ``` -------------------------------- ### Generate Report with Live Results Comparison Source: https://context7.com/quantconnect/lean-cli/llms.txt Compares backtest results with live trading results in a generated report. Requires paths to both result files. ```bash lean report \ --backtest-results "./backtest-results.json" \ --live-results "./live-results.json" ``` -------------------------------- ### Generate Daily Crypto Data Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Generates daily-resolution market data for 100 crypto symbols starting from January 1, 2015. Specify the security type and resolution as needed. ```bash lean data generate --start=20150101 --symbol-count=100 --security-type=Crypto --resolution=Daily ``` -------------------------------- ### Local Object Store Operations Source: https://context7.com/quantconnect/lean-cli/llms.txt Manages local object storage. These commands typically open the respective directories or initiate interactive processes for listing, getting, setting, or deleting objects. ```bash lean object-store list ``` ```bash lean object-store get ``` ```bash lean object-store set ``` ```bash lean object-store delete ``` -------------------------------- ### Live Deployment with Coinbase Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy for live trading with Coinbase Advanced Trade, requiring API credentials. ```bash lean live deploy "My Trading Strategy" \ --brokerage "Coinbase Advanced Trade" \ --coinbase-api-name "your-api-name" \ --coinbase-api-private-key "your-private-key" \ --data-provider-live "Coinbase Advanced Trade" ``` -------------------------------- ### Cloud Live Deployment with Notifications Source: https://context7.com/quantconnect/lean-cli/llms.txt Deploys a trading strategy to the cloud and configures email and SMS notifications for trade events. ```bash lean cloud live deploy "My Trading Strategy" \ --brokerage "Paper Trading" \ --notify-emails "user@example.com:Trade Alert" \ --notify-sms "+1234567890" ``` -------------------------------- ### lean object-store list Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Opens the local storage directory in the file explorer. ```APIDOC ## lean object-store list ### Description Opens the local storage directory in the file explorer. ### Method CLI Command ### Endpoint N/A ### Parameters #### Query Parameters - **--verbose** (boolean) - Optional - Enable debug logging ### Request Example ``` lean object-store list ``` ### Response N/A ``` -------------------------------- ### Optimization with Custom Config File Source: https://context7.com/quantconnect/lean-cli/llms.txt Runs parameter optimization using a specified configuration file. ```bash lean optimize "My Trading Strategy" --optimizer-config ./optimizer-config.json ``` -------------------------------- ### Pull All Cloud Projects to Local Source: https://context7.com/quantconnect/lean-cli/llms.txt Synchronizes all projects from QuantConnect's cloud to your local machine. This command fetches all available projects. ```bash lean cloud pull ``` -------------------------------- ### Cloud Live Management Commands Source: https://context7.com/quantconnect/lean-cli/llms.txt Commands to manage cloud-based live trading instances, including stopping and liquidating. ```bash lean cloud live stop "My Trading Strategy" lean cloud live liquidate "My Trading Strategy" ``` -------------------------------- ### lean object-store set Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Opens the local storage directory in the file explorer. ```APIDOC ## lean object-store set ### Description Opens the local storage directory in the file explorer. ### Method CLI Command ### Endpoint N/A ### Parameters #### Query Parameters - **--verbose** (boolean) - Optional - Enable debug logging ### Request Example ``` lean object-store set ``` ### Response N/A ``` -------------------------------- ### Interactive Data Download from QuantConnect Source: https://context7.com/quantconnect/lean-cli/llms.txt Initiates an interactive data download process from QuantConnect. The CLI will prompt for necessary details. ```bash lean data download ``` -------------------------------- ### Pull Specific Project from Cloud Source: https://context7.com/quantconnect/lean-cli/llms.txt Downloads a specific project from the QuantConnect cloud to your local machine. Requires the project name. ```bash lean cloud pull --project "My Trading Strategy" ``` -------------------------------- ### lean cloud live deploy Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Deploys a project to the Lean cloud for live trading. Supports options for automatic browser opening, showing secrets, disabling the browser, and verbose logging. ```APIDOC ## lean cloud live deploy ### Description Deploys a project to the Lean cloud for live trading. ### Options - `--open`: Automatically open the live results in the browser once the deployment starts. - `--show-secrets`: Show secrets as they are input. - `--no-browser`: Display OAuth URL without opening the browser. - `--verbose`: Enable debug logging. - `--help`: Show this message and exit. ``` -------------------------------- ### lean object-store ls Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Alias for 'list', opens the local storage directory in the file explorer. ```APIDOC ## lean object-store ls ### Description Alias for 'list'. Opens the local storage directory in the file explorer. ### Method CLI Command ### Endpoint N/A ### Parameters #### Query Parameters - **--verbose** (boolean) - Optional - Enable debug logging ### Request Example ``` lean object-store ls ``` ### Response N/A ``` -------------------------------- ### lean live Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Interact with the local machine for live trading. ```APIDOC ## lean live ### Description Interact with the local machine for live trading. ### Method CLI Command ### Endpoint N/A (CLI Command) ### Parameters #### Query Parameters - **--help** (flag) - Optional - Show this message and exit. ### Commands - **add-security**: Represents a command to add a security to the algorithm. - **cancel-order**: Represents a command to cancel a specific order by id. - **command**: Send a command to a local running live trading project. - **deploy**: Start live trading a project locally using Docker. - **liquidate**: Liquidate the given symbol from the latest deployment of the given project. - **stop**: Stop an already running local live trading project. - **submit-order**: Represents a command to submit an order to the algorithm. - **update-order**: Represents a command to update a specific order by id. ### Response N/A (CLI Command Output) ``` -------------------------------- ### Lean Research Environment Configuration Options Source: https://github.com/quantconnect/lean-cli/blob/master/README.md These are command-line options for configuring the Lean research environment, including API keys for various brokers and data providers, as well as settings for the Docker image and data download behavior. ```bash --bybit-api-key TEXT Your Bybit API key ``` ```bash --bybit-api-secret TEXT Your Bybit API secret ``` ```bash --trade-station-environment [live|paper] Whether Live or Paper environment should be used ``` ```bash --trade-station-account-id TEXT The TradeStation account Id ``` ```bash --alpaca-environment [live|paper] Whether Live or Paper environment should be used ``` ```bash --tastytrade-account-number TEXT The Tastytrade account number ``` ```bash --eze-domain TEXT Examples (broker provided): LIGHTSPEED, LIGHTSPEEDDELAY ``` ```bash --eze-locale TEXT Examples (broker provided): GLOBAL, AMERICAS, LIVE, DELAYED ``` ```bash --eze-user-name TEXT Your Eze Brokers username ``` ```bash --eze-password TEXT Your Eze Brokers password ``` ```bash --dydx-private-key-hex TEXT Your dYdX API private key in hex format ``` ```bash --dydx-address TEXT Your dYdX wallet address ``` ```bash --dydx-subaccount-number INTEGER Your dYdX subaccount number ``` ```bash --databento-api-key TEXT Your Databento.com API Key ``` ```bash --download-data Update the Lean configuration file to download data from the QuantConnect API, alias for --data-provider-historical QuantConnect ``` ```bash --data-purchase-limit INTEGER The maximum amount of QCC to spend on downloading data during the research session when using QuantConnect as historical data provider ``` ```bash -d, --detach Run Jupyter Lab in a detached Docker container and return immediately ``` ```bash --no-open Don't open the Jupyter Lab environment in the browser after starting it ``` ```bash --image TEXT The LEAN research image to use (defaults to quantconnect/research:latest) ``` ```bash --update Pull the LEAN research image before starting the research environment ``` ```bash --extra-docker-config TEXT Extra docker configuration as a JSON string. For more information https://docker- py.readthedocs.io/en/stable/containers.html ``` ```bash --no-update Use the local LEAN research image instead of pulling the latest version ``` ```bash --lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json) ``` ```bash --verbose Enable debug logging ``` ```bash --help Show this message and exit. ``` -------------------------------- ### Interactive Cloud Optimization Source: https://context7.com/quantconnect/lean-cli/llms.txt Initiates an interactive parameter optimization process on QuantConnect's cloud infrastructure. ```bash lean cloud optimize "My Trading Strategy" ``` -------------------------------- ### Run Cloud Backtest Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Run a backtest in the cloud, pushing local changes and opening results in the browser upon completion. Use this for iterative testing during development. ```bash lean cloud backtest "Project Name" --open --push ``` -------------------------------- ### Configuration Management Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Commands for managing Lean CLI configuration options. ```APIDOC ## lean config get ### Description Get the current value of a configurable option. Sensitive options like credentials cannot be retrieved this way for security reasons. Run `lean config list` to show all available options. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **KEY** (string) - Required - The configuration option key to retrieve. #### Query Parameters None #### Request Body None ### Request Example ``` lean config get default-language ``` ### Response #### Success Response (200) - **value** (string) - The current value of the configuration option. #### Response Example ```json { "value": "python" } ``` ``` ```APIDOC ## lean config list ### Description List the configurable options and their current values. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` lean config list ``` ### Response #### Success Response (200) - **options** (object) - A dictionary where keys are option names and values are their current settings. #### Response Example ```json { "options": { "default-language": "python", "api-key": "..." } } ``` ``` ```APIDOC ## lean config set ### Description Set a configurable option. Run `lean config list` to show all available options. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **KEY** (string) - Required - The configuration option key to set. - **VALUE** (string) - Required - The value to set for the configuration option. #### Query Parameters None #### Request Body None ### Request Example ``` lean config set default-language csharp ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Configuration option 'default-language' set to 'csharp'." } ``` ``` ```APIDOC ## lean config unset ### Description Unset a configurable option. Run `lean config list` to show all available options. ### Method CLI Command ### Endpoint N/A ### Parameters #### Path Parameters - **KEY** (string) - Required - The configuration option key to unset. #### Query Parameters None #### Request Body None ### Request Example ``` lean config unset api-key ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Configuration option 'api-key' has been unset." } ``` ``` -------------------------------- ### Push Local Project to Cloud with Encryption Source: https://context7.com/quantconnect/lean-cli/llms.txt Uploads a local project to the cloud and encrypts it using a specified key file. Ensures your code is protected when stored in the cloud. ```bash lean cloud push --project "./My Trading Strategy" --encrypt --key ./encryption.key ``` -------------------------------- ### Local Backtesting with Lean CLI Source: https://context7.com/quantconnect/lean-cli/llms.txt Run local backtests using Docker. Supports custom output directories, detached mode, debugging with IDEs (PyCharm, VS Code), data downloading, specific data providers, custom parameters, custom engine images, and release mode for C#. ```bash lean backtest "My Trading Strategy" ``` ```bash lean backtest "My Trading Strategy" --output ./results/backtest-001 ``` ```bash lean backtest "My Trading Strategy" --detach ``` ```bash lean backtest "My Trading Strategy" --debug pycharm ``` ```bash lean backtest "My Trading Strategy" --debug debugpy ``` ```bash lean backtest "My Trading Strategy" --debug vsdbg ``` ```bash lean backtest "My Trading Strategy" --download-data --data-purchase-limit 100 ``` ```bash lean backtest "My Trading Strategy" --data-provider-historical "Polygon" --polygon-api-key "your-key" ``` ```bash lean backtest "My Trading Strategy" --parameter symbol AAPL --parameter period 10 --parameter threshold 0.05 ``` ```bash lean backtest "My Trading Strategy" --image quantconnect/lean:latest --update ``` ```bash lean backtest "My CSharp Strategy" --release ``` -------------------------------- ### lean object-store properties Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Opens the local storage directory in the file explorer. ```APIDOC ## lean object-store properties ### Description Opens the local storage directory in the file explorer. ### Method CLI Command ### Endpoint N/A ### Parameters #### Query Parameters - **--verbose** (boolean) - Optional - Enable debug logging ### Request Example ``` lean object-store properties ``` ### Response N/A ``` -------------------------------- ### lean live command Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Sends a command to a local running live trading project. ```APIDOC ## lean live command ### Description Send a command to a local running live trading project. ### Method CLI Command ### Endpoint N/A (CLI Command) ### Parameters #### Path Parameters - **PROJECT** (string) - Required - The path to the project directory. #### Query Parameters - **--data** (TEXT) - Required - The command to send, 'str' representation of a 'dict' e.g. `{ "target": "BTCUSD", "$type":"MyCommand" }`. - **--lean-config** (FILE) - Optional - The Lean configuration file that should be used (defaults to the nearest lean.json). - **--verbose** (flag) - Optional - Enable debug logging. - **--help** (flag) - Optional - Show this message and exit. ### Response N/A (CLI Command Output) ``` -------------------------------- ### Lean CLI Backtest Parameters Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Pass key-value pairs as backtest parameters. Values can be string, int, or float. ```bash --parameter ... Key-value pairs to pass as backtest parameters. Values can be string, int, or float. Example: --parameter symbol AAPL --parameter period 10 --parameter threshold 0.05 ``` -------------------------------- ### Live Trading Management Commands Source: https://context7.com/quantconnect/lean-cli/llms.txt Provides commands to manage active live trading instances, including stopping and liquidating positions. ```bash lean live stop "My Trading Strategy" lean live liquidate "My Trading Strategy" lean live liquidate "My Trading Strategy" --ticker AAPL --market USA --security-type Equity ``` -------------------------------- ### Interact with Local Live Trading Project Source: https://github.com/quantconnect/lean-cli/blob/master/README.md This command group allows interaction with a locally running live trading project. It provides subcommands for managing securities, orders, and project deployment. ```bash lean live add-security --ticker "AAPL" --market "NASDAQ" --security-type "Equity" ``` ```bash lean live cancel-order --order-id 12345 ``` ```bash lean live command "{\"target\": \"BTCUSD\", \"$type\":\"MyCommand\"}" ``` ```bash lean live deploy ``` ```bash lean live liquidate --symbol "BTCUSD" ``` ```bash lean live stop ``` ```bash lean live submit-order --symbol "BTCUSD" --quantity 10 --type "Market" ``` ```bash lean live update-order --order-id 12345 --quantity 5 ``` -------------------------------- ### Encrypt Project Command Usage Source: https://github.com/quantconnect/lean-cli/blob/master/README.md Usage and options for the `lean encrypt` command, used to encrypt local projects with a specified encryption key. Provide the path to the encryption key file. ```bash Usage: lean encrypt [OPTIONS] PROJECT Encrypt your local project using the specified encryption key. Options: --key FILE Path to the encryption key to use --verbose Enable debug logging --help Show this message and exit. ``` -------------------------------- ### Push Specific Local Project to Cloud Source: https://context7.com/quantconnect/lean-cli/llms.txt Uploads a specific local project to QuantConnect's cloud. Requires the path to the project directory. ```bash lean cloud push --project "./My Trading Strategy" ```