旨在使在本地和云中更轻松地运行 QuantConnect 的 LEAN 引擎的 CLI
项目描述
QuantConnect 精益 CLI
Lean CLI 是一个跨平台的 CLI,旨在使在本地和云中使用 LEAN 引擎进行开发变得更加容易。
访问文档网站以获取全面和最新的文档。
强调
安装
CLI 可以通过运行来安装和更新pip install --upgrade lean。
请注意,CLI 中的许多命令都需要 Docker 才能运行。有关如何为您的操作系统安装 Docker 的说明,请参阅获取 Docker 。
注意:某些 Linux 用户可能需要tkinter使用以下命令进行安装:
For Python 3
sudo apt-get install python3-tk
For Python 2.7
sudo apt-get install python-tk
安装 CLI 后,在空目录中打开终端并运行lean init. 此命令从QuantConnect/Lean存储库下载最新的配置文件和示例数据。我们建议在运行的同一目录lean init中运行所有精益 CLI 命令。
用法
精益 CLI 支持多个工作流程。下面的示例可作为起点,您可以随意以任何方式混合本地和云功能。
使用 CLI 的以云为中心的工作流(本地开发、云执行)可能如下所示:
- 在您运行的目录中打开终端
lean init。 - 运行
lean cloud pull以提取远程更改的文件。 lean cloud backtest "Project Name" --open --push只要有需要回测的东西,就可以在本地开始编程并在云中运行回测。该--open标志表示完成后将在浏览器中打开回测结果,而该--push标志表示在运行回测之前将本地更改推送到云端。- 每当您想创建一个新项目时,运行
lean create-project "Project Name"并lean cloud push --project "Project Name"创建一个包含一些基本代码的新项目并将其推送到云端。 - 暂时完成后,运行
lean cloud push将所有本地更改的文件推送到云端。
使用 CLI 的以本地为中心的工作流(本地开发、本地执行)可能如下所示:
- 在您运行的目录中打开终端
lean init。 - 运行
lean create-project "Project Name"以使用一些基本代码创建一个新项目,以帮助您入门。 - 制定您的战略
./Project Name。 - 运行
lean research "Project Name"以启动 Jupyter Lab 会话以执行研究。 lean backtest "Project Name"每当有要测试的东西时,运行以运行回测。这将在 Docker 容器中运行您的策略,该容器包含与 QuantConnect.com 上使用的相同的包,但使用您自己的数据。
命令
注意:自述文件仅包含--help所有命令的文本。访问文档网站以获取更全面的文档。
lean backtestlean buildlean cloud backtestlean cloud livelean cloud optimizelean cloud pulllean cloud pushlean cloud statuslean config getlean config listlean config setlean config unsetlean create-projectlean data downloadlean data generatelean gui logslean gui restartlean gui startlean gui stoplean initlean library addlean library removelean livelean loginlean logoutlean logslean optimizelean reportlean researchlean whoami
lean backtest
使用 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/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|vsdbg|rider]
Enable a certain debugging method (see --help for more information)
--data-provider [Terminal Link|QuantConnect|Local]
Update the Lean configuration file to retrieve data from the given provider
--download-data Update the Lean configuration file to download data from the QuantConnect API, alias
for --data-provider QuantConnect
--data-purchase-limit INTEGER The maximum amount of QCC to spend on downloading data during the backtest when using
QuantConnect as 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)
--update Pull the LEAN engine image before running the backtest
--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.
lean build
构建您自己的 LEAN 版本和 Alpha Streams SDK 的 Docker 映像。
Usage: lean build [OPTIONS] [ROOT]
Build Docker images of your own version of LEAN and the Alpha Streams SDK.
ROOT must point to a directory containing the LEAN repository and the Alpha Streams SDK repository:
https://github.com/QuantConnect/Lean & https://github.com/QuantConnect/AlphaStreams
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 Alpha Streams SDK is compiled in a Docker container using the lean-cli/foundation:latest image.
4. The lean-cli/engine:latest image is built from Lean/Dockerfile using lean-cli/foundation:latest as base image.
5. The lean-cli/research:latest image is built from Lean/DockerfileJupyter using lean-cli/engine:latest as base image.
6. The default engine image is set to lean-cli/engine:latest.
7. 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.
lean cloud backtest
在云中回测项目。
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
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/cloud/backtest.py
lean cloud live
开始在云中进行项目的实时交易。
Usage: lean cloud live [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 Pro|Binance|Zerodha|Samco|Kraken|FTX]
The brokerage 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-data-feed BOOLEAN Whether the Interactive Brokers price data feed must be used instead of the
QuantConnect price data feed
--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-environment [Practice|Trade]
The environment to run in, Practice for fxTrade Practice, Trade for fxTrade
--oanda-account-id TEXT Your OANDA account id
--oanda-access-token TEXT Your OANDA API token
--bitfinex-api-key TEXT Your Bitfinex API key
--bitfinex-api-secret TEXT Your Bitfinex API secret
--gdax-use-sandbox [live|paper]
Whether the sandbox should be used
--gdax-api-key TEXT Your Coinbase Pro API key
--gdax-api-secret TEXT Your Coinbase Pro API secret
--gdax-passphrase TEXT Your Coinbase Pro API passphrase
--binance-use-testnet [live|paper]
Whether the testnet should be used
--binance-api-key TEXT Your Binance API key
--binance-api-secret TEXT Your Binance API secret
--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
--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
--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
--ftx-exchange-name [FTX|FTXUS]
FTX exchange name [FTX, FTXUS]
--ftx-api-key TEXT Your FTX API key
--ftxus-api-key TEXT Your FTX API key
--ftx-api-secret TEXT Your FTX API secret
--ftxus-api-secret TEXT Your FTX API secret
--ftx-account-tier [Tier1|Tier2|Tier3|Tier4|Tier5|Tier6]
Your FTX Account Tier
--ftxus-account-tier [Tier1|Tier2|Tier3|Tier4|Tier5|Tier6]
Your FTX Account Tier
--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
--notify-webhooks TEXT A comma-separated list of 'url:HEADER_1=VALUE_1:HEADER_2=VALUE_2:etc' pairs
configuring webhook-notifications
--notify-sms TEXT A comma-separated list of phone numbers configuring SMS-notifications
--push Push local modifications to the cloud before starting live trading
--open Automatically open the live results in the browser once the deployment starts
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/cloud/live.py
lean cloud optimize
优化云中的项目。
Usage: lean cloud optimize [OPTIONS] PROJECT
Optimize a project in the cloud.
PROJECT must be the name or id of the project to optimize.
An interactive prompt will be shown to configure the optimizer. If --target is given the command runs in non-
interactive mode. In this mode the CLI does not prompt for input and the following options become required:
--target, --target-direction, --parameter, --node and --parallel-nodes.
In non-interactive mode the --parameter option can be provided multiple times to configure multiple parameters:
- --parameter <name> <min value> <max value> <step size>
- --parameter my-first-parameter 1 10 0.5 --parameter my-second-parameter 20 30 5
In non-interactive mode the --constraint option can be provided multiple times to configure multiple constraints:
- --constraint "<statistic> <operator> <value>"
- --constraint "Sharpe Ratio >= 0.5" --constraint "Drawdown < 0.25"
If the project that has to be optimized 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 optimization.
Options:
--target TEXT The target statistic of the optimization
--target-direction [min|max] Whether the target must be minimized or maximized
--parameter <TEXT FLOAT FLOAT FLOAT>...
The 'parameter min max step' pairs configuring the parameters to optimize
--constraint TEXT The 'statistic operator value' pairs configuring the constraints of the optimization
--node [O2-8|O4-12|O8-16] The node type to run the optimization on
--parallel-nodes INTEGER The number of nodes that may be run in parallel
--name TEXT The name of the optimization (a random one is generated if not specified)
--push Push local modifications to the cloud before starting the optimization
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/cloud/optimize.py
lean cloud pull
将项目从 QuantConnect 拉到本地驱动器。
Usage: lean cloud pull [OPTIONS]
Pull projects from QuantConnect to the local drive.
This command overrides the content of local files with the content of their respective counterparts in the cloud.
This command will not delete local files for which there is no counterpart in the cloud.
Options:
--project TEXT Name or id of the project to pull (all cloud projects if not specified)
--pull-bootcamp Pull Boot Camp projects (disabled by default)
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/cloud/pull.py
lean cloud push
将本地项目推送到 QuantConnect。
Usage: lean cloud push [OPTIONS]
Push local projects to QuantConnect.
This command overrides the content of cloud files with the content of their respective local counterparts.
This command will not delete cloud files which don't have a local counterpart.
Options:
--project DIRECTORY Path to the local project to push (all local projects if not specified)
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/cloud/push.py
lean cloud status
在云端显示项目的实时交易状态。
Usage: lean cloud status [OPTIONS] PROJECT
Show the live trading status of a project in the cloud.
PROJECT must be the name or the id of the project to show the status for.
Options:
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/cloud/status.py
lean config get
获取可配置选项的当前值。
Usage: lean config get [OPTIONS] KEY
Get the current value of a configurable option.
Sensitive options like credentials cannot be retrieved this way for security reasons. Please open
~/.lean/credentials if you want to see your currently stored credentials.
Run `lean config list` to show all available options.
Options:
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/config/get.py
lean config list
列出可配置选项及其当前值。
Usage: lean config list [OPTIONS]
List the configurable options and their current values.
Options:
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/config/list.py
lean config set
设置一个可配置的选项。
Usage: lean config set [OPTIONS] KEY VALUE
Set a configurable option.
Run `lean config list` to show all available options.
Options:
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/config/set.py
lean config unset
取消设置可配置选项。
Usage: lean config unset [OPTIONS] KEY
Unset a configurable option.
Run `lean config list` to show all available options.
Options:
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/config/unset.py
lean create-project
创建一个包含启动代码的新项目。
Usage: lean create-project [OPTIONS] NAME
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`.
Options:
-l, --language [python|csharp] The language of the project to create
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/create_project.py
lean data download
从 QuantConnect 数据集中购买和下载数据。
Usage: lean data download [OPTIONS]
Purchase and download data from QuantConnect Datasets.
An interactive wizard will show to walk you through the process of selecting data, accepting the CLI API Access and
Data Agreement and payment. After this wizard the selected data will be downloaded automatically.
If --dataset is given the command runs in non-interactive mode. In this mode the CLI does not prompt for input or
confirmation but only halts when the agreement must be accepted. In non-interactive mode all options specific to the
selected dataset as well as --organization are required.
See the following url for the data that can be purchased and downloaded with this command:
https://www.quantconnect.com/datasets
Options:
--dataset TEXT The name of the dataset to download non-interactively
--organization TEXT The name or id of the organization to purchase and download data with
--overwrite Overwrite existing local data
--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.
见代码:lean/commands/data/download.py
lean data generate
生成随机市场数据。
Usage: lean data generate [OPTIONS]
Generate random market data.
This uses the random data generator in LEAN to generate realistic market data using a Brownian motion model.
This generator supports the following security types, tick types and resolutions:
| Security type | Generated tick types | Supported resolutions |
| ------------- | -------------------- | ------------------------------------ |
| Equity | Trade | Tick, Second, Minute, Hour and Daily |
| Forex | Quote | Tick, Second, Minute, Hour and Daily |
| CFD | Quote | Tick, Second, Minute, Hour and Daily |
| Future | Trade and Quote | Tick, Second, Minute, Hour and Daily |
| Crypto | Trade and Quote | Tick, Second, Minute, Hour and Daily |
| Option | Trade and Quote | Minute |
The following data densities are available:
- Dense: at least one data point per resolution step.
- Sparse: at least one data point per 5 resolution steps.
- VerySparse: at least one data point per 50 resolution steps.
Example which generates minute data for 100 equity symbols since 2015-01-01:
$ lean data generate --start=20150101 --symbol-count=100
Example which generates daily data for 100 crypto symbols since 2015-01-01:
$ lean data generate --start=20150101 --symbol-count=100 --security-type=Crypto --resolution=Daily
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:
--start [yyyyMMdd] Start date for the data to generate in yyyyMMdd format [required]
--end [yyyyMMdd] End date for the data to generate in yyyyMMdd format (defaults to today)
--symbol-count INTEGER RANGE The number of symbols to generate data for [required]
--security-type [Equity|Forex|Cfd|Future|Crypto|Option]
The security type to generate data for (defaults to Equity)
--resolution [Tick|Second|Minute|Hour|Daily]
The resolution of the generated data (defaults to Minute)
--data-density [Dense|Sparse|VerySparse]
The density of the generated data (defaults to Dense)
--include-coarse BOOLEAN Whether coarse universe data should be generated for Equity data (defaults to True)
--market TEXT The market to generate data for (defaults to standard market for the security type)
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
--update Pull the LEAN engine image before running the generator
--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.
见代码:lean/commands/data/generate.py
lean gui logs
查看本地 GUI 的日志。
Usage: lean gui logs [OPTIONS]
See the logs of the local GUI.
Options:
-f, --follow Update the logs in real-time while the GUI is running
--verbose Enable debug logging
--help Show this message and exit.
lean gui restart
重新启动本地 GUI 并在浏览器中打开它。
Usage: lean gui restart [OPTIONS]
Restart the local GUI and open it in the browser.
Options:
--no-open Skip opening the local GUI in the browser after restarting it
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/gui/restart.py
lean gui start
启动本地 GUI。
Usage: lean gui start [OPTIONS]
Start the local GUI.
Options:
--organization TEXT The name or id of the organization with the local GUI module subscription
--port INTEGER The port to run the local GUI on (defaults to 5612)
--no-open Skip opening the local GUI in the browser after starting it
--shortcut Create a desktop shortcut for launching the local GUI
--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.
见代码:lean/commands/gui/start.py
lean gui stop
停止本地 GUI。
Usage: lean gui stop [OPTIONS]
Stop the local GUI.
Options:
--verbose Enable debug logging
--help Show this message and exit.
lean init
搭建一个精益配置文件和数据目录。
Usage: lean init [OPTIONS]
Scaffold a Lean configuration file and data directory.
Options:
--verbose Enable debug logging
--help Show this message and exit.
lean library add
将自定义库添加到项目。
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 the name of a NuGet package (for C# projects) or of a PyPI package (for Python projects).
If --version is not given, the package 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.6 (which is what
the Docker images use).
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
Python example usage:
$ lean library add "My Python Project" tensorflow
$ lean library add "My Python Project" tensorflow --version 2.5.0
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/commands/library/add.py
lean library remove
从项目中删除自定义库。
Usage: lean library remove [OPTIONS] PROJECT NAME
Remove a custom library from a project.
PROJECT must be the path to the project directory.
NAME must be the name of the NuGet package (for C# projects) or of the PyPI package (for Python projects) to remove.
Custom C# libraries are removed from the 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 removed from the project's requirements.txt file.
C# example usage:
$ lean library remove "My CSharp Project" Microsoft.ML
Python example usage:
$ lean library remove "My Python Project" tensorflow
Options:
--no-local Skip making changes to your local environment
--verbose Enable debug logging
--help Show this message and exit.
见代码:lean/commands/library/remove.py
lean live
使用 Docker 在本地开始实时交易项目。
Usage: lean live [OPTIONS] PROJECT
Start live trading 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.
By default an interactive wizard is shown letting you configure the brokerage and data feed to use. If
--environment, --brokerage or --data-feed are given the command runs in non-interactive mode. In this mode the CLI
does not prompt for input.
If --environment is given it must be the name of a live environment in the Lean configuration.
If --brokerage and --data-feed are given, the options specific to the given brokerage/data feed must also be given.
The Lean config is used as fallback when a brokerage/data feed-specific option hasn't been passed in. If a required
option is not given and cannot be found in the Lean config the command aborts.
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:
--environment TEXT The environment to use
--output DIRECTORY Directory to store results in (defaults to PROJECT/live/TIMESTAMP)
-d, --detach Run the live deployment in a detached Docker container and return immediately
--gui Enable monitoring and controlling of the deployment via the local GUI
--gui-organization TEXT The name or id of the organization with the local GUI module subscription
--brokerage [Paper Trading|Interactive Brokers|Tradier|Oanda|Bitfinex|Coinbase Pro|Binance|Zerodha|Samco|Terminal Link|Atreyu|Trading Technologies|Kraken|FTX]
The brokerage to use
--data-feed [Interactive Brokers|Tradier|Oanda|Bitfinex|Coinbase Pro|Binance|Zerodha|Samco|Terminal Link|Trading Technologies|Kraken|FTX|IQFeed|Custom data only]
The data feed to use
--ib-organization TEXT The name or id of the organization with the Interactive Brokers module subscription
--ib-user-name TEXT Your Interactive Brokers username
--ib-account TEXT Your Interactive Brokers account id
--ib-password TEXT Your Interactive Brokers password
--ib-enable-delayed-streaming-data BOOLEAN
Whether delayed data may be used when your algorithm subscribes to a security you
don't have a market data subscription for
--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-environment [Practice|Trade]
The environment to run in, Practice for fxTrade Practice, Trade for fxTrade
--oanda-account-id TEXT Your OANDA account id
--oanda-access-token TEXT Your OANDA API token
--bitfinex-api-key TEXT Your Bitfinex API key
--bitfinex-api-secret TEXT Your Bitfinex API secret
--gdax-use-sandbox [live|paper]
Whether the sandbox should be used
--gdax-api-key TEXT Your Coinbase Pro API key
--gdax-api-secret TEXT Your Coinbase Pro API secret
--gdax-passphrase TEXT Your Coinbase Pro API passphrase
--binance-use-testnet [live|paper]
Whether the testnet should be used
--binance-organization TEXT The name or id of the organization with the Binance module subscription
--binance-api-key TEXT Your Binance API key
--binance-api-secret TEXT Your Binance API secret
--zerodha-organization TEXT The name or id of the organization with the zerodha module subscription
--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 BOOLEAN
Whether you have a history API subscription for Zerodha
--samco-organization TEXT The name or id of the organization with the samco module subscription
--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
--terminal-link-organization TEXT
The name or id of the organization with the Terminal Link module subscription
--bloomberg-environment [Production|Beta]
The environment to run in
--bloomberg-server-host TEXT The host of the Bloomberg server
--bloomberg-server-port INTEGER
The port of the Bloomberg server
--bloomberg-symbol-map-file FILE
The path to the Bloomberg symbol map file
--bloomberg-emsx-broker TEXT The EMSX broker to use
--bloomberg-emsx-user-time-zone TEXT
The EMSX user timezone to use
--bloomberg-emsx-account TEXT The EMSX account to use
--bloomberg-emsx-strategy TEXT The EMSX strategy to use
--bloomberg-emsx-notes TEXT The EMSX notes to use
--bloomberg-emsx-handling TEXT The EMSX handling to use
--bloomberg-allow-modification BOOLEAN
Whether modification is allowed
--atreyu-organization TEXT The name or id of the organization with the Atreyu module subscription
--atreyu-host TEXT The host of the Atreyu server
--atreyu-req-port INTEGER The Atreyu request port
--atreyu-sub-port INTEGER The Atreyu subscribe port
--atreyu-username TEXT Your Atreyu username
--atreyu-password TEXT Your Atreyu password
--atreyu-client-id TEXT Your Atreyu client id
--atreyu-broker-mpid TEXT The broker MPID to use
--atreyu-locate-rqd TEXT The locate rqd to use
--tt-organization TEXT The name or id of the organization with the Trading Technologies module subscription
--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-market-data-sender-comp-id TEXT
The market data sender comp id to use
--tt-market-data-target-comp-id TEXT
The market data target comp id to use
--tt-market-data-host TEXT The host of the market data server
--tt-market-data-port TEXT The port of the market data server
--tt-order-routing-sender-comp-id TEXT
The order routing sender comp id to use
--tt-order-routing-target-comp-id TEXT
The order routing target comp id to use
--tt-order-routing-host TEXT The host of the order routing server
--tt-order-routing-port TEXT The port of the order routing server
--tt-log-fix-messages BOOLEAN Whether FIX messages should be logged
--kraken-organization TEXT The name or id of the organization with the kraken module subscription
--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
--ftx-exchange-name [FTX|FTXUS]
FTX exchange name [FTX, FTXUS]
--ftx-organization TEXT The name or id of the organization with the FTX module subscription
--ftx-api-key TEXT Your FTX API key
--ftxus-api-key TEXT Your FTX API key
--ftx-api-secret TEXT Your FTX API secret
--ftxus-api-secret TEXT Your FTX API secret
--ftx-account-tier [Tier1|Tier2|Tier3|Tier4|Tier5|Tier6]
Your FTX Account Tier
--ftxus-account-tier [Tier1|Tier2|Tier3|Tier4|Tier5|Tier6]
Your FTX Account Tier
--iqfeed-iqconnect FILE The path to the IQConnect binary
--iqfeed-username TEXT Your IQFeed username
--iqfeed-password TEXT Your IQFeed password
--iqfeed-productName TEXT The product name of your IQFeed developer account
--iqfeed-version TEXT The product version of your IQFeed developer account
--release Compile C# projects in release configuration instead of debug
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
--update Pull the LEAN engine image before starting live trading
--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.
lean login
使用 QuantConnect 帐户登录。
Usage: lean login [OPTIONS]
Log in with a QuantConnect account.
If user id or API token is not provided an interactive prompt will show.
Credentials are stored in ~/.lean/credentials and are removed upon running `lean logout`.
Options:
-u, --user-id TEXT QuantConnect user id
-t, --api-token TEXT QuantConnect API token
--verbose Enable debug logging
--help Show this message and exit.
lean logout
注销并删除存储的凭据。
Usage: lean logout [OPTIONS]
Log out and remove stored credentials.
Options:
--verbose Enable debug logging
--help Show this message and exit.
lean logs
显示最近的回测/实时/优化日志。
Usage: lean logs [OPTIONS]
Display the most recent backtest/live/optimization logs.
Options:
--backtest Display the most recent backtest logs (default)
--live Display the most recent live logs
--optimization Display the most recent optimization logs
--project DIRECTORY The project to get the most recent logs from
--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.
lean optimize
使用 Docker 在本地优化项目的参数。
Usage: lean optimize [OPTIONS] PROJECT
Optimize a project's parameters 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.
By default an interactive wizard is shown letting you configure the optimizer. If --optimizer-config or --strategy
is given the command runs in non-interactive mode. In this mode the CLI does not prompt for input.
The --optimizer-config option can be used to specify the configuration to run the optimizer with.
When using the option it should point to a file like this (the algorithm-* properties should be omitted):
https://github.com/QuantConnect/Lean/blob/master/Optimizer.Launcher/config.json
If --strategy is given the optimizer configuration is read from the given options. In this case --strategy,
--target, --target-direction and --parameter become required.
In non-interactive mode the --parameter option can be provided multiple times to configure multiple parameters:
- --parameter <name> <min value> <max value> <step size>
- --parameter my-first-parameter 1 10 0.5 --parameter my-second-parameter 20 30 5
In non-interactive mode the --constraint option can be provided multiple times to configure multiple constraints:
- --constraint "<statistic> <operator> <value>"
- --constraint "Sharpe Ratio >= 0.5" --constraint "Drawdown < 0.25"
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/optimizations/TIMESTAMP)
-d, --detach Run the optimization in a detached Docker container and return immediately
--optimizer-config FILE The optimizer configuration file that should be used
--strategy [Grid Search|Euler Search]
The optimization strategy to use
--target TEXT The target statistic of the optimization
--target-direction [min|max] Whether the target must be minimized or maximized
--parameter <TEXT FLOAT FLOAT FLOAT>...
The 'parameter min max step' pairs configuring the parameters to optimize
--constraint TEXT The 'statistic operator value' pairs configuring the constraints of the optimization
--release Compile C# projects in release configuration instead of debug
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
--update Pull the LEAN engine image before running the optimizer
--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.
lean report
生成回测报告。
Usage: lean report [OPTIONS]
Generate a report of a backtest.
This runs the LEAN Report Creator in Docker to generate a polished, professional-grade report of a backtest.
If --backtest-results is not given, a report is generated for the most recent local backtest.
The name, description, and version are optional and will be blank if not given.
If the given backtest data source file is stored in a project directory (or one of its subdirectories, like the
default <project>/backtests/<timestamp>), the default name is the name of the project directory and the default
description is the description stored in the project's config.json file.
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:
--backtest-results FILE Path to the JSON file containing the backtest results
--live-results FILE Path to the JSON file containing the live trading results
--report-destination FILE Path where the generated report is stored as HTML (defaults to ./report.html)
-d, --detach Run the report creator in a detached Docker container and return immediately
--strategy-name TEXT Name of the strategy, will appear at the top-right corner of each page
--strategy-version TEXT Version number of the strategy, will appear next to the project name
--strategy-description TEXT Description of the strategy, will appear under the 'Strategy Description' section
--overwrite Overwrite --report-destination if it already contains a file
--image TEXT The LEAN engine image to use (defaults to quantconnect/lean:latest)
--update Pull the LEAN engine image before running the report creator
--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.
lean research
使用 Docker 在本地运行 Jupyter Lab 环境。
Usage: lean research [OPTIONS] PROJECT
Run a Jupyter Lab environment locally using Docker.
By default the official LEAN research image is used. You can override this using the --image option. Alternatively
you can set the default research image using `lean config set research-image <image>`.
Options:
--port INTEGER The port to run Jupyter Lab on (defaults to 8888)
--data-provider [Terminal Link|QuantConnect|Local]
Update the Lean configuration file to retrieve data from the given provider
--download-data Update the Lean configuration file to download data from the QuantConnect API, alias
for --data-provider QuantConnect
--data-purchase-limit INTEGER The maximum amount of QCC to spend on downloading data during the research session
when using QuantConnect as data provider
-d, --detach Run Jupyter Lab in a detached Docker container and return immediately
--no-open Don't open the Jupyter Lab environment in the browser after starting it
--image TEXT The LEAN research image to use (defaults to quantconnect/research:latest)
--update Pull the LEAN research image before starting the research environment
--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.
lean whoami
显示谁登录。
Usage: lean whoami [OPTIONS]
Display who is logged in.
Options:
--verbose Enable debug logging
--help Show this message and exit.
发展
要使用精益 CLI,请克隆存储库,进入包含 Python 3.6+ 的环境并运行pip install -r requirements.txt. 此命令将安装所需的依赖项并以可编辑模式安装 CLI。这意味着您将能够编辑代码并在下次运行时立即看到结果lean。
如果需要添加依赖,先更新setup.py(如果是生产依赖)或者requirements.txt(如果是开发依赖)再重新运行pip install -r requirements.txt。
可以通过运行来运行自动化测试pytest。运行测试时会模拟文件系统和 HTTP 请求,以确保它们在隔离环境中运行。
python setup.py sdist bdist_wheel可以通过从项目的根目录运行并安装它来构建精益 CLI pip install --force-reinstall dist/lean-dev-py3-none-any.whl。安装新版本后,要更新自述文件的命令参考部分,请python scripts/readme.py从项目的根目录运行。
维护者可以通过将包含新版本的 Git 标签推送到 GitHub 来发布新版本。这将触发 GitHub Actions 工作流程,该工作流程将当前master分支发布到 PyPI,并将标签的值作为版本。确保版本没有以“v”为前缀。