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 run a backtest for. 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:

  • --brokerage "Paper Trading"
    • No required options.
  • --brokerage "Interactive Brokers"
    • --ib-user-name: must be set to your Interactive Brokers username (example: trader777).
    • --ib-account: must be set to your Interactive Brokers account id (example: DU1234567).
    • --ib-password: must be set to your Interactive Brokers account password.
  • --brokerage "Tradier"
    • --tradier-account-id: must be set to your Tradier account id, which you can find on your Settings/API Access page.
    • --tradier-access-token: must be set to your Tradier access token.
    • --tradier-use-sandbox: must be set to yes or no depending on whether you want to use the developer sandbox.
  • --brokerage "OANDA"
    • --oanda-account-id: must be set to your OANDA account id, which you can find on your Account Statement page.
    • --oanda-access-token: must be set to your OANDA API token, which you can generate on the Manage API Access page.
    • --oanda-environment: must be set to Practice for fxTrade Practice or Trade for fxTrade.
  • --brokerage "Bitfinex"
    • --bitfinex-api-key: must be set to your Bitfinex API key, which you can generate on the API Management page.
    • --bitfinex-api-secret: must be set to your Bitfinex API secret.
  • --brokerage "Coinbase Pro"
    • --gdax-api-key: must be set to your Coinbase Pro API key, which you can generate on the API settings page.
    • --gdax-api-secret: must be set to your Coinbase Pro API secret.
    • --gdax-passphrase: must be set to your Coinbase Pro API passphrase.
    • --gdax-use-sandbox: must be set to yes or no depending on whether you want to use the sandbox.
  • --brokerage "Binance"
    • --binance-api-key: must be set to your Binance API key, which you can generate on the API Management page.
    • --binance-api-secret: must be set to your Binance API secret.
    • --binance-use-testnet: must be set to yes or no depending on whether you want to use the testnet.
  • --brokerage "Zerodha"
    • --zerodha-api-key: must be set to your Kite Connect API key.
    • --zerodha-access-token: must be set to your Kite Connect access token.
    • --zerodha-product-type: must be set to 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: must be set to EQUITY if you are trading equities on NSE or BSE, or COMMODITY if you are trading commodities on MCX.
  • --brokerage "Trading Link"
    • --terminal-link-organization: must be set to the name or id of the QuantConnect organization with a license for the Terminal Link module.
    • --bloomberg-environment: must be set to the environment to use, which can be either Production or Beta.
    • --bloomberg-server-host: must be set to the host of the Bloomberg server.
    • --bloomberg-server-port: must be set to the port of the Bloomberg server.
    • --bloomberg-symbol-map-file: must be set to the path to a symbol map file. The symbol map file must be a JSON file (comments are supported) in which the keys are the Bloomberg symbol names and the values are the 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"
          }*/
      }
      
    • --bloomberg-emsx-broker: must be set to the name of the EMSX broker to use.
    • --bloomberg-emsx-user-time-zone: may be set to EMSX user timezone to use (optional).
    • --bloomberg-emsx-account: may be set to EMSX account to use (optional).
    • --bloomberg-emsx-strategy: may be set to the EMSX strategy to use (optional).
    • --bloomberg-emsx-notes: may be set to the EMSX notes to use (optional).
    • --bloomberg-emsx-handling: may be set to EMSX handling to use (optional).
    • --bloomberg-allow-modification: must be set to yes or no depending on whether modification is allowed.
  • --brokerage "Atreyu"
    • --atreyu-organization: must be set to the name or id of the QuantConnect organization with a license for the Atreyu module.
    • --atreyu-host: must be set to the host of the Atreyu server.
    • --atreyu-req-port: must be set to the request port to use.
    • --atreyu-sub-port: must be set to the subscribe port to use.
    • --atreyu-username: must be set to your Atreyu username.
    • --atreyu-password: must be set to your Atreyu password.
    • --atreyu-client-id: must be set to Atreyu client id.
    • --atreyu-broker-mpid: must be set to the broker MPID to use.
    • --atreyu-locate-rqd: must be set to the locate rqd to use.
  • --brokerage "Trading Technologies"
    • --tt-organization: must be set to the name or id of the QuantConnect organization with a license for the Trading Technologies module.
    • --tt-user-name: must be set to your Trading Technologies username.
    • --tt-session-password: must be set to Trading Technologies session password.
    • --tt-account-name: must be set to Trading Technologies account name.
    • --tt-rest-app-key: must be set to your Trading Technologies REST app key.
    • --tt-rest-app-secret: must be set to Trading Technologies app secret.
    • --tt-rest-environment: must be set to the REST environment to run in.
    • --tt-market-data-sender-comp-id: must be set to the market data sender comp id.
    • --tt-market-data-target-comp-id: must be set to the market data target comp id.
    • --tt-market-data-host: must be set to the host of the market data server.
    • --tt-market-data-port: must be set to the port of the market data server.
    • --tt-order-routing-sender-comp-id: must be set to the order routing sender comp id.
    • --tt-order-routing-target-comp-id: must be set to the order routing target comp id.
    • --tt-order-routing-host: must be set to the host of the order routing server.
    • --tt-order-routing-port: must be set to the port of the order routing server.
    • --tt-log-fix-messages: must be set to yes or no depending on whether FIX messages should be logged.

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

  • --data-feed "Interactive Brokers"
    • Inherits all options required by --brokerage "Interactive Brokers".
    • --ib-enable-delayed-streaming-data: must be set to yes or no depending on whether delayed data may be used when your algorithm subscribes to a security you don't have a market data subscription for.
  • --data-feed "Tradier"
    • Inherits all options required by --brokerage "Tradier".
  • --data-feed "OANDA"
    • Inherits all options required by --brokerage "Tradier".
  • --data-feed "Bitfinex"
    • Inherits all options required by --brokerage "Bitfinex".
  • --data-feed "Coinbase Pro"
    • Inherits all options required by --brokerage "Coinbase Pro".
  • --data-feed "Binance"
    • Inherits all options required by --brokerage "Binance".
  • --data-feed "Zerodha"
    • Inherits all options required by --brokerage "Zerodha".
    • --zerodha-history-subscription: must be set to yes or no depending on whether you have a history API subscription for Zerodha.
  • --data-feed "Terminal Link"
    • Inherits all options required by --brokerage "Terminal Link".
  • --data-feed "Atreyu"
    • Inherits all options required by --brokerage "Atreyu".
  • --data-feed "Trading Technologies"
    • Inherits all options required by --brokerage "Trading Technologies".
  • --data-feed "IQFeed" (only supported on Windows)
    • --iqfeed-iqconnect: must be set to the path to your IQConnect binary.
    • --iqfeed-username: must be set to your IQFeed username.
    • --iqfeed-password: must be set to your IQFeed password.
    • --iqfeed-product-name: must be set to the product name of your IQFeed developer account.
    • --iqfeed-version: must be set to the product version of your IQFeed developer account.
  • --data-feed "Custom data only"
    • No required options.

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 for.

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.
--guiEnable monitoring and controlling of the deployment via the GUI.
--gui-organization <value>The name or id of the QuantConnect organization with a subscription for the local GUI module.
--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.
--ib-user-name <value>Your Interactive Brokers username.
--ib-account <value>Your Interactive Brokers account id.
--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 you don't have a market data subscription for.
--tradier-account-id <value>Your Tradier account id.
--tradier-access-token <value>Your Tradier access token.
--tradier-use-sandbox <boolean>Whether the developer sandbox should be used.
--oanda-account-id <value>Your OANDA account id.
--oanda-access-token <value>Your OANDA API token.
--oanda-environment <value>Practice if you want to trade on fxTrade Practice, or Trade if you want to trade on fxTrade.
--bitfinex-api-key <value>Your Bitfinex API key.
--bitfinex-api-secret <value>Your Bitfinex API secret.
--gdax-api-key <value>Your Coinbase Pro API key.
--gdax-api-secret <value>Your Coinbase Pro API secret.
--gdax-passphrase <value>Your Coinbase Pro API passphrase.
--gdax-use-sandbox <boolean>Whether the sandbox should be used.
--binance-api-key <value>Your Binance API key.
--binance-api-secret <value>Your Binance API secret.
--binance-use-testnet lt;boolean>Whether the testnet should be used.
--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.
--terminal-link-organization <value>The name or id of the QuantConnect organization with a subscription for the Terminal Link module.
--bloomberg-environment <value>The environment to run int, which must be Production or Beta.
--bloomberg-server-host <value>The host on which the Bloomberg server is running.
--bloomberg-server-port <value>The port on which the Bloomberg server is running.
--bloomberg-symbol-map-file <path>The path to the symbol map file. The symbol map file must be a JSON file in which the keys are Bloomberg symbol names and the values are corresponding QuantConnect symbols.
--bloomberg-emsx-broker <value>The EMSX broker to use.
--bloomberg-emsx-user-timezone <value>The EMSX user timezone to use.
--bloomberg-emsx-account <value>The EMSX account to use.
--bloomberg-emsx-strategy <value>The EMSX strategy to use.
--bloomberg-emsx-notes <value>The EMSX notes to use.
--bloomberg-emsx-handling <value>The EMSX handling to use.
--bloomberg-allow-modification <boolean>Whether modification is allowed.
--atreyu-organization <value>The name or id of the QuantConnect organization with a subscription for the Atreyu module.
--atreyu-host <value>The host of the Atreyu server.
--atreyu-req-port <value>The Atreyu request port.
--atreyu-sub-port <value>The Atreyu subscribe port.
--atreyu-username <value>Your Atreyu username.
--atreyu-password <value>Your Atreyu password.
--atreyu-client-id <value>Your Atreyu client id.
--atreyu-broker-mpid <value>The broker MPID to use.
--atreyu-locate-rqd <value>The locate rqd to use.
--tt-organization <value>The name or id of the QuantConnect organization with a subscription for the Trading Technologies module.
--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 to run in.
--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.
--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.
--image <value>The LEAN engine image to use (defaults to quantconnect/lean:latest).
--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 Chat.

Did you find this page helpful?

Contribute to the documentation: