API Reference

lean live

Introduction

Start live trading a project locally using Docker.

$ lean live <project> [options]

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 feed to use. When --environment, --brokerage, or --data-feed is given, 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 or --data-feed 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 feed.

The following options are required for each brokerage in non-interactive mode:

--brokerageRequired Options
"Paper Trading"N/A
"Atreyu"--atreyu-host
--atreyu-req-port
--atreyu-sub-port
--atreyu-username
--atreyu-password
--atreyu-client-id
--atreyu-broker-mpid
--atreyu-locate-rqd
"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
"Coinbase Pro"--gdax-api-key
--gdax-api-secret
--gdax-passphrase
--gdax-use-sandbox
"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
"Terminal Link"--terminal-link-environment
--terminal-link-server-host
--terminal-link-server-port
--terminal-link-emsx-broker
--terminal-link-allow-modification
"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
--tt-log-fix-messages
"Zerodha"--zerodha-api-key
--zerodha-access-token
--zerodha-product-type
--zerodha-trading-segment

The --data-feed option is required. The following table shows the available data feeds and their required options in non-interactive mode:

--data-feedRequired Options
"Atreyu"All options required by --brokerage "Atreyu".
"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".
"Coinbase Pro"--gdax-api-key
--gdax-api-secret
--gdax-passphrase
"Custom data only"N/A
"Interactive Brokers"All options required by --brokerage "Interactive Brokers".
--ib-enable-delayed-streaming-data
"IQFeed"--iqfeed-iqconnect
--iqfeed-username
--iqfeed-password
--iqfeed-product-name
--iqfeed-version
"Kraken"All options required by --brokerage "Kraken".
"OANDA"--oanda-account-id
--oanda-access-token
"Polygon Data Feed"--polygon-api-key
"Samco"All options required by --brokerage "Samco".
"Terminal Link"All options required by --brokerage "Terminal Link".
"Tradier"--tradier-account-id
--tradier-access-token
"Zerodha"All options required by --brokerage "Zerodha".
--zerodha-history-subscription

If you omit some of the required brokerage or data feed options when running in non-interactive mode, the CLI uses the option values in your LEAN configuration file.

Example non-interactive usage:

$ lean live "My Project" \
    --brokerage "Paper Trading" \
    --data-feed "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.

Arguments

The lean live command expects the following arguments:

ArgumentDescription
<project>The path to the project directory or algorithm file to start local live trading.

Options

The lean live command supports the following options:

OptionDescription
--environment <value>The name of the environment in the Lean configuration file to use.
--output <path>Directory to store results in (defaults to <project>/live/<timestamp>).
--detach, -dRun the live deployment in a detached Docker container and return immediately. The name of the Docker container is shown before the command ends. You can use Docker's own commands to manage the detached container.
--brokerage <value>The brokerage to use when running in non-interactive mode.
--data-feed <value>The data feed to use when running in non-interactive mode.
--data-provider <value>Update the Lean configuration file to retrieve data from the given provider (Terminal Link, QuantConnect, or Local).
--atreyu-host <value>The host of the Atreyu Trading server.
--atreyu-req-port <value>The Atreyu Trading request port.
--atreyu-sub-port <value>The Atreyu Trading subscribe port.
--atreyu-username <value>Your Atreyu Trading username.
--atreyu-password <value>Your Atreyu Trading password.
--atreyu-client-id <value>Your Atreyu Trading client id.
--atreyu-broker-mpid <value>The broker MPID to use.
--atreyu-locate-rqd <value>The locate rqd to use.
--binance-exchange-name <value>Binance or BinanceUS
--binance-api-key <value>Your Binance API key, which you can generate on the API Management page on the Binance website.
--binanceus-api-key <value>Your Binance US API key, which you can generate on the API Management page on the Binance US website.
--binance-api-secret <value>Your Binance API secret.
--binanceus-api-secret <value>Your Binance US API secret.
--binance-use-testnet <value>live to use the production environment or paper to use the testnet.
--bitfinex-api-key <value>Your Bitfinex API key, which you can generate on the API Management page on the Bitfinex website.
--bitfinex-api-secret <value>Your Bitfinex API secret.
--gdax-api-key <value>Your Coinbase Pro API key, which you can generate on the API settings page on the Coinbase Pro website.
--gdax-api-secret <value>Your Coinbase Pro API secret.
--gdax-passphrase <value>Your Coinbase Pro API passphrase.
--gdax-use-sandbox <value>live to use the live trading environment or paper to use the sandbox.
--ib-user-name <value>Your Interactive Brokers username (example: trader777).
--ib-account <value>Your Interactive Brokers account id (example: DU1234567).
--ib-password <value>Your Interactive Brokers password.
--ib-enable-delayed-streaming-data <boolean>Whether delayed data may be used when your algorithm subscribes to a security for which you don't have a market data subscription.
--iqfeed-iqconnect <path>The path to your IQConnect binary.
--iqfeed-username <value>Your IQFeed username.
--iqfeed-password <value>Your IQFeed password.
--iqfeed-product-name <value>The product name of your IQFeed developer account.
--iqfeed-version <value>The product version of your IQFeed developer account.
--kraken-api-key <value>Your Kraken API key, which you can find on the API Management Settings page on the Kraken website.
--kraken-api-secret <value>Your Kraken API secret.
--kraken-verification-tier <value>Your Kraken verification tier (Starter, Intermediate, or Pro). For more information about verification tiers, see Verification levels explained on the Kraken website.
--oanda-account-id <value>Your OANDA account id, which you can find on your Account Statement page on the OANDA website.
--oanda-access-token <value>Your OANDA API token, which you can generate on the Manage API Access page on the OANDA website.
--oanda-environment <value>Practice to trade on fxTrade Practice or Trade to trade on fxTrade.
--polygon-api-key <value>Your Polygon data feed API Key.
--samco-client-id <value>Your Samco account Client ID.
--samco-client-password <value>Your Samco account password.
--samco-year-of-birth <value>Your year of birth (YYYY) registered with Samco.
--samco-product-type <value>The product type, which must be mis if you are targeting intraday products, cnc if you are targeting delivery products, or nrml if you are targeting carry forward products.
--samco-trading-segment <value>The trading segment, which must be equity if you are trading equities on NSE or BSE, or commodity if you are trading commodities on MCX.
--terminal-link-environment <value>The environment to run in, which must be Production or Beta.
--terminal-link-server-host <value>The host on which the Terminal Link server is running.
--terminal-link-server-port <value>The port on which the Terminal Link server is running.
--terminal-link-symbol-map-file <path>The path to the symbol map file. The symbol map file must be a JSON file (comments are supported) in which the keys are Bloomberg symbol names and the values are corresponding QuantConnect symbols. This content can be used as an example:
/* This is a manually created file that contains mappings from Bloomberg's own naming to original symbols defined by respective exchanges. */
{
    // Example:
    /*"SPY US Equity": {
        "Underlying": "SPY",
        "SecurityType": "Equity",
        "Market": "usa"
    }*/
}
--terminal-link-emsx-broker <value>The EMSX broker to use.
--terminal-link-emsx-user-timezone <value>The EMSX user time zone to use (optional).
--terminal-link-emsx-account <value>The EMSX account to use (optional).
--terminal-link-emsx-strategy <value>The EMSX strategy to use (optional).
--terminal-link-emsx-notes <value>The EMSX notes to use (optional).
--terminal-link-emsx-handling <value>The EMSX handling to use (optional).
--terminal-link-allow-modification <boolean>Whether modification is allowed.
--tradier-account-id <value>Your Tradier account id, which you can find on your Settings > API Access page on the Tradier website.
--tradier-access-token <value>Your Tradier access token.
--tradier-environment <value>live to use the live environment or paper to use the developer sandbox.
--tt-user-name <value>Your Trading Technologies username.
--tt-session-password <value>Your Trading Technologies session password.
--tt-account-name <value>Your Trading Technologies account name.
--tt-rest-app-key <value>Your Trading Technologies REST app key.
--tt-rest-app-secret <value>Your Trading Technologies REST app secret.
--tt-rest-environment <value>The REST environment in which to run.
--tt-market-data-sender-comp-id <value>The market data sender comp id to use.
--tt-market-data-target-comp-id <value>The market data target comp id to use.
--tt-market-data-host <value>The host of the market data server.
--tt-market-data-port <value>The port of the market data server.
--tt-order-routing-sender-comp-id <value>The order routing sender comp id to use.
--tt-order-routing-target-comp-id <value>The order routing target comp id to use.
--tt-order-routing-host <value>The host of the order routing server.
--tt-order-routing-port <value>The port of the order routing server.
--tt-log-fix-messages <boolean>Whether FIX messages should be logged.
--zerodha-api-key <value>Your Kite Connect API key.
--zerodha-access-token <value>Your Zerodha access token.
--zerodha-product-type <value>The product type, which must be mis if you are targeting intraday products, cnc if you are targeting delivery products, or nrml if you are targeting carry forward products.
--zerodha-trading-segment <value>The trading segment, which must be equity if you are trading equities on NSE or BSE, or commodity if you are trading commodities on MCX.
--zerodha-history-subscription <boolean>Whether you have a history API subscription for Zerodha.
--live-cash-balance <value>A comma-separated list of currency:amount pairs that define the initial cash balance.
--live-holdings <value>A comma-separated list of "symbol:symbolId:quantity:averagePrice" pairs that define the initial portfolio holdings. For example, "GOOG:GOOCV VP83T1ZUHROL:10:50.0".
--image <value>The LEAN engine image to use (defaults to quantconnect/lean:latest).
--python-venv <value>The path of the python virtual environment to use.
--updatePull the LEAN engine image before starting live trading.
--lean-config <path>The Lean configuration file that should be used (defaults to the nearest lean.json file).
--releaseCompile C# projects in release configuration instead of debug.
--verboseEnable debug logging.
--helpDisplay the help text of the lean live command and exit.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: