Brokerages

Interactive Brokers

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. The Lean CLI also supports starting live trading for a cloud project on any of the brokerages supported in the cloud. We recommend live trading your projects in our cloud because we provide a battle-tested, colocated infrastructure racked in Equinix, maintained by our engineers to ensure the best possible stability and uptime. This page contains instructions on how to start live trading with the Interactive Brokers brokerage.

To view the implementation of the IB brokerage integration, see the Lean.Brokerages.InteractiveBrokers repository.

Deploy Local Algorithms

Follow these steps to start local live trading with the Interactive Brokers brokerage:

  1. Open a terminal in your CLI root directory.
  2. Run lean live "<projectName>" to start a live deployment wizard for the project in ./<projectName> and then enter the brokerage number.
    $ 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) Samco
    10) Terminal Link
    11) Atreyu
    12) Trading Technologies
    13) Kraken
    14) FTX 
    Enter an option: 
  3. Enter the number of the organization that has a subscription for the Interactive Brokers module.
    $ lean live "My Project"
    Select the organization with the Interactive Brokers module subscription:
    1) Organization 1
    2) Organization 2
    3) Organization 3
    Enter an option: 1
  4. Set up IB Key Security via IBKR Mobile. For instructions, see IB Key Security via IBKR Mobile on the IB website.
  5. 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: ****************
  6. Enter whether you want to enable delayed market data.
    $ lean live "My Project"
    Enable delayed market data? [yes/no]: 
    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.
  7. Enter the number of the data feed to use and then follow the steps required for the data connection.
    $ lean live "My Project"
    Select a data feed:
    1) Interactive Brokers
    2) Tradier
    3) Oanda
    4) Bitfinex
    5) Coinbase Pro
    6) Binance
    7) Zerodha
    8) Samco
    9) Terminal Link
    10) Trading Technologies
    11) Kraken
    12) FTX
    13) IQFeed
    14) Polygon Data Feed
    15) Custom data only
    To enter multiple options, separate them with comma.:
  8. If you select IQFeed, see IQFeed for set up instructions.

    If you select Polygon Data Feed, see Polygon for set up instructions.

  9. View the result in the <projectName>/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.

Deploy Cloud Algorithms

Follow these steps to start live trading a project in the cloud with the Interactive Brokers brokerage:

  1. Log in to the CLI if you haven't done so already.
  2. Open a terminal in your CLI root directory.
  3. Run lean cloud live "<projectName>" --push --open to push ./<projectName>. to the cloud, start a live deployment wizard, and open the results in the browser once the deployment starts.
    $ lean cloud live "My Project" --push --open
    [1/1] Pushing 'My Project'
    Successfully updated cloud file 'My Project/main.py'
    Started compiling project 'My Project'
    Successfully compiled project '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) Samco
    10) Kraken
    11) FTX
    Enter an option:
  4. Enter the number of the Interactive Brokers brokerage.
  5. Set up IB Key Security via IBKR Mobile. For instructions, see IB Key Security via IBKR Mobile on the IB website.
  6. Go back to the terminal and enter your Interactive Brokers username, account id, and password.
    $ lean cloud live "My Project" --push --open
    Username: trader777
    Account id: DU1234567
    Account password: ****************
  7. Enter whether you want to use the price data feed from Interactive Brokers instead of the one from QuantConnect. Enabling this feature requires you to have active Interactive Brokers market data subscriptions for all data required by your algorithm.
    $ lean cloud live "My Project" --push --open
    Do you want to use the Interactive Brokers price data feed instead of the QuantConnect price data feed? (yes/no): y
  8. Select the live node that you want to use. If you only have one idle live trading node, it is selected automatically and this step is skipped.
    $ lean cloud live "My Project" --push --open
    Select a node:
    1) L-MICRO node 89c90172 - 1 CPU @ 2.4GHz, 0.5GB Ram
    2) L-MICRO node 85a52135 - 1 CPU @ 2.4GHz, 0.5GB Ram
    Enter an option: 1
  9. Configure your notification settings. You can configure any combination of email, webhook, SMS, and Telegram notifications for order events and emitted insights.
    $ lean cloud live "My Project" --push --open
    Do you want to send notifications on order events? [y/N]: y
    Do you want to send notifications on insights? [y/N]: y
    Email notifications: None
    Webhook notifications: None
    SMS notifications: None
    Select a notification method:
    1) Email
    2) Webhook
    3) SMS
    4) Telegram
    Enter an option: 1
    Email address: john.doe@example.com
    Subject: Algorithm notification
    Email notifications: john.doe@example.com
    Webhook notifications: None
    SMS notifications: None
    Telegram notifications: None
    Do you want to add another notification method? [y/N]: n
  10. Enable or disable automatic algorithm restarting. This feature attempts to restart your algorithm if it fails due to a runtime error, like a brokerage API disconnection.
    $ lean cloud live "My Project" --push --open
    Do you want to enable automatic algorithm restarting? [Y/n]: y
  11. Verify the configured settings and confirm them to start the live deployment in the cloud.
    $ lean cloud live "My Project" --push --open
    Brokerage: Interactive Brokers
    Project id: 1234567
    Environment: Live
    Server name: L-MICRO node 89c90172
    Server type: L-MICRO
    Data provider: QuantConnect
    LEAN version: 11157
    Order event notifications: Yes
    Insight notifications: Yes
    Email notifications: john.doe@example.com
    Webhook notifications: None
    SMS notifications: None
    Telegram notifications: None
    Automatic algorithm restarting: Yes
    Are you sure you want to start live trading for project 'My Project'? [y/N]: y
  12. Inspect the result in the browser, which opens automatically after the deployment starts.

Follow these steps to see the live status of a project:

  1. Log in to the CLI if you haven't done so already.
  2. Open a terminal in your CLI root directory.
  3. Run lean cloud status "<projectName>" to show the status of the cloud project named "<projectName>".
    $ lean cloud status "My Project"
    Project id: 1234567
    Project name: My Project
    Project url: https://www.quantconnect.com/project/1234567
    Live status: Running
    Live id: L-1234567a8901d234e5e678ddd9b0123c
    Live url: https://www.quantconnect.com/project/1234567/live
    Brokerage: Paper Trading
    Launched: 2021-06-09 15:10:12 UTC

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: