Live trading

Local live trading

Introduction

The Lean CLI supports local live trading with all brokerages supported by LEAN, which makes the transfer from backtesting to live trading as seamless as possible. This page contains instructions on how to start local live trading for all the brokerages supported by LEAN.

Follow these steps to start local live trading:

  1. Open a terminal in the directory you ran lean init in.
  2. Run lean live "My Project" to start a live deployment wizard for the project in ./My Project.
    $ lean live "My Project"
    Select a brokerage:
    1) Paper Trading
    2) Interactive Brokers
    3) Tradier
    4) OANDA
    5) Bitfinex
    6) Coinbase Pro
    7) Binance
    8) Zerodha
    9) Terminal Link
    10) Atreyu
    11) Trading Technologies
    Enter an option:
  3. Enter the number of the brokerage to use.
    $ lean live "My Project"
    Select a brokerage:
    1) Paper Trading
    2) Interactive Brokers
    3) Tradier
    4) OANDA
    5) Bitfinex
    6) Coinbase Pro
    7) Binance
    8) Zerodha
    9) Terminal Link
    10) Atreyu
    11) Trading Technologies
    Enter an option:
  4. Configure your brokerage settings. Depending on which brokerage you select in step 3 you get different prompts to configure your credentials. See the table of contents on the right for quick links to exact instructions for each brokerage.
  5. Enter the number of the data feed to use.
    $ lean live "My Project"
    Select the data feed to use:
    1) Interactive Brokers
    2) Tradier
    3) OANDA
    4) Bitfinex
    5) Coinbase Pro
    6) Binance
    7) Zerodha
    8) Terminal Link
    9) Trading Technologies
    10) Custom data only
    11) IQFeed
    Enter an option:
    This step is only shown if you selected the paper trading brokerage in step 3 or if you are on Windows.
  6. Configure your data feed. Depending on which data feed you select in step 5 you get different prompts to configure your credentials. See the table of contents on the right for quick links to exact instructions for each data feed.
  7. View the result in the <project>/live/<timestamp> directory. Results are stored in real-time in JSON format. You can save results to a different directory by providing the --output <path> option in step 2.

If you already have a live environment configured in your Lean configuration file, you can skip the interactive wizard by providing the --environment <value> option in step 2. The value of this option must be the name of an environment which has live-mode set to true.

If you are using the local GUI you can make it possible to monitor and control the live deployment through there by providing the --gui flag in step 2.

Paper trading

The paper trading brokerage does not have any brokerage-specific settings. After selecting "Paper Trading" in step 3 of the tutorial in the introduction, the CLI automatically skips to step 5.

If your algorithm only uses custom data, you can select the "Custom data only" data feed option in step 5 of the tutorial in the introduction. This data feed doesn't require any brokerage credentials, but only works if your algorithm doesn't subscribe to non-custom data. Your algorithm crashes if it attempts to subscribe to non-custom data with this data feed in place.

Interactive Brokers

Follow these steps after selecting Interactive Brokers as your brokerage in the tutorial in the introduction:

  1. Log in to Interactive Brokers in your browser and go to User Settings > Security > Secure Login System.
  2. Deselect all options or only select "IB Key Security via IBKR Mobile" on the Secure Login System page.
  3. Go back to the terminal and enter your Interactive Brokers username, account id, and password.
    $ lean live "My Project"
    Username: trader777
    Account id: DU1234567
    Account password: ****************
  4. Continue with the next step of the tutorial in the introduction.

Follow these steps after selecting Interactive Brokers as your data feed in the tutorial in the introduction:

  1. Follow the steps of configuring Interactive Brokers as brokerage above if you chose paper trading as the brokerage.
  2. Enter whether you want to enable delayed market data.
    $ lean live "My Project"
    Enable delayed market data? [y/N]: y
    This property configures the behavior when your algorithm attempts to subscribe to market data for which you don't have a market data subscription on Interactive Brokers. When enabled, your algorithm continues running using delayed market data. When disabled, live trading will stop and LEAN will shut down.
  3. Continue with the next step of the tutorial in the introduction.

Tradier

Follow these steps after selecting Tradier as your brokerage or data feed in the tutorial in the introduction:

  1. Enter your Tradier account id and access token. You can find these credentials on your Settings/API Access page.
    $ lean live "My Project"
    Account id: VA000001
    Access token: ****************
  2. Enter whether the developer sandbox should be used.
    $ lean live "My Project"
    Use the developer sandbox? [y/N]: y
  3. Continue with the next step of the tutorial in the introduction.

OANDA

Follow these steps after selecting OANDA as your brokerage or data feed in the tutorial in the introduction:

  1. Enter your OANDA account id. You can find this number on your Account Statement page.
    $ lean live "My Project"
    Account id: 001-011-5838423-001
  2. Enter your OANDA API token. You can generate a token on the Manage API Access page.
    $ lean live "My Project"
    API token: ****************
  3. Enter which environment you want to use. You can either choose trade for fxTrade or practice for fxTrade Practice.
    $ lean live "My Project"
    Environment (practice, trade): practice
  4. Continue with the next step of the tutorial in the introduction.

Bitfinex

Follow these steps after selecting Bitfinex as your brokerage or data feed in the tutorial in the introduction:

  1. Enter your API key id and secret. You can generate new API credentials on the API Management page.
    $ lean live "My Project"
    API key: bbbMsqbxjytVM9cGvnLpKguz9rZf2T5qACxaVx7E8Mm
    API secret: *******************************************
  2. Continue with the next step of the tutorial in the introduction.

Coinbase Pro

Follow these steps after selecting Coinbase Pro as your brokerage or data feed in the tutorial in the introduction:

  1. Enter your API key, API secret, and passphrase. You can generate new API credentials on the API settings page.
    $ lean live "My Project"
    API key: 6d3ef5ca2d2fa52e4ee55624b0471261
    API secret: ****************************************************************************************
    Passphrase: ****************
  2. Enter whether the sandbox should be used.
    $ lean live "My Project"
    Use the sandbox? [y/N]: n
  3. Continue with the next step of the tutorial in the introduction.

Binance

Follow these steps after selecting Binance as your brokerage or data feed in the tutorial in the introduction:

  1. Enter your API key and API secret. You can create a new API key on the API Management page.
    $ lean live "My Project"
    API key: 6d3ef5ca2d2fa52e4ee55624b0471261
    API secret: ********************************
  2. Enter whether the testnet should be used.
    $ lean live "My Project"
    Use the testnet? [y/N]: n
  3. Continue with the next step of the tutorial in the introduction.

Zerodha

Follow these steps after selecting Zerodha as your brokerage in the tutorial in the introduction:

  1. Enter your Kite Connect API key and access token.
    $ lean live "My Project"
    API key: hp9erb9ct0lqaxpm
    Access token: ********************
  2. Enter the product type. This property 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.
    $ lean live "My Project"
    Product type (MIS, CNC, NRML): MIS
  3. Enter the trading segment. This property must be EQUITY if you are trading equities on NSE or BSE, or COMMODITY if you are trading commodities on MCX.
    $ lean live "My Project"
    Trading segment (EQUITY, COMMODITY): EQUITY
  4. Continue with the next step of the tutorial in the introduction.

Follow these steps after selecting Zerodha as your data feed in the tutorial in the introduction:

  1. Follow the steps of configuring Zerodha as brokerage above if you chose paper trading as the brokerage.
  2. Enter whether you have a history API subscription.
    $ lean live "My Project"
    Do you have a history API subscription? [y/N]: y
  3. Continue with the next step of the tutorial in the introduction.

Terminal Link

Follow these steps after selecting Terminal Link as your brokerage or data feed in the tutorial in the introduction:

  1. Enter the number of the organization that has a subscription for the Terminal Link module.
    $ lean live "My Project"
    Select the organization with the Terminal Link module subscription:
    1) Organization 1
    2) Organization 2
    3) Organization 3
    Enter an option: 1
  2. Enter the environment to run in. This property must be either Production or Beta.
    $ lean live "My Project"
    Environment (Production, Beta): Production
  3. Enter the host and port of the Bloomberg server.
    $ lean live "My Project"
    Server host: 127.0.0.1
    Server port: 8194
  4. Enter the path to the symbol map file.
    $ lean live "My Project"
    Path to symbol map file: ~/Documents/symbol-map-file.json
    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"
        }*/
    }
    
  5. Enter your EMSX configuration (properties followed by [] can be skipped by pressing enter).
    $ lean live "My Project"
    EMSX broker: someValue
    EMSX user timezone [UTC]:
    EMSX account []:
    EMSX strategy []:
    EMSX notes []:
    EMSX handling []:
  6. Enter whether modification must be allowed.
    $ lean live "My Project"
    Allow modification (yes/no): no
  7. Continue with the next step of the tutorial in the introduction.

Atreyu

Follow these steps after selecting Atreyu as your brokerage in the tutorial in the introduction:

  1. Enter the number of the organization that has a subscription for the Atreyu module.
    $ lean live "My Project"
    Select the organization with the Atreyu module subscription:
    1) Organization 1
    2) Organization 2
    3) Organization 3
    Enter an option: 1
  2. Enter the Atreyu server configuration.
    $ lean live "My Project"
    Host:
    Request port:
    Subscribe port:
  3. Enter your Atreyu credentials.
    $ lean live "My Project"
    Username:
    Password:
    Client id:
  4. Enter the broker MPID to use.
    $ lean live "My Project"
    Broker MPID:
  5. Enter the locate rqd to use.
    $ lean live "My Project"
    Locate rqd:
  6. Continue with the next step of the tutorial in the introduction.

Trading Technologies

Follow these steps after selecting Trading Technologies as your brokerage or data feed in the tutorial in the introduction:

  1. Enter the number of the organization that has a subscription for the Trading Technologies module.
    $ lean live "My Project"
    Select the organization with the Trading Technologies module subscription:
    1) Organization 1
    2) Organization 2
    3) Organization 3
    Enter an option: 1
  2. Enter your Trading Technologies credentials.
    $ lean live "My Project"
    User name: john
    Session password: ****************       
    Account name: jane
  3. Enter the REST configuration.
    $ lean live "My Project"
    REST app key: my-rest-app-key
    REST app secret: ******************
    REST environment: my-environment
  4. Enter the market data configuration.
    $ lean live "My Project"
    Market data sender comp id:
    Market data target comp id:
    Market data host:
    Market data port:
  5. Enter the order routing configuration.
    $ lean live "My Project"
    Order routing sender comp id:
    Order routing target comp id:
    Order routing host:
    Order routing port:
  6. Enter whether FIX messages must be logged.
    $ lean live "My Project"
    Log FIX messages (yes/no): yes
  7. Continue with the next step of the tutorial in the introduction.

IQFeed

Instead of using the data feed from your brokerage, you can also use IQFeed if you're on Windows. Using IQFeed requires you to have an IQFeed developer account and you need to have the IQFeed client installed locally. Follow these steps after selecting IQFeed as your data feed in the tutorial in the introduction:

  1. Enter the path to the IQConnect binary. The default path is C:/Program Files (x86)/DTN/IQFeed/iqconnect.exe if you used the default settings when installing the IQFeed client.
    $ lean live "My Project"
    IQConnect binary location [C:/Program Files (x86)/DTN/IQFeed/iqconnect.exe]:
  2. Enter your IQFeed username and password.
    $ lean live "My Project"
    Username: 123456
    Password: **********
  3. Enter the product id and version of your IQFeed developer account.
    $ lean live "My Project"
    Product id: YOUR_ID
    Product version: 1.0
  4. Continue with the next step of the tutorial in the introduction.

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: