{"id":10384,"date":"2021-04-28T19:36:00","date_gmt":"2021-04-28T23:36:00","guid":{"rendered":"https:\/\/ibkrcampus.eu\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/"},"modified":"2024-02-13T20:38:02","modified_gmt":"2024-02-13T20:38:02","slug":"activex-in-excel-with-a-tws-sample-spreadsheet","status":"publish","type":"trading-lessons","link":"https:\/\/www.interactivebrokers.eu\/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\/3\/2024\/02\/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":850,"featured_media":10385,"parent":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"contributors-categories":[149],"traders-academy":[100,103,105],"class_list":["post-10384","trading-lessons","type-trading-lessons","status-publish","has-post-thumbnail","contributors-categories-interactive-brokers","traders-academy-beginner-trading","traders-academy-level","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 v28.4) - 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\/10384\/\" \/>\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.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus EU\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-13T20:38:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2024\/02\/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:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/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.eu\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2024\\\/02\\\/Thumbnail-ActiveX-in-Excel.jpg\",\n\t            \"datePublished\": \"2021-04-28T23:36:00+00:00\",\n\t            \"dateModified\": \"2024-02-13T20:38:02+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:\\\/\\\/www.interactivebrokers.eu\\\/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:\\\/\\\/www.interactivebrokers.eu\\\/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:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/activex-in-excel-with-a-tws-sample-spreadsheet\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2024\\\/02\\\/Thumbnail-ActiveX-in-Excel.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/3\\\/2024\\\/02\\\/Thumbnail-ActiveX-in-Excel.jpg\",\n\t            \"width\": 1280,\n\t            \"height\": 720,\n\t            \"caption\": \"charts on monitor screen\"\n\t        },\n\t        {\n\t            \"@type\": \"BreadcrumbList\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/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\": \"Home\",\n\t                    \"item\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 2,\n\t                    \"name\": \"Academy Lessons\",\n\t                    \"item\": \"https:\\\/\\\/www.interactivebrokers.eu\\\/campus\\\/trading-lessons\\\/\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 3,\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.eu\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.eu\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus EU\",\n\t            \"description\": \"\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.eu\\\/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}<\/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\/10384\/","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.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","og_site_name":"IBKR Campus EU","article_modified_time":"2024-02-13T20:38:02+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2024\/02\/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:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","url":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/","name":"ActiveX in Excel, with a TWS Sample spreadsheet","isPartOf":{"@id":"https:\/\/ibkrcampus.eu\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2024\/02\/Thumbnail-ActiveX-in-Excel.jpg","datePublished":"2021-04-28T23:36:00+00:00","dateModified":"2024-02-13T20:38:02+00:00","description":"We will cover the basics of using ActiveX controls in Excel to gather and share information with TWS.","breadcrumb":{"@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#primaryimage","url":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2024\/02\/Thumbnail-ActiveX-in-Excel.jpg","contentUrl":"https:\/\/www.interactivebrokers.eu\/campus\/wp-content\/uploads\/sites\/3\/2024\/02\/Thumbnail-ActiveX-in-Excel.jpg","width":1280,"height":720,"caption":"charts on monitor screen"},{"@type":"BreadcrumbList","@id":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/activex-in-excel-with-a-tws-sample-spreadsheet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.interactivebrokers.eu\/campus\/"},{"@type":"ListItem","position":2,"name":"Academy Lessons","item":"https:\/\/www.interactivebrokers.eu\/campus\/trading-lessons\/"},{"@type":"ListItem","position":3,"name":"ActiveX in Excel, with a TWS Sample spreadsheet"}]},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.eu\/campus\/#website","url":"https:\/\/ibkrcampus.eu\/campus\/","name":"IBKR Campus EU","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.eu\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/trading-lessons\/10384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/trading-lessons"}],"about":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/types\/trading-lessons"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/users\/850"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/comments?post=10384"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/trading-lessons\/10384\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/media\/10385"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/media?parent=10384"}],"wp:term":[{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/contributors-categories?post=10384"},{"taxonomy":"traders-academy","embeddable":true,"href":"https:\/\/ibkrcampus.eu\/campus\/wp-json\/wp\/v2\/traders-academy?post=10384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}