QuantConnect/lean-cli(新しいタブで開きます)
主要言語: Python
CLI for running the LEAN engine locally and in the cloud
- star 数
- 330
- watcher 数
- 10
- fork 数
- 171
- issue 数
- 37
- 最終更新
- 2026/10/31
主要言語: Python
CLI for running the LEAN engine locally and in the cloud
The Lean CLI is a cross-platform CLI aimed at making it easier to develop with the LEAN engine locally and in the cloud.
Visit the documentation website for comprehensive and up-to-date documentation.
The CLI can be installed and updated by running pip install --upgrade lean.
Note that many commands in the CLI require Docker to run. See Get Docker for instructions on how to install Docker for your operating system.
Note: Some Linux users may need to install tkinter using the following commands:
For Python 3
sudo apt-get install python3-tk
For Python 2.7
sudo apt-get install python-tk
After installing the CLI, open a terminal in an empty directory and run lean init. This command downloads the latest configuration file and sample data from the QuantConnect/Lean repository. We recommend running all Lean CLI commands in the same directory lean init was ran in.
The Lean CLI supports multiple workflows. The examples below serve as a starting point, you're free to mix local and cloud features in any way you'd like.
A cloud-focused workflow (local development, cloud execution) with the CLI may look like this:
lean init in.lean cloud pull to pull remotely changed files.lean cloud backtest "Project Name" --open --push whenever there is something to backtest. The --open flag means that the backtest results will be opened in the browser when done, while the --push flag means that local changes are pushed to the cloud before running the backtest.lean create-project "Project Name" and lean cloud push --project "Project Name" to create a new project containing some basic code and to push it to the cloud.lean cloud push to push all locally changed files to the cloud.A locally-focused workflow (local development, local execution) with the CLI may look like this:
lean init in.lean create-project "Project Name" to create a new project with some basic code to get you started../Project Name.lean research "Project Name" to start a Jupyter Lab session to perform research in.lean backtest "Project Name" to run a backtest whenever there's something to test. This runs your strategy in a Docker container containing the same packages as the ones used on QuantConnect.com, but with your own data.You can save some typing by shortening command names to any unambiguous prefix. For example, lean clo back runs lean cloud backtest. If a prefix could match more than one command, the CLI shows you the options instead of guessing. They're handy for quick typing, but write out full command names in your scripts. A new command could later share the same prefix and break a shortcut that used to work.
The following CLI configurations are available. Use the lean config list command to list them at any time.
| Key | Description |
|---|---|
user-id |
The user id used when making authenticated requests to the QuantConnect API. |
api-token |
The API token used when making authenticated requests to the QuantConnect API. |
default-language |
The default language used when creating new projects (allowed values: python, csharp). |
engine-image |
The Docker image used when running the LEAN engine (quantconnect/lean:latest if not set). |
research-image |
The Docker image used when running the research environment (quantconnect/research:latest if not set). |
database-update-frequency |
How often the databases are updated. The format is DD.HH:MM:SS. If the frequency is less than a day can just be HH:MM:SS. Update can be disabled by setting this option to a non-date value (-, _, ..., etc.). If unset, default value is 1 day |
Note: the readme only contains the --help text of all commands. Visit the documentation website for more comprehensive documentation.
lean backtestlean buildlean cloud backtestlean cloud livelean cloud live broadcastlean cloud live commandlean cloud live deploylean cloud live liquidatelean cloud live stoplean cloud object-store deletelean cloud object-store getlean cloud object-store listlean cloud object-store lslean cloud object-store propertieslean cloud object-store setlean cloud optimizelean cloud pulllean cloud pushlean cloud statuslean config getlean config listlean config setlean config unsetlean create-projectlean data downloadlean data generatelean decryptlean delete-projectlean encryptlean initlean library addlean library removelean livelean live add-securitylean live cancel-orderlean live commandlean live deploylean live liquidatelean live stoplean live submit-orderlean live update-orderlean loginlean logoutlean logslean object-store deletelean object-store getlean object-store listlean object-store lslean object-store propertieslean object-store setlean optimizelean private-cloud add-computelean private-cloud startlean private-cloud stoplean project-createlean project-deletelean reportlean researchlean uilean whoamiBacktest a project locally using Docker.
Usage: lean backtest [OPTIONS] PROJECT
Backtest a project locally using Docker.
If PROJECT is a directory, the algorithm in the main.py or Main.cs file inside it will be executed.
If PROJECT is a file, the algorithm in the specified file will be executed.
Go to the following url to learn how to debug backtests locally using the Lean CLI:
https://www.lean.io/docs/v2/lean-cli/backtesting/debugging
By default the official LEAN engine image is used. You can override this using the --image option. Alternatively you
can set the default engine image for all commands using `lean config set engine-image <image>`.
Options:
--output DIRECTORY Directory to store results in (defaults to PROJECT/backtests/TIMESTAMP)
-d, --detach Run the backtest in a detached Docker container and return immediately
--debug [pycharm|ptvsd|debugpy|vsdbg|rider|local-platform]
Enable a certain debugging method (see --help for more information)
--data-provider-historical [Interactive Brokers|Oanda|Bitfinex|Coinbase Advanced Trade|Binance|Kraken|CharlesSchwab|IQFeed|Polygon|FactSet|AlphaVantage|CoinApi|ThetaData|QuantConnect|Local|Quant Bridge|Bybit|TradeStation|Alpaca|Tastytrade|Eze|dYdX|Databento|Webull|Public]
Update the Lean configuration file to retrieve data from the given historical provider
--ib-user-name TEXT Your Interactive Brokers username
--ib-account TEXT Your Interactive Brokers account id
--ib-password TEXT Your Interactive Brokers password
--ib-host TEXT External Interactive Brokers Gateway Host (Optional).
--ib-port TEXT External Interactive Brokers Gateway Port (Optional).
--ib-weekly-restart-utc-time TEXT
Weekly restart UTC time (hh:mm:ss). Each week on Sunday your algorithm is restarted at
this time, and will require 2FA verification. This is required by Interactive Brokers.
Use this option explicitly to override the default value. (Optional).
--oanda-account-id TEXT Your OANDA account id
--oanda-access-token TEXT Your OANDA API token
--oanda-environment [Practice|Trade]
The environment to run in, Practice for fxTrade Practice, Trade for fxTrade
--bitfinex-api-key TEXT Your Bitfinex API key
--bitfinex-api-secret TEXT Your Bitfinex API secret
--coinbase-api-name TEXT Your Coinbase Advanced Trade API name from file.
--coinbase-api-private-key TEXT
Your Coinbase Advanced Trade API private key from file.
--binance-exchange-name [Binance|BinanceUS|Binance-USDM-Futures|Binance-COIN-Futures]
Binance exchange name [Binance, BinanceUS, Binance-USDM-Futures, Binance-COIN-Futures]
--binance-api-key TEXT Your Binance API key
--binanceus-api-key TEXT Your Binance API key
--binance-api-secret TEXT Your Binance API secret
--binanceus-api-secret TEXT Your Binance API secret
--kraken-api-key TEXT Your Kraken API key
--kraken-api-secret TEXT Your Kraken API secret
--kraken-verification-tier [Starter|Intermediate|Pro]
Your Kraken Verification Tier
--charles-schwab-user-name TEXT
Your Charles Schwab login ID
--charles-schwab-account-number TEXT
The CharlesSchwab account number
--iqfeed-iqconnect TEXT The path to the IQConnect binary
--iqfeed-username TEXT Your IQFeed username
--iqfeed-password TEXT Your IQFeed password
--iqfeed-version TEXT The product version of your IQFeed developer account
--iqfeed-host TEXT The IQFeed host address (Optional).
--polygon-api-key TEXT Your Polygon.io API Key
--polygon-license-type [Individual|Business]
Select your Polygon.io subscription plan (Optional).
--factset-auth-config-file FILE
The path to the FactSet authentication configuration file
--alpha-vantage-api-key TEXT Your Alpha Vantage Api Key
--alpha-vantage-price-plan [Free|Plan30|Plan75|Plan150|Plan300|Plan600|Plan1200]
Your Alpha Vantage Premium API Key plan
--coinapi-api-key TEXT Your coinapi.io Api Key
--coinapi-product [Free|Startup|Streamer|Professional|Enterprise]
CoinApi pricing plan (https://www.coinapi.io/market-data-api/pricing)
--thetadata-ws-url TEXT The ThetaData host address (Optional).
--thetadata-rest-url TEXT The ThetaData host address (Optional).
--thetadata-subscription-plan [Free|Value|Standard|Pro]
Your ThetaData subscription price plan
--quant-bridge-connection-type [DAPI|SAPI]
Quant Bridge Connection Type [DAPI, SAPI]
--quant-bridge-environment [Production|Beta]
The environment to run in
--quant-bridge-server-host TEXT
The host of the Quant Bridge server
--quant-bridge-server-port INTEGER
The port of the Quant Bridge server
--quant-bridge-openfigi-api-key TEXT
The Open FIGI API key to use for mapping options
--quant-bridge-server-auth-id TEXT
The Auth ID of the Quant Bridge server
--bybit-api-key TEXT Your Bybit API key
--bybit-api-secret TEXT Your Bybit API secret
--trade-station-environment [live|paper]
Whether Live or Paper environment should be used
--trade-station-account-id TEXT
The TradeStation account Id
--alpaca-environment [live|paper]
Whether Live or Paper environment should be used
--tastytrade-account-number TEXT
The Tastytrade account number
--eze-domain TEXT Examples (broker provided): LIGHTSPEED, LIGHTSPEEDDELAY
--eze-locale TEXT Examples (broker provided): GLOBAL, AMERICAS, LIVE, DELAYED
--eze-user-name TEXT Your Eze Brokers username
--eze-password TEXT Your Eze Brokers password
--dydx-private-key-hex TEXT Your dYdX API private key in hex format
--dydx-address TEXT Your dYdX wallet address
--dydx-subaccount-number INTEGER
Your dYdX subaccount number
--databento-api-key TEXT Your Databento.com API Key
--webull-environment [live|paper]
Whether Live or Paper environment should be used
--webull-app-key TEXT Your Webull App Key
--webull-app-secret TEXT Your Webull App Secret
--webull-account-id TEXT Your Webull account id
--webull-use-2fa BOOLEAN Whether two-factor authentication (2FA) should be used (Optional).
--public-secret-key TEXT Your Public.com API secret key
--public-account-number TEXT Your Public.com account number. Public lets you have more than one account, so this
picks which one to trade.
--download-data Update the Lean configuration file to download data from the QuantConnect API, alias
for --data-provider-historical QuantConnect
--data-purchase-limit INTEGER The maximum amount of QCC to spend on downloading data during the backtest when using
QuantConnect as historical data provider
--release Compile C# projects in release configuration instead of debug
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
--python-venv TEXT The path of the python virtual environment to be used
--update Pull the LEAN engine image before running the backtest
--backtest-name TEXT Backtest name
--extra-docker-config TEXT Extra docker configuration as a JSON string. For more information https://docker-
py.readthedocs.io/en/stable/containers.html
--no-update Use the local LEAN engine image instead of pulling the latest version
--parameter <TEXT TEXT>... 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
--lean-config FILE The Lean configuration file that should be used (defaults to the nearest lean.json)
--verbose Enable debug logging
--help Show this message and exit.
See code: lean/commands/backtest.py
Build Docker images of your own version of LEAN.
Usage: lean build [OPTIONS] [ROOT]
Build Docker images of your own version of LEAN.
ROOT must point to a directory containing the LEAN repository:
https://github.com/QuantConnect/Lean
When ROOT is not given, the current directory is used as root directory.
This command performs the following actions:
1. The lean-cli/foundation:latest image is built from Lean/DockerfileLeanFoundation(ARM).
2. LEAN is compiled in a Docker container using the lean-cli/foundation:latest image.
3. The lean-cli/engine:latest image is built from Lean/Dockerfile using lean-cli/foundation:latest as base image.
4. The lean-cli/research:latest image is built from Lean/DockerfileJupyter using lean-cli/engine:latest as base image.
5. The default engine image is set to lean-cli/engine:latest.
6. The default research image is set to lean-cli/research:latest.
When the foundation Dockerfile is the same as the official foundation Dockerfile, quantconnect/lean:foundation is used
instead of building a custom foundation image.
Options:
--tag TEXT The tag to apply to custom images (defaults to latest)
--verbose Enable debug logging
--help Show this message and exit.
See code: lean/commands/build.py
Backtest a project in the cloud.
Usage: lean cloud backtest [OPTIONS] PROJECT
Backtest a project in the cloud.
PROJECT must be the name or id of the project to run a backtest for.
If the project that has to be backtested has been pulled to the local drive with `lean cloud pull` it is possible to
use the --push option to push local modifications to the cloud before running the backtest.
Options:
--name TEXT The name of the backtest (a random one is generated if not specified)
--push Push local modifications to the cloud before running the backtest
--open Automatically open the results in the browser when the backtest is finished
--parameter <TEXT TEXT>... 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
--verbose Enable debug logging
--help Show this message and exit.
See code: lean/commands/cloud/backtest.py
Interact with the QuantConnect cloud live deployments.
Usage: lean cloud live [OPTIONS] COMMAND [ARGS]...
Interact with the QuantConnect cloud live deployments.
Options:
--help Show this message and exit.
Commands:
broadcast Broadcast a command to all running cloud live trading projects in an organization.
command Send a command to a running cloud live trading project.
deploy Start live trading for a project in the cloud.
liquidate Stops live trading and liquidates existing positions for a certain project.
stop Stops live trading for a certain project without liquidating existing positions.
Broadcast a command to all running cloud live trading projects in an organization.
Usage: lean cloud live broadcast [OPTIONS]
Broadcast a command to all running cloud live trading projects in an organization.
Options:
--data TEXT The command to send, 'str' representation of a 'dict' e.g. "{ \"target\": \"BTCUSD\",
\"$type\":\"MyCommand\" }" [required]
--organization TEXT The name or id of the organization to broadcast the command to, defaults to the organization
of the current Lean CLI directory
--exclude-project TEXT The name or id of the project to exclude from the broadcast, by default all projects are
included
--verbose Enable debug logging
--help Show this message and exit.
See code: lean/commands/cloud/live/broadcast.py
Send a command to a running cloud live trading project.
Usage: lean cloud live command [OPTIONS] PROJECT
Send a command to a running cloud live trading project.
Options:
--data TEXT The command to send, 'str' representation of a 'dict' e.g. "{ \"target\": \"BTCUSD\",
\"$type\":\"MyCommand\" }"
--verbose Enable debug logging
--help Show this message and exit.
See code: lean/commands/cloud/live/command.py
Start live trading for a project in the cloud.
Usage: lean cloud live deploy [OPTIONS] PROJECT
Start live trading for a project in the cloud.
PROJECT must be the name or the id of the project to start live trading for.
By default an interactive wizard is shown letting you configure the deployment. If --brokerage is given the command
runs in non-interactive mode. In this mode the CLI does not prompt for input or confirmation. In non-interactive mode
the options specific to the given brokerage are required, as well as --node, --auto-restart, --notify-order-events and
--notify-insights.
Options:
--brokerage [Paper Trading|Interactive Brokers|Tradier|Oanda|Bitfinex|Coinbase Advanced Trade|Binance|Zerodha|Samco|Quant Bridge|Trading Technologies|Kraken|CharlesSchwab|Bybit|TradeStation|Alpaca|Tastytrade|Eze|dYdX|Webull|Public|ClearStreet]
The brokerage to use
--data-provider-live [QuantConnect|Interactive Brokers|Tradier|Oanda|Bitfinex|Coinbase Advanced Trade|Binance|Zerodha|Samco|Quant Bridge|Trading Technologies|Kraken|CharlesSchwab|Polygon|CoinApi|Bybit|TradeStation|Alpaca|Tastytrade|Eze|dYdX]
The live data provider to use
--ib-user-name TEXT Your Interactive Brokers username
--ib-account TEXT Your Interactive Brokers account id
--ib-password TEXT Your Interactive Brokers password
--ib-host TEXT External Interactive Brokers Gateway Host (Optional).
--ib-port TEXT External Interactive Brokers Gateway Port (Optional).
--ib-weekly-restart-utc-time TEXT
Weekly restart UTC time (hh:mm:ss). Each week on Sunday your algorithm is restarted at
this time, and will require 2FA verification. This is required by Interactive Brokers.
Use this option explicitly to override the default value. (Optional).
--ib-financial-advisors-group-filter TEXT
Use this field to filter data by a specific financial advisor group within your
Interactive Brokers account. Leave blank to include all groups. (Optional).
--tradier-account-id TEXT Your Tradier account id
--tradier-access-token TEXT Your Tradier access token
--tradier-environment [live|paper]
Whether the developer sandbox should be used
--oanda-account-id TEXT Your OANDA account id
--oanda-access-token TEXT Your OANDA API token
--oanda-environment [Practice|Trade]
The environment to run in, Practice for fxTrade Practice, Trade for fxTrade
--bitfinex-api-key TEXT Your Bitfinex API key
--bitfinex-api-secret TEXT Your Bitfinex API secret
--coinbase-api-name TEXT Your Coinbase Advanced Trade API name from file.
--coinbase-api-private-key TEXT
Your Coinbase Advanced Trade API private key from file.
--binance-exchange-name [Binance|BinanceUS|Binance-USDM-Futures|Binance-COIN-Futures]
Binance exchange name [Binance, BinanceUS, Binance-USDM-Futures, Binance-COIN-Futures]
--binance-api-key TEXT Your Binance API key
--binanceus-api-key TEXT Your Binance API key
--binance-api-secret TEXT Your Binance API secret
--binanceus-api-secret TEXT Your Binance API secret
--binance-use-testnet [live|paper]
Whether the testnet should be used
--zerodha-api-key TEXT Your Kite Connect API key
--zerodha-access-token TEXT Your Kite Connect access token
--zerodha-product-type [mis|cnc|nrml]
MIS if you are targeting intraday products, CNC if you are targeting delivery
products, NRML if you are targeting carry forward products
--zerodha-trading-segment [equity|commodity]
EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading
commodities on MCX
--zerodha-history-subscription [true|false]
Whether you have a history API subscription for Zerodha
--samco-client-id TEXT Your Samco account Client ID
--samco-client-password TEXT Your Samco account password
--samco-year-of-birth TEXT Your year of birth (YYYY) registered with Samco
--samco-product-type [mis|cnc|nrml]
MIS if you are targeting intraday products, CNC if you are targeting delivery
products, NRML if you are targeting carry forward products
--samco-trading-segment [equity|commodity]
EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading
commodities on MCX
--quant-bridge-server-auth-id TEXT
The Auth ID of the Quant Bridge server
--quant-bridge-environment [Production|Beta]
The environment to run in
--quant-bridge-server-host TEXT
The host of the SAPI server
--quant-bridge-server-port INTEGER
The port of the SAPI server
--quant-bridge-emsx-broker TEXT
The EMSX broker to use (Optional).
--quant-bridge-emsx-account TEXT
The EMSX account to use (Optional).
--quant-bridge-emsx-team TEXT The EMSX team to receive order events from (Optional).
--quant-bridge-openfigi-api-key TEXT
The Open FIGI API key to use for mapping options
--tt-user-name TEXT Your Trading Technologies username
--tt-session-password TEXT Your Trading Technologies session password
--tt-account-name TEXT Your Trading Technologies account name
--tt-rest-app-key TEXT Your Trading Technologies REST app key
--tt-rest-app-secret TEXT Your Trading Technologies REST app secret
--tt-rest-environment TEXT The REST environment to run in
--tt-order-routing-sender-comp-id TEXT
The order routing sender comp id to use
--kraken-api-key TEXT Your Kraken API key
--kraken-api-secret TEXT Your Kraken API secret
--kraken-verification-tier [Starter|Intermediate|Pro]
Your Kraken Verification Tier
--charles-schwab-user-name TEXT
Your Charles Schwab login ID
--charles-schwab-account-number TEXT
The CharlesSchwab account number
--bybit-api-key TEXT Your Bybit API key
--bybit-api-secret TEXT Your Bybit API secret
--bybit-vip-level [VIP0|VIP1|VIP2|VIP3|VIP4|VIP5|SupremeVIP|Pro1|Pro2|Pro3|Pro4|Pro5]
Your Bybit VIP Level
--bybit-use-testnet [live|paper|demo]
Whether the testnet should be used
--trade-station-environment [live|paper]
Whether Live or Paper environment should be used
--trade-station-account-id TEXT
The TradeStation account Id
--alpaca-environment [live|paper]
Whether Live or Paper environment should be used
--tastytrade-account-number TEXT
The Tastytrade account number
--eze-domain TEXT Examples (broker provided): LIGHTSPEED, LIGHTSPEEDDELAY
--eze-locale TEXT Examples (broker provided): GLOBAL, AMERICAS, LIVE, DELAYED
--eze-user-name TEXT Your Eze Brokers username
--eze-password TEXT Your Eze Brokers password
--eze-trading-account TEXT Format: BANK;BRANCH;CUSTOMER;DEPOSIT
--dydx-private-key-hex TEXT Your dYdX API private key in hex format
--dydx-address TEXT Your dYdX wallet address
--dydx-subaccount-number INTEGER
Your dYdX subaccount number
--dydx-environment [live|paper]
Whether the developer sandbox should be used
--webull-environment [live|paper]
Whether Live or Paper environment should be used
--webull-app-key TEXT Your Webull App Key
--webull-app-secret TEXT Your Webull App Secret
--webull-account-id TEXT Your Webull account id
--webull-use-2fa BOOLEAN Whether two-factor authentication (2FA) should be used (Optional).
--public-secret-key TEXT Your Public.com API secret key
--public-account-number TEXT Your Public.com account number. Public lets you have more than one account, so this
picks which one to trade.
--clearstreet-access-token TEXT
Your Clear Street API access token
--clearstreet-account-id TEXT Your Clear Street account id, the numeric id of the account the algorithm trades
--polygon-api-key TEXT Your Polygon.io API Key
--polygon-license-type [Individual|Business]
Select your Polygon.io subscription plan (Optional).
--coinapi-api-key TEXT Your coinapi.io Api Key
--coinapi-product [Free|Startup|Streamer|Professional|Enterprise]
CoinApi pricing plan (https://www.coinapi.io/market-data-api/pricing)
--alpaca-api-key TEXT Your Alpaca Api Key
--alpaca-api-secret TEXT Your Alpaca Api Secret
--node TEXT The name or id of the live node to run on
--auto-restart BOOLEAN Whether automatic algorithm restarting must be enabled
--notify-order-events BOOLEAN Whether notifications must be sent for order events
--notify-insights BOOLEAN Whether notifications must be sent for emitted insights
--notify-emails TEXT A comma-separated list of 'email:subject' pairs configuring email-notifications. Wrap
a subject containing ',' in double quotes, e.g. 'a@x.com:"Fills, orders"'
--notify-webhooks TEXT A comma-separated list of 'url:HEADER_1=VALUE_1:HEADER_2=VALUE_2:etc' pairs
configuring webhook-notifications. Wrap a url (with ',' or a ':' outside its scheme
and port) or a header (with ':' or ',') in double quotes, e.g.
'"https://x.com/hook?t=1:2":"Auth=Bearer a:b"'
--notify-sms TEXT A comma-separated list of phone numbers configuring SMS-notifications
--notify-telegram TEXT A comma-separated list of 'user/group Id:token(optional)' pairs configuring telegram-
notif