2001 Interactive Brokers LLC. All Rights Reserved.

Transcription

2001 Interactive Brokers LLC. All rights reserved.Sun, Sun Microsystems, the Sun Logo and Java are trademarks or registeredtrademarks of Sun Microsystems, Inc. in the United States and other countries.Excel, Windows and Visual Basic (VB) are trademarks or registered trademarksof the Microsoft Corporation in the United States and/or in other countries.Any symbols displayed within these pages are for illustrative purposes only, andare not intended to portray any recommendation.

Table of ContentsIntroduction . 10How to Use this Guide . 11Organization . 11Part I: Introducing the Excel API. 11Part II: Preparing to Use the Excel API . 11Part III: Getting to Know the Excel API Spreadsheet . 11Part IV: Creating Your Own API Application. 12Part V: Where to Go from Here . 12Footnotes and References . 12Icons . 13Part I: Introducing the Excel API. 14Chapter 1 - What is TWS? . 15What Can You Do with TWS? . 16A Quick Look at TWS . 16Chapter 2 - Why Would I Use an API? . 18An Example . 19Another Example . 19Why Use the Excel API? . 21Part II: Preparing to Use the Excel API . 22Chapter 3 - Enable TWS to Support the API . 23Enable TWS to Support the API . 23Chapter 4 - Download the API Software . 24Chapter 5 – Using the Sample Excel API Application . 27www.interactivebrokers.com3

Part III: Getting to Know the Excel API Spreadsheet . 29Chapter 6 - Introducing the Excel Pages. 30The Pages . 31Common Action Buttons . 32Chapter 7 - The Tickers Page. 34Define a Ticker . 34Request Market Data. 35Create a Group Combination Strategy . 36Chapter 8 - The Orders Page . 37Add Your Tickers to the Orders Page . 38Create an Order . 38Order Types . 39Order Status Fields . 40Chapter 9 - The Extended Order Attributes Page . 41An Example . 42Extended Order Attributes . 42Chapter 10: The Conditional Orders Page . 44Set Up a Conditional Order. 45Chapter 11 – The Open Orders Page . 47How Do I Subscribe? . 47Clearing Open Orders . 47Named Ranges for Results . 48View the VB Code . 48What Happens If an Open Order Executes? . 494www.interactivebrokers.com

Chapter 12 – The Executions Page . 50How Do I Subscribe to Executions? . 50Clearing Executions . 50Named Ranges for Results . 51View the VB Code . 51The Executions Reporting Page . 52Chapter 13 – The Account Page . 53How Do I Subscribe to Account Updates? . 53Clearing Account Values . 54Named Ranges for Results . 54View the VB Code . 54Chapter 14 – The Portfolio Page . 56Chapter 15 – The Historical Data Page. 57How Do I Request Historical Data?. 58Historical Data Parameters . 58Canceling Historical Data Requests. 61Chapter 16 - The Market Scanner Page . 63How Do I Subscribe to a Market Scanner? . 64Elements of a Market Data Scan . 64Available Market Scanners . 66Viewing Market Scanner Results. 67Deleting Market Scanner Results. 68Cancelling a Scanner Subscription . 68Chapter 17 - The Contract Details and Bond Contract Details Pages . 69www.interactivebrokers.com5

Contract Details Page. 69Expired Options . 69Bond Contract Details Page . 70Using Contract Details on Other Pages . 71Chapter 18 – The Market Depth Page. 72View More Than Ten Rows of Market Depth . 72Cancelling a Market Depth Request . 73Chapter 19 – The Old Style Executions and Account-Portfolio Pages . 74Old Style Executions. 74Old Style Account-Portfolio . 74Part IV: Creating Your Own API Application. 75Chapter 20 – Download the Samples . 76Chapter 21 - Using VBA to Customize the API . 77Using the Visual Basic Editor (VBE) . 77Looking at the Visual Basic Editor . 78Create and Save a VBA Macro . 79Run the Macro. 81Look at the Code . 81Chapter 22 - Sample Applications for the API . 84Samples Overview . 84Download the Samples . 85Example 1 : Sell based on P & L . 85Modify the P&L Trigger Value . 86Limit the Sample to a Specific Stock . 866www.interactivebrokers.com

Enable or Start the Subroutine . 86Code Summary. 87New Worksheet(s) . 87Example 2 : Buy/Sell based on Top Implied Volatility Gainer Market ScanResults . 87How Does the Sample Work? . 88Enable or Start the Subroutine . 89Code Summary. 89New Worksheet(s): . 89Example 3 : Export Daily Executions . 90How Does the Sample Work? . 90Run the Macro. 91Code Summary. 91New Worksheet(s): . 91Example 4 : Create DDE “OptionTrader” . 92How Does the Sample Work? . 92Code Summary. 93New Worksheet(s): . 93Example 5: Currency Converter . 93How Does the Sample Work? . 94Code Summary. 94Modified Worksheet(s): . 94Part V: Where to Go from Here . 95Chapter 23 – Additional Resources . 96Help with Visual Basic for Applications Programming . 96www.interactivebrokers.com7

Help with the TWS API . 97The API Users’ Guide . 97The API Beta and API Production Release Notes . 97The API Highlights . 97The TWS API Tour. 98The TWS API Webinar . 98API Customer Forums . 98IB Customer Service . 98IB Features Poll. 99Chapter 24 – The Excel API for Advisors . 100Sett

your trading), how to navigate the Interactive Brokers website to find support and information, where to find some helpful resources outside the realm of IB support, (such as Visual Basic and other programming help), and how to find answers to Excel-specific questions. Footnotes and References 1Any symbols displayed are for illustrative purposes only and are not intended to portray a .