Brokerages

Interactive Brokers

Introduction

QuantConnect enables you to run your algorithms in live mode with real-time market data. We have successfully hosted more than 200,000 live algorithms and have had more than $22B in volume traded on our servers since 2015.

Interactive Brokers (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.

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

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.

Individual Accounts

IB supports cash and margin accounts. To set the account type in an algorithm, see the IB brokerage model documentation.

FA Accounts

IB supports FA accounts for Trading Firm and Institution organizations. FA accounts enable certified professionals to use a single trading algorithm to manage several client accounts. If your account code starts with F, FA, or I, then you have an FA account. For more information about FA accounts, see Financial Advisors.

Create an Account

You need to open an IBKR Pro account to deploy algorithms with IB. The IB API does not support IBKR Lite accounts. To create an IB account, see the Open an Account page on the IB website.

You need to activate IBKR Mobile Authentication (IB Key) to deploy live algorithms with your brokerage account. After you open your account, follow the installation and activation instructions on the IB website.

Paper Trading

IB supports paper trading. Follow the Opening a Paper Trading Account page in the IB documentation to set up your paper trading account.

If you want to use IB market data and trade with your paper trading account, follow these steps:

  1. Log in to the IB Client Portal.
  2. In the top-right corner, click the person icon and then click Settings.
  3. In the Account Configuration section, click Paper Trading Account.
  4. Click Yes.
  5. Click Save.

The IB paper trading environment simulates most aspects of a production Trader Workstation account, but you may encounter some differences due to its construction as a simulator with no execution or clearing abilities.

Insured Bank Deposit Sweep Program

LEAN doesn't support IB accounts in the Insured Bank Deposit Sweep Program because when LEAN reads your account balances, it includes cash that's in the FDIC Sweep Account Cash, which isn't tradable. For example, if your account has $150K USD of cash, only $100K may be available to trade if $50K is in FDIC Sweep Account Cash.

Asset Classes

Our Interactive Brokers integration supports the following asset classes:

You may not be able to trade all assets with IB. For example, if you live in the EU, you can't trade US ETFs. Check with your local regulators to know which assets you are allowed to trade. You may need to adjust settings in your brokerage account to live trade some assets.

Data Providers

You might need to purchase an IB market data subscription for your trading. For more information about live data providers, see Datasets.

Orders

We model the IB API by supporting several order types, order properties, and order updates. When you deploy live algorithms, you can place manual orders through the IDE.

Order Types

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

Order TypeIB Documentation Page
MarketOrderMarket Orders
LimitOrderLimit Orders
LimitIfTouchedOrderLimit if Touched Orders
StopMarketOrderStop Orders
StopLimitOrderStop-Limit Orders
TrailingStopOrderTrailing Stop Orders
MarketOnOpenOrderMarket-on-Open (MOO) Orders
MarketOnCloseOrderMarket-on-Close (MOC) Orders
ComboMarketOrderSpread Orders
ComboLimitOrderSpread Orders
ComboLegLimitOrderSpread Orders
ExerciseOptionOptions Exercise

The following table describes the available order types for each asset class that IB supports:

Order TypeUS EquityEquity OptionsForexFuturesFutures OptionsIndex Options
MarketOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
LimitOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
LimitIfTouchedOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
StopMarketOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
StopLimitOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
TrailingStopOrdergreen checkgreen checkgreen checkgreen checkgreen checkgreen check
MarketOnOpenOrdergreen checkgreen checkgreen checkgreen check
MarketOnCloseOrdergreen checkgreen checkgreen checkgreen checkgreen check
ComboMarketOrdergreen checkgreen checkgreen check
ComboLimitOrdergreen checkgreen checkgreen check
ComboLegLimitOrdergreen checkgreen checkgreen check
ExerciseOptiongreen check
Not supported for cash-settled Options
green check

Order Properties

We model custom order properties from the IB API. The following table describes the members of the InteractiveBrokersOrderProperties object that you can set to customize order execution. The table does not include the preceding methods for FA accounts.

PropertyDescription
TimeInForceA TimeInForce instruction to apply to the order. The following instructions are supported:
  • Day
  • GoodTilCanceled
  • GoodTilDate
OutsideRegularTradingHoursA flag to signal that the order may be triggered and filled outside of regular trading hours.

Updates

We model the IB API by supporting order updates.

Financial Advisor Group Orders

To place FA group orders, see Financial Advisors.

Fractional Trading

The IB API and FIX/CTCI don't support fractional trading.

Handling Splits

If you're using raw data normalization and you have active orders with a limit, stop, or trigger price in the market for a US Equity when a stock split occurs, the following properties of your orders automatically adjust to reflect the stock split:

  • Quantity
  • Limit price
  • Stop price
  • Trigger price

Fill Time

IB has a 400 millisecond fill time for live orders.

Brokerage Liquidations

When IB liquidates part of your position, you receive an order event that contains the Brokerage Liquidation message.

Fees

To view the IB trading fees, see the Commissions page on the IB website. To view how we model their fees, see Fees.

Margin

We model buying power and margin calls to ensure your algorithm stays within the margin requirements. If you have more than $25,000 in your brokerage account, you can use the PatternDayTradingMarginModel to make use of the 4x intraday leverage and 2x overnight leverage available on most brokerages from the PDT rule.

Slippage

Orders through IB do not experience slippage in backtests. In paper trading and live trading, your orders may experience slippage.

To view how we model IB slippage, see Slippage.

Fills

We fill market orders immediately and completely in backtests. In live trading, if the quantity of your market orders exceeds the quantity available at the top of the order book, your orders are filled according to what is available in the order book.

To view how we model IB order fills, see Fills.

Settlements

If you trade with a margin account, trades settle immediately

To view how we model settlement for IB trades, see Settlement.

Security and Stability

Note the following security and stability aspects of our IB integration.

Account Credentials

When you deploy live algorithms with IB, we don't save your brokerage account credentials.

API Outages

We call the IB API to place live trades. Sometimes the API may be down. Check the IB status page to see if the API is currently working.

Connections

By default, IB only supports one connection at a time to your account. If you interfere with your brokerage account while an algorithm is connected to it, the algorithm may stop executing. If you deploy a live running algorithm with your IB account and want to open Trader Workstation (TWS) with the same IB account, create a second user on your IB account and log in to TWS with the new user credentials. To run more than one algorithm with IB, open an IB subaccount for each additional algorithm.

If you can't log in to TWS with your credentials, contact IB. If you can log in to TWS but can't log in to the deployment wizard, contact us and provide the algorithm ID and deployment ID.

SMS 2FA

Our IB integration doesn't support Two-Factor Authentication (2FA) via SMS or the Online Security Code Card. Use the IB Key Security via IBKR Mobile instead.

System Resets

You'll receive a notification on your IB Key device every Sunday to re-authenticate the connection between IB and your live algorithm. When you deploy your algorithm, you can select a time on Sunday to receive the notification. If you don't re-authenticate before the timeout period, your algorithm quits executing. Ensure your IB Key device has sufficient battery for the time you expect to receive the notification. If you don't receive a notification, see I am not receiving IBKR Mobile notifications on the IB website.

Deposits and Withdraws

You can deposit and withdraw cash from your brokerage account while you run an algorithm that's connected to the account. We sync the algorithm's cash holdings with the cash holdings in your brokerage account every day at 7:45 AM Eastern Time (ET).

Demo Algorithm

The following algorithm demonstrates the functionality of the IB brokerage:

Deploy Live Algorithms

You must have an available live trading node for each live trading algorithm you deploy.

Follow these steps to deploy a live algorithm:

  1. Open the project you want to deploy.
  2. Click the Lightning icon Deploy Live icon.
  3. On the Deploy Live page, click the Brokerage field and then click Interactive Brokers from the drop-down menu.
  4. Enter your IB user name, ID, and password.
  5. Your account details are not saved on QuantConnect.

  6. In the Weekly Restart UTC field, enter the Coordinated Universal Time (UTC) time of when you want to receive notifications on Sundays to re-authenticate your account connection.
  7. For example, 4 PM UTC is equivalent to 11 AM Eastern Standard Time, 12 PM Eastern Daylight Time, 8 AM Pacific Standard Time, and 9 AM Pacific Daylight Time. To convert from UTC to a different time zone, see the UTC Time Zone Converter on the UTC Time website.

    If your IB account has 2FA enabled, you receive a notification on your IB Key device every Sunday to re-authenticate the connection between IB and your live algorithm. If you don't re-authenticate before the timeout period, your algorithm quits executing.

  8. Click the Node field and then click the live trading node that you want to use from the drop-down menu.
  9. (Optional) In the Data Provider section, click Show and change the data provider or add additional providers.
  10. In most cases, we suggest using both the QC and IB data providers.

    If you use IB data provider and trade with a paper trading account, you need to share the market data subscription with your paper trading account. For instructions on sharing market data subscription, see Account Types.

  11. (Optional) Set up notifications.
  12. Configure the Automatically restart algorithm setting.
  13. By enabling automatic restarts, the algorithm will use best efforts to restart the algorithm if it fails due to a runtime error. This can help improve the algorithm's resilience to temporary outages such as a brokerage API disconnection.

  14. Click Deploy.
  15. If your IB account has 2FA enabled, tap the notification on your IB Key device and then enter your pin.

The deployment process can take up to 5 minutes. When the algorithm deploys, the live results page displays. If you know your brokerage positions before you deployed, you can verify they have been loaded properly by checking your equity value in the runtime statistics, your cashbook holdings, and your position holdings.

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: