API Reference
lean live deploy
Description
Starts local live trading in a Docker container using the quantconnect/lean Docker image.
The logs of the algorithm are shown in real-time and the full results are stored in the <project> / live / <timestamp> directory.
You can use the --output
option to change the output directory.
The given <project>
argument must be either a project directory or a file containing the algorithm to backtest.
If it is a project directory, the CLI looks for a main.py or Main.cs file, assuming the first file it finds to contain the algorithm to run.
By default, an interactive wizard is shown letting you configure the brokerage and data provider to use.
When you provide --environment
or both --brokerage
and --data-provider-live
, the command runs in non-interactive mode and does not prompt for input.
When the --environment
option is given, the environment with the given name is used.
The given environment must be one of the live environments stored in your Lean configuration file.
This means the environment must have the live-mode
property set to true
.
When --brokerage
and --data-provider-live
is given, the live configuration is read from the command-line options.
In case a required option has not been provided, the command falls back to the property with the same name in your Lean configuration file.
The command aborts if this property also hasn't been set.
The required options depend on the selected brokerage or data provider.
The following options are required for each brokerage in non-interactive mode:
--brokerage | Required Options |
---|---|
"Paper Trading" | N/A |
Alpaca | --alpaca-environment |
--alpaca-api-key | |
--alpaca-api-secret | |
Binance | --binance-exchange-name |
--binance-api-key or --binanceus-api-key | |
--binance-api-secret or --binanceus-api-secret | |
--binance-use-testnet | |
Bitfinex | --bitfinex-api-key |
--bitfinex-api-secret | |
Bybit | --bybit-api-key |
--bybit-api-secret | |
--bybit-vip-level | |
--bybit-use-testnet | |
"Coinbase Advanced Trade" | --coinbase-api-name |
--coinbase-api-private-key | |
"Interactive Brokers" | --ib-user-name |
--ib-account | |
--ib-password | |
Kraken | --kraken-api-key |
--kraken-api-secret | |
--kraken-verification-tier | |
Oanda | --oanda-account-id |
--oanda-access-token | |
--oanda-environment | |
Samco | --samco-client-id |
--samco-client-password | |
--samco-year-of-birth | |
--samco-product-type | |
--samco-trading-segment | |
TDAmeritrade | --tdameritrade-api-key |
--tdameritrade-access-token | |
--tdameritrade-account-number | |
"Terminal Link" | --terminal-link-connection-type |
--terminal-link-environment | |
--terminal-link-server-host | |
--terminal-link-server-port | |
--terminal-link-emsx-account | |
--terminal-link-emsx-broker | |
--terminal-link-openfigi-api-key | |
--terminal-link-server-auth-id if you use --terminal-link-connection-type SAPI | |
TradeStation | --trade-station-environment |
--trade-station-account-type | |
Tradier | --tradier-account-id |
--tradier-access-token | |
--tradier-environment | |
"Trading Technologies" | --tt-user-name |
--tt-session-password | |
--tt-account-name | |
--tt-rest-app-key | |
--tt-rest-app-secret | |
--tt-rest-environment | |
--tt-market-data-sender-comp-id | |
--tt-market-data-target-comp-id | |
--tt-market-data-host | |
--tt-market-data-port | |
--tt-order-routing-sender-comp-id | |
--tt-order-routing-target-comp-id | |
--tt-order-routing-host | |
--tt-order-routing-port | |
Zerodha | --zerodha-api-key |
--zerodha-access-token | |
--zerodha-product-type | |
--zerodha-trading-segment |
The --data-provider-live
option is required.
The following table shows the available live data providers and their required options in non-interactive mode.
To select multiple data providers, seperate them with a comma.
The order you select them in defines the order of precedence.
--data-provider-live | Required Options |
---|---|
Alpaca | All options required by --brokerage Alpaca . |
Binance | --binance-exchange-name |
--binance-api-key or --binanceus-api-key | |
--binance-api-secret or --binanceus-api-secret | |
Bitfinex | All options required by --brokerage Bitfinex . |
Bybit | --bybit-api-key |
--bybit-api-secret | |
--bybit-vip-level | |
CoinApi | --coinapi-api-key |
--coinapi-product | |
"Coinbase Advanced Trade" | All options required by --brokerage "Coinbase Advanced Trade" . |
"Custom data only" | N/A |
IEX | --iex-cloud-api-key |
--iex-price-plan | |
"Interactive Brokers" | All options required by --brokerage "Interactive Brokers" . |
--ib-enable-delayed-streaming-data | |
IQFeed | --iqfeed-iqconnect |
--iqfeed-username | |
--iqfeed-password | |
--iqfeed-version | |
--iqfeed-host | |
Kraken | All options required by --brokerage Kraken . |
Oanda | All options required by --brokerage Oanda . |
Polygon | --polygon-api-key |
Samco | All options required by --brokerage Samco . |
TDAmeritrade | All options required by --brokerage TDAmeritrade . |
"Terminal Link" | All options required by --brokerage "Terminal Link" . |
ThetaData | --thetadata-subscription-plan |
TradeStation | All options required by --brokerage TradeStation . |
Tradier | --tradier-account-id |
--tradier-access-token | |
"Trading Technologies" | --tt-user-name |
--tt-session-password | |
--tt-account-name | |
--tt-rest-app-key | |
--tt-rest-app-secret | |
--tt-rest-environment | |
--tt-order-routing-sender-comp-id | |
Zerodha | All options required by --brokerage Zerodha . |
--zerodha-history-subscription |
The --data-provider-historical
option specifies the source of historical data. The following table shows the available historical data providers and their required options in non-interactive mode. If the live data provider you set also provides historical data and you omit the --data-provider-historical
option, it defaults to the same value as the --data-provider-live
option. If the live data provider you set doesn't provide historical data and you omit the --data-provider-historical
option, it defaults to the Local
data provider.
--data-provider-historical | Required Options |
---|---|
Alpaca | All options required by --brokerage Alpaca . |
AlphaVantage | --alpha-vantage-api-key |
--alpha-vantage-price-plan | |
Binance | --binance-exchange-name |
--binance-api-key or --binanceus-api-key | |
--binance-api-secret or --binanceus-api-secret | |
Bitfinex | All options required by --brokerage Bitfinex . |
Bybit | --bybit-api-key |
--bybit-api-secret | |
--bybit-vip-level | |
CoinApi | --coinapi-api-key |
--coinapi-product | |
"Coinbase Advanced Trade" | All options required by --brokerage "Coinbase Advanced Trade" . |
FactSet | --factset-auth-config-file |
IEX | --iex-cloud-api-key |
--iex-price-plan | |
"Interactive Brokers" | All options required by --brokerage "Interactive Brokers" . |
IQFeed | --iqfeed-iqconnect |
--iqfeed-username | |
--iqfeed-password | |
--iqfeed-version | |
--iqfeed-host | |
Kraken | All options required by --brokerage Kraken . |
Local | N/A |
Oanda | All options required by --brokerage Oanda . |
Polygon | --polygon-api-key |
QuantConnect | N/A |
ThetaData | --thetadata-subscription-plan |
TradeStation | All options required by --brokerage TradeStation . |
Zerodha | All options required by --brokerage Zerodha . |
--zerodha-history-subscription |
If you omit some of the required brokerage or data provider options when running in non-interactive mode, the CLI uses the option values in your LEAN configuration file.
Example non-interactive usage:
$ lean live deploy "My Project" \ --brokerage "Paper Trading" \ --data-provider-live "Interactive Brokers" \ --ib-user-name trader777 \ --ib-account DU1234567 \ --ib-password hunter2 \ --ib-enable-delayed-streaming-data yes
The Docker image that is used contains the same libraries as the ones available on QuantConnect. If the selected project is a C# project, it is compiled before starting live trading.
By default, the official LEAN engine image is used.
You can override this using the --image <value>
option.
Alternatively, you can set the default engine image for all commands using lean config set engine-image <value>
.
The image is pulled before starting the local live trading if it doesn't exist locally yet or if you pass the --update
flag.
Options
The lean live deploy
command supports the following options:
Option | Description |
---|---|
--environment <string> | 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 |
--brokerage <enum: Paper Trading | The brokerage to use |
--data-provider-live <enum: Interactive Brokers | The live data provider to use |
--data-provider-historical <enum: Interactive Brokers | Update the Lean configuration file to retrieve data from the given historical provider |
--ib-user-name <string> | Your Interactive Brokers username |
--ib-account <string> | Your Interactive Brokers account id |
--ib-password <string> | Your Interactive Brokers password |
--ib-weekly-restart-utc-time <string> | 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) |
--tradier-account-id <string> | Your Tradier account id |
--tradier-access-token <string> | Your Tradier access token |
--tradier-environment <enum: live|paper> | Whether the developer sandbox should be used |
--oanda-account-id <string> | Your OANDA account id |
--oanda-access-token <string> | Your OANDA API token |
--oanda-environment <enum: Practice|Trade> | The environment to run in, Practice for fxTrade Practice, Trade for fxTrade |
--bitfinex-api-key <string> | Your Bitfinex API key |
--bitfinex-api-secret <string> | Your Bitfinex API secret |
--coinbase-api-name <string> | Your Coinbase Advanced Trade API name from file |
--coinbase-api-private-key <string> | Your Coinbase Advanced Trade API private key from file |
--binance-exchange-name <enum: Binance | Binance exchange name [Binance, BinanceUS, Binance-USDM-Futures, Binance-COIN-Futures] |
--binance-api-key <string> | Your Binance API key |
--binanceus-api-key <string> | Your Binance API key |
--binance-api-secret <string> | Your Binance API secret |
--binanceus-api-secret <string> | Your Binance API secret |
--binance-use-testnet <enum: live|paper> | Whether the testnet should be used |
--zerodha-api-key <string> | Your Kite Connect API key |
--zerodha-access-token <string> | Your Kite Connect access token |
--zerodha-product-type <enum: 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 <enum: equity|commodity> | EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading commodities on MCX |
--zerodha-history-subscription <enum: true|false> | Whether you have a history API subscription for Zerodha |
--samco-client-id <string> | Your Samco account Client ID |
--samco-client-password <string> | Your Samco account password |
--samco-year-of-birth <string> | Your year of birth (YYYY) registered with Samco |
--samco-product-type <enum: 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 <enum: equity|commodity> | EQUITY if you are trading equities on NSE or BSE, COMMODITY if you are trading commodities on MCX |
--terminal-link-connection-type <enum: DAPI|SAPI> | Terminal Link Connection Type [DAPI, SAPI] |
--terminal-link-environment <enum: Production|Beta> | The environment to run in |
--terminal-link-server-host <string> | The host of the TerminalLink server |
--terminal-link-server-port <integer> | The port of the TerminalLink server |
--terminal-link-emsx-broker <string> | The EMSX broker to use (Optional) |
--terminal-link-emsx-account <string> | The EMSX account to use (Optional) |
--terminal-link-emsx-team <string> | The EMSX team to receive order events from (Optional) |
--terminal-link-openfigi-api-key <string> | The Open FIGI API key to use for mapping options |
--terminal-link-server-auth-id <string> | The Auth ID of the TerminalLink server |
--tt-user-name <string> | Your Trading Technologies username |
--tt-session-password <string> | Your Trading Technologies session password |
--tt-account-name <string> | Your Trading Technologies account name |
--tt-rest-app-key <string> | Your Trading Technologies REST app key |
--tt-rest-app-secret <string> | Your Trading Technologies REST app secret |
--tt-rest-environment <string> | The REST environment to run in |
--tt-order-routing-sender-comp-id <string> | The order routing sender comp id to use |
--tt-market-data-sender-comp-id <string> | The market data sender comp id to use |
--tt-market-data-target-comp-id <string> | The market data target comp id to use |
--tt-market-data-host <string> | The host of the market data server |
--tt-market-data-port <string> | The port of the market data server |
--tt-order-routing-target-comp-id <string> | The order routing target comp id to use |
--tt-order-routing-host <string> | The host of the order routing server |
--tt-order-routing-port <string> | The port of the order routing server |
--tt-log-fix-messages <boolean> | Whether FIX messages should be logged (Optional) |
--kraken-api-key <string> | Your Kraken API key |
--kraken-api-secret <string> | Your Kraken API secret |
--kraken-verification-tier <enum: Starter|Intermediate|Pro> | Your Kraken Verification Tier |
--tdameritrade-api-key <string> | Your TDAmeritrade API key |
--tdameritrade-access-token <string> | Your TDAmeritrade OAuth Access Token |
--tdameritrade-account-number <string> | Your TDAmeritrade account number |
--bybit-api-key <string> | Your Bybit API key |
--bybit-api-secret <string> | Your Bybit API secret |
--bybit-vip-level <enum: VIP0 | Your Bybit VIP Level |
--bybit-use-testnet <enum: live|paper> | Whether the testnet should be used |
--trade-station-environment <enum: live|paper> | Whether Live or Paper environment should be used |
--trade-station-account-id <string> | The TradeStation account Id |
--alpaca-environment <enum: live|paper> | Whether Live or Paper environment should be used |
--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 (Optional) |
--iqfeed-iqconnect <string> | The path to the IQConnect binary |
--iqfeed-username <string> | Your IQFeed username |
--iqfeed-password <string> | Your IQFeed password |
--iqfeed-version <string> | The product version of your IQFeed developer account |
--iqfeed-host <string> | The IQFeed host address (Optional) |
--polygon-api-key <string> | Your Polygon.io API Key |
--iex-cloud-api-key <string> | Your iexcloud.io API token publishable key |
--iex-price-plan <enum: Launch|Grow|Enterprise> | Your IEX Cloud Price plan |
--coinapi-api-key <string> | Your coinapi.io Api Key |
--coinapi-product <enum: Free | CoinApi pricing plan (https://www.coinapi.io/market-data-api/pricing) |
--thetadata-ws-url <string> | The ThetaData host address (Optional) |
--thetadata-rest-url <string> | The ThetaData host address (Optional) |
--thetadata-subscription-plan <enum: Free | Your ThetaData subscription price plan |
--alpaca-api-key <string> | Your Alpaca Api Key |
--alpaca-api-secret <string> | Your Alpaca Api Secret |
--factset-auth-config-file <file> | The path to the FactSet authentication configuration file |
--alpha-vantage-api-key <string> | Your Alpha Vantage Api Key |
--alpha-vantage-price-plan <enum: Free | Your Alpha Vantage Premium API Key plan |
--release | Compile C# projects in release configuration instead of debug |
--image <string> | The LEAN engine image to use (defaults to quantconnect/lean:latest) |
--python-venv <string> | The path of the python virtual environment to be used |
--live-cash-balance <string> | A comma-separated list of currency:amount pairs of initial cash balance |
--live-holdings <string> | A comma-separated list of symbol:symbolId:quantity:averagePrice of initial portfolio holdings |
--update | Pull the LEAN engine image before starting live trading |
--show-secrets | Show secrets as they are input |
--extra-docker-config <string> | 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 |
--lean-config <file> | The Lean configuration file that should be used (defaults to the nearest lean.json) |
--verbose | Enable debug logging |
--help | Display the help text of the lean live deploy command and exit |