IB-Matlab User Guide
Version 2.23
November 21, 2024
Fully compatible with:
Windows, Linux, Mac OS
IB TWS versions 962 - 983
MATLAB R2007a - R2024b
© Yair Altman, Octahedron Ltd.
http://UndocumentedMatlab.com/IB-Matlab
Undocumented Matlab
The engineering choice for professional Matlab solutions
Table of Contents
2 Installation and licensing 7
2.1 Licensing and activation 10
2.2 Switching activated computers 11
2.3 Updating the static Java classpath 12
4 Querying account and portfolio data 17
5 Querying current market data 22
5.2 Market depth (Level II) data 28
5.4 Contract details and options chain 35
6 Querying historical and intra-day data 42
7.3 Streaming market depth (Level II) data 58
8.5 Financial Advisor (multi-client) orders 69
8.6 Potential impact of an order (“what-if”) 72
9.1 VWAP (best-effort) orders 73
9.2 TWAP (best-effort) orders 75
9.6 Setting special order attributes 85
9.7 Exercising and lapsing options 88
9.8 Algorithmic trading orders 90
10 Accessing and cancelling open trade orders 93
10.1 Retrieving the list of open orders 93
10.3 Cancelling open orders 97
11.1 Processing events in IB-Matlab 98
11.2 Example – using CallbackExecDetails to track executions 103
11.3 Example – using CallbackTickGeneric to check if a security is shortable 104
11.4 Example – using CallbackContractDetails to get a contract’s full options chain 105
11.5 Example – using CallbackUpdateMktDepth for realtime order-book GUI update 107
12 Tracking trade executions 110
12.3 Using CallbackExecDetails 114
13 TWS connection parameters 115
14 Handling errors, problems, and IB messages 120
14.1 Messages sent from IB 120
14.2 Ambiguous/invalid security errors 124
14.4 Troubleshooting specific problems/errors 130
15 Using the Java connector object 133
15.1 Using the connector object 133
15.2 Programming interface 134
16 Sample strategies/models using IB-Matlab 142
16.2 Using RSI technical indicator 145
17 Frequently-asked questions (FAQ) 150
18.1 Sample program screenshots 155
18.2 About the author (Yair Altman) 158