Before we begin, there are some prerequisites the TWS API requires. For example, if are looking to use our excel APIs, you would need Java and a Windows copy of Microsoft Excel installed.
Overview of the TWS API
The Interactive Brokers’ TWS APIs allows other applications and programs to work with the Trader Workstation (TWS) or IB Gateway. Trader Workstation is our flagship trading platform and IB Gateway is the lightweight version without any of the manual trading features.
In this course, we will cover connecting Microsoft Excel to TWS so we can retrieve market data, place orders, view account and portfolio data and much more! We’ll explore a sample spreadsheet that has been created by IBKR to highlight the functionality of the Excel TWS API. You can reference the sample spreadsheet as we show you examples in this course. We’ll also cover making an API request, such as retrieving market data, using a blank Excel spreadsheet. This way you’ll know how to connect your existing spreadsheet with TWS.
Let’s briefly cover the TWS API a bit more in depth, and its capabilities.
Downloading and installing TWS
Before we get started, make sure you have TWS or IB Gateway installed, If you don’t, you can head over to our website, ibkr.com, select “Log In” in the upper right hand corner of the page and from the drop down menu, select Trader Workstation or API: IB Gateway.
They can also be found on our main website, under the menu Trading, then Platforms.
In addition, there are some prerequisites the TWS API requires. For example, if are looking to use our excel APIs, you would need Java and a Windows copy of Microsoft Excel installed.
The latest version of our Excel APIs are supported with both 32-bit and 64-bit Operating Systems. However, they are not compatible with the Mac Operating System. Our website will automatically provide a download version but you may choose a different version if you’d like.
Installing the TWS API
To obtain all the components required to use the Excel APIs, including sample sheets and source code, on our website, you may navigate to ibkr.com and access the menus at the top and select Trading > APIs and select Download and Resources.
Our APIs are provided with a Non-Commercial license agreement. You may download either the stable or latest version.
Note, the Excel APIs are only supported for the windows operating system. The most up-to-date version of Interactive Brokers API source code is hosted on Github as a private repository. We refer to this as our “beta client” although it doesn’t use formal release numbers as do our “Latest” and “Stable” API versions.
This code is frequently updated with new features and functionality, and periodically the API source code in this private repository is published as a new version of API Latest. Users can gain access to the Github repository to view the current Beta API source code as well as to contribute suggestions and source code.
Our goal in allowing our users to contribute is to improve the reliability and versatility of the API for everyone. Review this page if you’d like to access and contribute to the API Beta version.
After successfully installing, you will find the API samples and components installed on the same drive as the operating system which is usually the c drive.
- Here you’ll see the folders samples, source, source, and tests.
- The source folder contains the necessary files to create your own API application, and in essence define the available messages the API can send and receive.
- In this course, we will discuss the content from the samples folder, which contains the sample spreadsheets for DDE, ActiveX, and RTD inside the “Excel” folder.
- The DdeSocketBridge folder inside samples contains the batch file necessary to run the new DDE sample. We’ll cover this more later. Also note, the tests folder contains the library TwsLib.dll , which is used by the ActiveX sample.
Configuring TWS Settings for API
TWS is required to be open on your computer to integrate with Excel. Just double click on the Trader Workstation desktop icon to launch and log into TWS.
Now that TWS is running, let’s enable the API functionality. Go to the menu at the top of TWS and select Edit > Global Configuration > API > Settings, and then check the box on the left Enable ActiveX and Socket Clients.
By default, the sample sheet that we’ll use port 7496 so you’ll see that set here. When done click on Apply and then click on Ok.
Now that we have TWS configured, the next video in this course will go over using Excel RTD, which stands for real time data. Hope you can join us!
Disclosure: Interactive Brokers
The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
Supporting documentation for any claims and statistical information will be provided upon request.
Any stock, options or futures symbols displayed are for illustrative purposes only and are not intended to portray recommendations.
Disclosure: API Examples Discussed
Throughout the lesson, please keep in mind that the examples discussed are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.