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, CFDs, 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:
- Log in to the IB Client Portal.
- In the top-right corner, click the person icon and then click .
- In the Account Configuration section, click Paper Trading Account.
- Click .
- Click .
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. You can trade the CFD equivalent. 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.
The following table describes the available order types for each asset class that IB supports:
Order Type | US Equity | Equity Options | Forex | Futures | Futures Options | Index Options | CFD |
---|---|---|---|---|---|---|---|
Market | |||||||
Limit | |||||||
Limit if touched | |||||||
Stop market | |||||||
Stopl imit | |||||||
Trailing stop | |||||||
Market on open | |||||||
Market on close | |||||||
Combo market | |||||||
Combo limit | |||||||
Combo leg limit | |||||||
Exercise Option | Not supported for cash-settled Options |
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 methods for FA accounts.
Property | Data Type | Description | Default Value |
---|---|---|---|
TimeInForce time_in_force | A TimeInForce instruction to apply to the order. The following instructions are supported:
| TimeInForce.GoodTilCanceled TimeInForce.GOOD_TIL_CANCELED | |
OutsideRegularTradingHours outside_regular_trading_hours | bool | A 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.
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:
- Open the project you want to deploy.
- Click the Deploy Live icon.
- On the Deploy Live page, click the Brokerage field and then click from the drop-down menu.
- Enter your IB user name, ID, and password. if ($localPlatform) { include(DOCS_RESOURCES."/brokerages/interactive-brokers/paper-trading-data-feeds.html"); } ?>
- 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.
- Click the Node field and then click the live trading node that you want to use from the drop-down menu.
- (Optional) In the Data Provider section, click and change the data provider or add additional providers.
- (Optional) Set up notifications.
- Configure the Automatically restart algorithm setting.
- Click .
- If your IB account has 2FA enabled, tap the notification on your IB Key device and then enter your pin.
Your account details are not saved on QuantConnect.
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.
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.
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.
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.
Troubleshooting
The following table describes errors you may see when deploying to IB:
Error Message(s) | Possible Cause and Fix |
---|---|
The credentials you provided are incorrect. Typically, the password contains leading and/or trailing white spaces. Copy the password to a text editor to ensure the password is correct. If you can't log in to Trader Workstation (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. | |
|
|
IB still recognizes your previous live deployment as being partially connected. It can take a minute to fully disconnect. For more information, see Security and Stability > Connections. | |
|
|
You haven't replied to the two factor authentication requests. The code card authentication is triggered when you don't reply to the IB mobile 2FA requests. 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. | |
Upgrade your plan from IBKR Lite to IBKR Pro. | |
Your algorithm added an invalid security. For example, a deslisted stock, an expired contract, or inexistent contract (invalid expiration date or strike price). If the security should be valid, contact us and provide the algorithm Id and deployment Id. | |
|
|
Your algorithm uses the Interactive Brokers Data Provider, but you don't have a subscription to it. Subscribe to the data bundle you need, contact IB, or re-deploy the algorithm with a different data provider. Try the QuantConnect or the hybrid QuantConnect + Interactive Brokers data providers on QuantConnect Cloud or try a third-party provider. | |
IB didn't repond to an order request. Stop and re-deploy the algorithm. On the next deployment, LEAN retrieves this order or the positions it opened or closed. |
To view the description of less common errors, see Error Codes in the TWS API Documentation. If you need further support, open a new support ticker and add the live deployment with the error.