IB-Matlab is a commercial application that connects Matlab with Interactive-Brokers (IB).
IB-Matlab provides a Matlab interface to the InteractiveBrokers API (Application Programming Interface) connector. This enables quantitative traders and algo traders to easily leverage Matlab’s superior analysis and visualization capabilities, with IB’s no-nonsense low-cost trading platform for stocks, ETFs, mutual funds, bonds, options, futures, commodities and Forex.
While IB’s Java connector, which is provided by IB, can be used directly in Matlab, setting up the event callbacks and data conversions between Matlab and the connector is definitely not easy. You need to be familiar with both Matlab AND Java, at least to some degree.
Other applications that solve these problems are either expensive, limited in functionality or deployment (for example, ActiveX solutions will only work properly on 32-bit Windows systems), or are not supported. matlab2ib quant2ib
IB-Matlab solves the IB-to-Matlab connectivity problem with an easy-to-use Matlab interface that works out-of-the-box on all Matlab platforms (Win32, Win64, Mac, Linux). It outshines the alternatives in terms of performance, features, stability, deployment, cost and overall value.
Main features of IB-Matlab
- Full solution – IB-Matlab is an inexpensive application that enables simple Matlab access to the entire IB API functionality.
- Connectivity – IB-Matlab enables users to connect Matlab to TWS or the IB Gateway, on the Matlab’s computer or on a different computer.
- Stability – IB-Matlab has been installed, tested and used by hundreds of traders since 2010. IB-Matlab is reportedly used to actively trade over $100,000,000 daily (this is not a typo – USD 100 million). It is rock solid.
- Inexpensive – IB-Matlab is extremely inexpensive compared to other connectors of its kind and to the amount of time that would be needed to develop a custom application from scratch. A fully-functional free trial version is available (see below).
- Easy to use – Users can activate IB’s API by simple Matlab commands, without any need to know Java (on which the API is based) nor Matlab programming. IB-Matlab simplifies the IB API in a very easy-to-use yet powerful interface that can be used by any Matlab user, novice or advanced.
- Entire API functionality –
- Active trading actions: buy, sell, short, modify, cancel
- Market query actions: current market data, scanner filter, streaming quotes, real-time bars, historical and intraday data
- Account query actions: account info, portfolio list, open orders, executions data
- IB events: all ~40 asynchronous events that are sent by the IB server are accessible in Matlab (see below)
- Novice and advanced users – IB-Matlab users can use either simple one-line Matlab commands, or internal objects exposed by IB-Matlab, to access the full range of IB’s API.
- Event callbacks – Users can easily attach Matlab code (callbacks) to IB events. For example, this enables special operations (e.g., adding an entry in an Excel file, sending an SMS (text message) or email) whenever an order is fully or partially executed, or a specified price is reached.
- Additional functionality – IB-Matlab also provides functionality that is not readily available in the basic IB API: the ability to specify automated trading; specifying custom trades such as brackets or combo spreads; automatically changing unfulfilled limits based on the momentary bid/ask prices; and changing order types at a certain time.
- Up-to-date – IB-Matlab is up-to-date with the latest IB API (9.69, from April 2013), and the latest IB clients – both the Trading WorkStation (TWS) and the IB Gateway. Other IB installations (past and future) are also generally supported.
- Platforms – IB-Matlab works on all platforms on which Matlab runs: Windows (both 32 and 64 bits), Mac, Linux/Unix.
- Matlab compatibility – IB-Matlab works on Matlab 7.1 and newer, including the very latest Matlab release (currently R2013b). Support for Matlab releases older than 7.1 can be provided upon demand.
- Performance – IB-Matlab is optimized for performance, providing fast and responsive connectivity. While Matlab as a platform is not well-suited for HFT, IB-Matlab still enables placing multiple requests per second, and receiving dozens of streaming quotes or other IB messages per second.
- Security – IB-Matlab does not transmit any information externally except to IB, so your portfolio and trading information are as safe as your own computer.
- Development – IB-Matlab was developed by an acknowledged Matlab expert, who wrote the textbook bible on Matlab-Java interfacing.
- Support – Custom development and ongoing support is available directly from the developer, with extremely fast response times.
- Client base – IB-Matlab is actively used by hundreds of traders, ranging from individual traders, to hedge funds and banks.
- Backtesting – IB-Matlab does not include backtesting functionality, but can easily integrate with either WFAToolbox or TA Developer backtesting and analysis applications, which can be used to develop, test and deploy trading algorithms, all within the Matlab environment.
No other solution provides this rich set of features – not even close. Shop around and see for yourself. In fact, I am so confident that you will not find a better product, that I am happy to help your search: you can start here. When you’re satisfied, come back here to get your free trial. You will not be disappointed.
Free trial version
A fully-functional free trial version is available upon request – please email me and I will be happy to send you a no-obligations copy and to help you install it on your system. There are absolutely no strings attached: the trial is completely free and fully functional, just limited in duration.
In order to use the trial, you need an active IB account. Since the trial is time-limited, it makes sense to ask for the trial only when you have the IB account ready.
- Quick-reference help
- Full User Guide (PDF)
- Syntax details and usage examples
- Real-time trading system demo that uses IB-Matlab, presented at the MATLAB Computational Finance Conference in New York in May 2013, and at the MATLAB Computational Finance Virtual Conference in Sep 2013 (presentation slides, demo source-code, webinar video).
- Two reviews of IB-Matlab were published in the Automated Trader magazine (2011, 2012). The full reviews (PDF) are available for download here (2011, 2012).
- IB’s online API Guide
Pricing and support
The license for a single user on a single computer for the first year costs $349. This includes installation support, fixing bugs, and any fixes that may be required due to IB API changes.
Annual renewal (including license, support and maintenance) for each following year costs $99.
Please email me if you require any of the following:
- A fully-functional free trial version
- Multi-year license
- Perpetual license
- Volume (multi-computer) license
- Deployment (compiled) license
- Development (source-code) license
- Custom development of features
I pride myself on providing top-quality software and support. Customer satisfaction is a top priority for me.
[orderId,ibConnectionObject,contract,order] = IBMatlab(varargin)
Possible inputs parameters:
- varargin = Matlab struct or fieldname/value pairs with the following optional fields:
- Connection: ClientId, Host, Port, AccountName, FAProfile
- Action: one of Buy, Sell, SShort, Query, Cancel, Account, History, Realtime, Scanner, Portfolio or License
- Query type: one of OPEN [for the list of open orders], EXECUTIONS [for the list of today's executions]
- Order type: one of MKT, MKTCLS, LMT, LMTCLS, PEGMKT, STP, STPLMT, MIT, TRAIL, REL, TWAP, VWAP, GuarranteedVWAP, TRAILLIMIT, etc. – see full list here and detailed explanations here; note that IB does not allow some combinations of orders and securities
- Order data: Action, Quantity, TIF, LimitPrice, AuxPrice, OCAGroup, ParentId, TrailStopPrice, GoodAfterTime, GoodTillDate, BracketDelta, BracketTypes, TriggerMethod, OutsideRTH, OrderId, Hold, Timeout
- TWAP/VWAP order data: StrategyType, MaxPctVol, StartTime, EndTime, AllowPastEndTime, NoTakeLiq
- Combo order data: ComboActions, ComboRatios, ComboBagSymbol
- Automated order data: LimitBasis, LimitDelta, LimitRepeatEvery, LimitUpdateMode, LimitChangeTime, LimitChangeType, Tick
- Contract data: Symbol, LocalSymbol, SecType, Exchange, Currency, Expiry, Strike, Right
- Historical data: EndDateTime, DurationValue, DurationUnits, BarSize, WhatToShow, UseRTH, FormatDate (note IB’s pace limitations)
- Streaming quotes data: QuotesNumber, QuotesBufferSize, ReconnectEvery, GenericTickList
- Scanner parameters: Type, ParametersType, AbovePrice, AboveVolume, AverageOptionVolumeAbove, BelowPrice, CouponRateAbove, CouponRateBelow, ExcludeConvertible, Instrument, LocationCode, MarketCapAbove, MarketCapBelow, MaturityDateAbove, MaturityDateBelow, MoodyRatingAbove, MoodyRatingBelow, NumberOfRows, ScanCode, ScannerSettingPairs, SPRatingAbove, SPRatingBelow, StockTypeFilter
- Event callbacks: CallbackFunction, CallbackAccountDownloadEnd, CallbackAccountSummary, CallbackAccountSummaryEnd, CallbackBondContractDetails, CallbackCommissionReport, CallbackConnectionClosed, CallbackContractDetails, CallbackContractDetailsEnd, CallbackCurrentTime, CallbackDeltaNeutralValidation, CallbackExecDetails, CallbackExecDetailsEnd, CallbackFundamentalData, CallbackHistoricalData, CallbackManagedAccounts, CallbackMarketDataType, CallbackMessage, CallbackNextValidId, CallbackOpenOrder, CallbackOpenOrderEnd, CallbackOrderStatus, CallbackPosition, CallbackPositionEnd, CallbackTickPrice, CallbackTickSize, CallbackTickString, CallbackTickGeneric, CallbackTickEFP, CallbackTickOptionComputation, CallbackTickSnapshotEnd, CallbackRealtimeBar, CallbackReceiveFA, CallbackScannerData, CallbackScannerDataEnd, CallbackScannerParameters, CallbackUpdateAccountTime, CallbackUpdateAccountValue, CallbackUpdateMktDepth, CallbackUpdateMktDepthL2, CallbackUpdateNewsBulletin, CallbackUpdatePortfolio
- General: LogFileName, MsgDisplayLevel
- orderId = -1 if unsuccessful, otherwise the ID of the placed order, or data for ‘QUERY’ actions
- ibConnectionObject = reference of Java object that interfaces with IB
- contract = object that holds contract info for Buy/Sell actions when Hold=1 (see example 10 below)
- order = object that holds order info for Buy/Sell actions when Hold=1 (see example 10 below)
Representative usage examples of IB-Matlab are available here. The following examples are available:
- Buy stock
- Sell stock
- Get portfolio data
- Get account data
- Get market data (snapshot) for a particular security
- Get historical data
- Get streaming quotes data
- Specify event callback – ExecDetails
- Specify event callback – TickGeneric
- Using the underlying Java connection object
THIS SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.