SkillAgentSearch skills...

Lean.Brokerages.InteractiveBrokers

InteractiveBrokers Brokerage Plugin

Install / Use

/learn @QuantConnect/Lean.Brokerages.InteractiveBrokers
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

header-cheetah

     

Introduction

This repository hosts the Interactive Brokers (IB) Brokerage Plugin Integration with the QuantConnect LEAN Algorithmic Trading Engine. LEAN is a brokerage agnostic operating system for quantitative finance. Thanks to open-source plugins such as this LEAN can route strategies to almost any market.

LEAN is maintained primarily by QuantConnect, a US based technology company hosting a cloud algorithmic trading platform. QuantConnect has successfully hosted more than 200,000 live algorithms since 2015, and trades more than $1B volume per month.

About Interactive Brokers

<p align="center"> <picture > <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/79997186/188234310-4d3cf2e5-4a88-4f8b-abaf-1f4c8f5ae71e.png"> <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/79997186/188234305-1924c76a-86c1-46cf-b9bf-b29f8449e97e.png"> <img alt="introduction" width="40%"> </picture> <p>

IB was founded by Thomas Peterffy in 1993 with the goal to "create technology to provide liquidity on better terms. Compete on price, speed, size, diversity of global products and advanced trading tools". IB provides access to trading Equities, ETFs, Options, Futures, Future Options, Forex, Gold, Warrants, Bonds, and Mutual Funds for clients in over 200 countries and territories with no minimum deposit. IB also provides paper trading, a trading platform, and educational services.

For more information about the IB brokerage, see the QuantConnect-IB Integration Page.

Using the Brokerage Plugin

Deploying IB with VSCode User Interace

You can deploy using a visual interface in the QuantConnect cloud. For instructions, see the QuantConnect-IB Integration Page.

deploy-ib

In the QuantConnect Cloud Platform, you can harness the QuantConnect Live Data Feed, the IB Live Data Feed, or both. For most users, this is substantially cheaper and easier than self-hosting.

Deploying IB with LEAN CLI

Follow these steps to start local live trading with the IB 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 IB 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 IB username, account id, and password.

    $ lean live "My Project"
    Username: trader777
    Account id: DU1234567
    Account password: ****************
    
  6. 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.:
    

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

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

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

Account Types

The IB API does not support the IBKR LITE plan. You need an IBKR PRO plan. Individual and Financial Advisor (FA) accounts are available. IB supports cash and margin accounts.

Order Types and Asset Classes

The following table describes the order types that IB supports. For specific details about each order type, refer to the IB documentation.

| Order Type | IB Documentation Page | | ----------- | ----------- | | MarketOrder | Market Orders | | LimitOrder | Limit Orders | | LimitIfTouchedOrder | Limit if Touched Orders | | StopMarketOrder | Stop Orders | | StopLimitOrder | Stop-Limit Orders | | TrailingStopOrder | Trailing Stop Orders | | MarketOnOpenOrder | Market-on-Open (MOO) Orders | | MarketOnCloseOrder | Market-on-Close (MOC) Orders | | ExerciseOption | Options Exercise |

Downloading Data

For local deployment, the algorithm needs to download the following datasets:

Brokerage Model

Lean models the brokerage behavior for backtesting purposes. The margin model is used in live trading to avoid placing orders that will be rejected due to insufficient buying power.

You can set the Brokerage Model with the following statements

SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash);
SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);

Read Documentation

Fees

We model the order fees of IB for each asset class. For information about each asset class, see Fees.

Margin

We model buying power and margin calls to ensure your algorithm stays within the margin requirements.

Read Documentation

Buying Power

In the US, IB allows up to 2x leverage on Equity trades for margin accounts. In other countries, IB may offer different amounts of leverage. To figure out how much leverage you can access, check with your local legislation or contact an IB representative. We model the US version of IB leverage by default.

Margin Calls

Regulation T margin rules apply. When the amount of margin remaining in your portfolio drops below 5% of the total portfolio value, you receive a warning. When the amount of margin remaining in your portfolio drops to zero or goes negative, the portfolio sorts the generate

View on GitHub
GitHub Stars64
CategoryDevelopment
Updated3d ago
Forks52

Languages

C#

Security Score

95/100

Audited on Mar 29, 2026

No findings