{"id":176002,"date":"2021-04-28T19:36:00","date_gmt":"2021-04-28T23:36:00","guid":{"rendered":"https:\/\/ibkrcampus.com\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/"},"modified":"2023-04-25T20:49:09","modified_gmt":"2023-04-26T00:49:09","slug":"activex-in-excel-with-a-tws-sample-spreadsheet","status":"publish","type":"trading-lessons","link":"https:\/\/www.interactivebrokers.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","title":{"rendered":"ActiveX in Excel, with a TWS Sample spreadsheet"},"content":{"rendered":"<p><strong>What is ActiveX?<\/strong><\/p>\n<p>ActiveX is a legacy technology developed by Microsoft, it essentially allows applications to share information with each other. This lesson will cover the basics of ActiveX.<\/p>\n<p>The current <a href=\"https:\/\/interactivebrokers.github.io\/tws-api\/activex.html\" target=\"_blank\" rel=\"noopener\">ActiveX API for Excel<\/a> wraps the C#\/.NET API and is provided as an open source project TWSLib.<\/p>\n<h4><strong>Initial Connection<\/strong><\/h4>\n<p>The initial connection procedure is like other socket-based technologies such as the DDE socket bridge, the python API or Java.<br \/>\nIn TWS, navigate to G<strong>lobal Configuration -&gt; API -&gt; Settings<\/strong> and ensure that &#8220;<strong>Enable ActiveX and Socket Clients<\/strong>&#8221; is selected.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-medium wp-image-4518 lazyload\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/01\/activex-tws.png\" alt=\"\" width=\"840\" height=\"540\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 840px; aspect-ratio: 840\/540;\"><\/p>\n<ul>\n<li>By default, the ActiveX sample connects on port <strong>7496<\/strong>, so let\u2019s make sure this option is selected as well.<\/li>\n<li>Then, navigate to C:TWS APIsamplesExcel and open the ActiveX Sample spreadsheet.<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"half wp-image-4519 size-full aligncenter lazyload\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/activex-in-file-explorer.png\" alt=\"\" width=\"639\" height=\"334\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 639px; aspect-ratio: 639\/334;\"><\/p>\n<ul>\n<li>In the ActiveX sample, the connectivity to TWS via the API is handled in the \u201cGeneral\u201d tab.<\/li>\n<li>As with other socket-based technologies, the host, port, and clientId are required when establishing a connection to TWS<br \/>\nWhen using Excel and TWS on the same machine, leave the Host column blank, as this represents the \u201clocalhost\u201d<\/li>\n<li>The port will be the same port TWS listens on, 7496, by default.<\/li>\n<li>The client ID can be any positive integer and will be used to this specific API connection. See our Connectivity documentation for further details.<\/li>\n<li>Once you review these parameters, click \u201c<strong>Connect to TWS<\/strong>\u201d. If successful, there will be a green \u201cConnected\u201d button displayed.<\/li>\n<li>When you are done using the spreadsheet, to terminate the socket connection by clicking on \u201cDisconnect from TWS\u201d.<\/li>\n<\/ul>\n<h4><strong>Requesting Market Data<\/strong><\/h4>\n<p>Similar to the new DDE spreadsheet, the ActiveX sample consists of a separate tab for each of the different functionalities offered with the API.<br \/>\nThe tickers tab demonstrates how to query watchlist data from TWS. For a more in-depth overview of what is required to request market data in the sample, such as the contract description, we encourage you to review Lesson 3 of the course, as the spreadsheets are similar.<\/p>\n<ul>\n<li>After entering the parameters of the contract click the symbol, for example IBM in row 12.<\/li>\n<li>Then click on \u201c<strong>Request Market Data<\/strong>\u201d.<\/li>\n<li>The quotes for available tick types will begin to populate.<\/li>\n<li>When you want data to stop streaming click the button \u201c<strong>Cancel Market Data<\/strong>\u201d.<\/li>\n<\/ul>\n<h4><strong>Details for programmers<\/strong><\/h4>\n<p>When creating your own custom spreadsheet using the ActiveX API, we would encourage you to review the underlying <strong>VBA code<\/strong> of the sample spreadsheet.<\/p>\n<p><em>Please note, IBKR is not able to provide any programming assistance.<\/em><\/p>\n<p>To view the underlying VBA code, press <strong>Alt-F11<\/strong> to open the VBA Editor.&nbsp; Here the underlying code for the Tickers tab is shown, showing the different subroutines this tab uses to perform requests and return data.&nbsp; See other forms and modules in the VBA project explorer on the left.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.<\/p>\n","protected":false},"author":851,"featured_media":181017,"parent":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"contributors-categories":[13576],"traders-academy":[13125,13128,13132],"class_list":{"0":"post-176002","1":"trading-lessons","2":"type-trading-lessons","3":"status-publish","4":"has-post-thumbnail","6":"contributors-categories-interactive-brokers","7":"traders-academy-beginner-trading","8":"traders-academy-level","9":"traders-academy-trading-lesson"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Archives | Traders&#039; Academy | IBKR Campus<\/title>\n<meta name=\"description\" content=\"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/trading-lessons\/176002\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ActiveX in Excel, with a TWS Sample spreadsheet\" \/>\n<meta property=\"og:description\" content=\"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-26T00:49:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/Thumbnail-ActiveX-in-Excel.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"ActiveX in Excel, with a TWS Sample spreadsheet\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/\",\n\t            \"name\": \"ActiveX in Excel, with a TWS Sample spreadsheet\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/Thumbnail-ActiveX-in-Excel.jpg\",\n\t            \"datePublished\": \"2021-04-28T23:36:00+00:00\",\n\t            \"dateModified\": \"2023-04-26T00:49:09+00:00\",\n\t            \"description\": \"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.\",\n\t            \"breadcrumb\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#breadcrumb\"\n\t            },\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/Thumbnail-ActiveX-in-Excel.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2021\\\/04\\\/Thumbnail-ActiveX-in-Excel.jpg\",\n\t            \"width\": 1280,\n\t            \"height\": 720,\n\t            \"caption\": \"ActiveX in Excel, with a TWS Sample spreadsheet\"\n\t        },\n\t        {\n\t            \"@type\": \"BreadcrumbList\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#breadcrumb\",\n\t            \"itemListElement\": [\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 1,\n\t                    \"name\": \"Academy Lessons\",\n\t                    \"item\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/trading-lessons\\\/\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 2,\n\t                    \"name\": \"ActiveX in Excel, with a TWS Sample spreadsheet\"\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Archives | Traders' Academy | IBKR Campus","description":"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/trading-lessons\/176002\/","og_locale":"en_US","og_type":"article","og_title":"ActiveX in Excel, with a TWS Sample spreadsheet","og_description":"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","og_site_name":"IBKR Campus US","article_modified_time":"2023-04-26T00:49:09+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/Thumbnail-ActiveX-in-Excel.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_title":"ActiveX in Excel, with a TWS Sample spreadsheet","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","url":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","name":"ActiveX in Excel, with a TWS Sample spreadsheet","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#primaryimage"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/Thumbnail-ActiveX-in-Excel.jpg","datePublished":"2021-04-28T23:36:00+00:00","dateModified":"2023-04-26T00:49:09+00:00","description":"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.","breadcrumb":{"@id":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/Thumbnail-ActiveX-in-Excel.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2021\/04\/Thumbnail-ActiveX-in-Excel.jpg","width":1280,"height":720,"caption":"ActiveX in Excel, with a TWS Sample spreadsheet"},{"@type":"BreadcrumbList","@id":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Academy Lessons","item":"https:\/\/ibkrcampus.com\/campus\/trading-lessons\/"},{"@type":"ListItem","position":2,"name":"ActiveX in Excel, with a TWS Sample spreadsheet"}]},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"}]}},"_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/trading-lessons\/176002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/trading-lessons"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/trading-lessons"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/851"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=176002"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/trading-lessons\/176002\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/181017"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=176002"}],"wp:term":[{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=176002"},{"taxonomy":"traders-academy","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/traders-academy?post=176002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}