{"id":203269,"date":"2024-03-12T12:39:32","date_gmt":"2024-03-12T16:39:32","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=203269"},"modified":"2024-03-21T10:05:51","modified_gmt":"2024-03-21T14:05:51","slug":"getting-started-with-the-interactive-brokers-native-api","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/","title":{"rendered":"Getting Started with the Interactive Brokers Native API"},"content":{"rendered":"\n<p><em>The article &#8220;Getting Started with the Interactive Brokers Native API&#8221; first appeared on <a href=\"https:\/\/robotwealth.com\/getting-started-with-the-interactive-brokers-native-api\/\">Robot Wealth<\/a> blog.<\/em><\/p>\n\n\n\n<p>Here at Robot Wealth, we trade with Interactive Brokers (IB) primarily because they offer access to global markets at a reasonable price.<\/p>\n\n\n\n<p>In recent times, IB has put some time and effort into upping its tech game, including development of an API for interacting with its desktop trading applications.<\/p>\n\n\n\n<p>An application that interacts with IB\u2019s desktop trading applications via the API is essentially a message-handling program. So I want to show you a simple but effective architecture for managing the flow of messages and the operations they trigger. If you can understand this framework, then you can basically design any application you can think of.<\/p>\n\n\n\n<p>Before we get to that, I\u2019ll show you how to get started with the IB API \u2013 how it works, how to configure it, and options available for using it.<\/p>\n\n\n\n<p>Then I\u2019ll show you a Hello World example, and in later articles, I\u2019ll go through some more interesting and complex use cases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-ib-api-is-kind-of-different\">The IB API is (kind of) different<\/h2>\n\n\n\n<p>The IB API is essentially a message protocol for communicating with the IB desktop trading platforms \u2013 Trader Workstation (TWS) and Gateway (GW).<\/p>\n\n\n\n<p>If you think about this in terms of the normal client-server framework, your trading code is essentially the \u201cclient\u201d and TWS is the \u201cserver\u201d, and they communicate using the IB API. TWS acts as an intermediary to IB\u2019s actual servers, and the API provides an interface to TWS.<\/p>\n\n\n\n<p>The most obvious implication is that you need to have TWS or GW running in order to use the API.<\/p>\n\n\n\n<p>This means that you also need to deal with restarts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-dealing-with-restarts\">Dealing with restarts<\/h3>\n\n\n\n<p>TWS and GW were designed to be restarted daily (for example to re-download contract definitions where contracts have been changed or new contracts added). However, they have an auto-restart feature that restarts the application daily without user intervention. With this option enabled, the application can run for up to a week without re-authenticating. However, after the nightly server reset on Saturday night (US), you will have to re-authenticate.<\/p>\n\n\n\n<p>Of course, if you\u2019re trading, you\u2019ll be checking on the platform constantly, but it\u2019s nice not to have to re-authenticate every time it restarts.<\/p>\n\n\n\n<p>To set that option in TWS, from the File menu, choose Global Configuration:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1081\" height=\"477\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/file__global_config-robot-wealth.png\" alt=\"\" class=\"wp-image-203311 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/file__global_config-robot-wealth.png 1081w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/file__global_config-robot-wealth-700x309.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/file__global_config-robot-wealth-300x132.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/file__global_config-robot-wealth-768x339.png 768w\" data-sizes=\"(max-width: 1081px) 100vw, 1081px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1081px; aspect-ratio: 1081\/477;\" \/><\/figure>\n\n\n\n<p>Then, from the Configuration menu, choose \u201cLock and Exit\u201d. Check the \u201cAuto restart\u201d button, uncheck the \u201cAuto log off\u201d button, and set the time you\u2019d like to have the application restart:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1096\" height=\"565\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/lock_and_exit_autorestart-robot-wealth-1.png\" alt=\"\" class=\"wp-image-203335 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/lock_and_exit_autorestart-robot-wealth-1.png 1096w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/lock_and_exit_autorestart-robot-wealth-1-700x361.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/lock_and_exit_autorestart-robot-wealth-1-300x155.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/lock_and_exit_autorestart-robot-wealth-1-768x396.png 768w\" data-sizes=\"(max-width: 1096px) 100vw, 1096px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1096px; aspect-ratio: 1096\/565;\" \/><\/figure>\n\n\n\n<p>The restart time is in the time zone you have set for TWS. You can see TWS\u2019 current time in the top right hand corner:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"343\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/current_time-robot-wealth-1100x343.png\" alt=\"\" class=\"wp-image-203313 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/current_time-robot-wealth-1100x343.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/current_time-robot-wealth-700x218.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/current_time-robot-wealth-300x94.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/current_time-robot-wealth-768x240.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/current_time-robot-wealth.png 1115w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/343;\" \/><\/figure>\n\n\n\n<p>If you need to change the time zone, you\u2019ll need to log out, and from the log in screen choose \u201cMore options\u201d. You can then change your time zone:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"987\" height=\"574\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/change-timezone-settings-robot-wealth.png\" alt=\"\" class=\"wp-image-203340 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/change-timezone-settings-robot-wealth.png 987w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/change-timezone-settings-robot-wealth-700x407.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/change-timezone-settings-robot-wealth-300x174.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/change-timezone-settings-robot-wealth-768x447.png 768w\" data-sizes=\"(max-width: 987px) 100vw, 987px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 987px; aspect-ratio: 987\/574;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Using the IB API<\/h2>\n\n\n\n<p>You have a few options for working with the IB API. You can either use an existing wrapper such as&nbsp;<a href=\"https:\/\/github.com\/erdewit\/ib_insync\">ib_insync<\/a>, or work with the native API.<\/p>\n\n\n\n<p>The advantage of something like ib_insync is that all of the \u201cplumbing\u201d code is done for you \u2013 in particular, it\u2019s a fully asynchronous framework which handles messages to and from TWS.<\/p>\n\n\n\n<p>The native API is a bit more complex to work with, and you\u2019ll have to figure out how to handle messages yourself (async, threading, etc). On the other hand, the native API is officially supported by IB (ib_insync is third-party software, although at the moment is actively maintained), and it removes any limitations on customisation.<\/p>\n\n\n\n<p>In this series, we\u2019ll use the native API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the native IB API<\/h2>\n\n\n\n<p>The first step is installing the native API.<\/p>\n\n\n\n<p>Grab the software installer for your operating system from&nbsp;<a href=\"https:\/\/interactivebrokers.github.io\/\">IB\u2019s github pages<\/a>. Run the installer and follow the prompts.<\/p>\n\n\n\n<p>You\u2019ll also need Python \u2013&nbsp;<a href=\"https:\/\/docs.anaconda.com\/free\/miniconda\/index.html\">Miniconda<\/a>&nbsp;provides a good, minimal installation, but use whatever you normally work with.<\/p>\n\n\n\n<p>Once the API software is installed, navigate to the installation directory (on Windows, usually C:\\TWS API). Then drill down to the pythonclient directory and run the setup.py file with the&nbsp;<code>install<\/code>&nbsp;parameter:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"808\" height=\"408\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/install_native_api_pythonclient-robot-wealth.png\" alt=\"\" class=\"wp-image-203315 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/install_native_api_pythonclient-robot-wealth.png 808w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/install_native_api_pythonclient-robot-wealth-700x353.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/install_native_api_pythonclient-robot-wealth-300x151.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/install_native_api_pythonclient-robot-wealth-768x388.png 768w\" data-sizes=\"(max-width: 808px) 100vw, 808px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 808px; aspect-ratio: 808\/408;\" \/><\/figure>\n\n\n\n<p>Once the installation completes, verify that it worked by doing&nbsp;<code>python -m pip show ibapi<\/code>&nbsp;to show the latest installed version:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1042\" height=\"303\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/confirm_install-robot-wealth.png\" alt=\"\" class=\"wp-image-203316 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/confirm_install-robot-wealth.png 1042w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/confirm_install-robot-wealth-700x204.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/confirm_install-robot-wealth-300x87.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/confirm_install-robot-wealth-768x223.png 768w\" data-sizes=\"(max-width: 1042px) 100vw, 1042px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1042px; aspect-ratio: 1042\/303;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring TWS to use the API<\/h2>\n\n\n\n<p>Next we need to configure TWS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable logging<\/h3>\n\n\n\n<p>TWS can be configured to write a separate log file that documents communication via the API. This will make debugging a whole lot simpler, so enable it in TWS as follows:<\/p>\n\n\n\n<p>From the File menu, select \u201cGlobal Configuration\u201d. Then, select \u201cAPI\u201d \u2013&gt; \u201cSettings\u201d and check the box for \u201cCreate API message file\u201d:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"617\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/create_log_file-robot-wealth-1100x617.png\" alt=\"\" class=\"wp-image-203318 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/create_log_file-robot-wealth-1100x617.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/create_log_file-robot-wealth-700x393.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/create_log_file-robot-wealth-300x168.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/create_log_file-robot-wealth-768x431.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/create_log_file-robot-wealth.png 1441w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/617;\" \/><\/figure>\n\n\n\n<p>TWS logs are encrypted. To read them, you\u2019ll need to export them from TWS as follows:<\/p>\n\n\n\n<p>From the Help menu, select \u201cTroubleshooting\u201d \u2013&gt; \u201cDiagnostics\u201d \u2013&gt; \u201cAPI Log Files\u201d:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"847\" height=\"468\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/export_tws_logs-robot-wealth.png\" alt=\"\" class=\"wp-image-203319 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/export_tws_logs-robot-wealth.png 847w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/export_tws_logs-robot-wealth-700x387.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/export_tws_logs-robot-wealth-300x166.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/export_tws_logs-robot-wealth-768x424.png 768w\" data-sizes=\"(max-width: 847px) 100vw, 847px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 847px; aspect-ratio: 847\/468;\" \/><\/figure>\n\n\n\n<p>You can then select the logs you want to export.<\/p>\n\n\n\n<p>See&nbsp;<a href=\"\/campus\/ibkr-api-page\/trader-workstation-api\/#tws-logs\">here<\/a>&nbsp;for more detailed information about the TWS log files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration settings<\/h3>\n\n\n\n<p>You\u2019ll also need to configure the following settings in TWS:<\/p>\n\n\n\n<p>From the File menu, select \u201cGlobal Configuration\u201d \u2013&gt; \u201cAPI\u201d \u2013&gt; \u201cSettings\u201d. Then, make the following changes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check the box for \u201cEnable ActiveX and Socket Clients\u201d<\/li>\n\n\n\n<li>Designate a socket port \u2013 7496 is the default<\/li>\n\n\n\n<li>Check the box for \u201cAllow connections from localhost only\u201d \u2013 this will allow connections only from applications running on the same machine as TWS.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1100\" height=\"765\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/api_config_settings-robot-wealth-1-1100x765.png\" alt=\"\" class=\"wp-image-203343 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/api_config_settings-robot-wealth-1-1100x765.png 1100w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/api_config_settings-robot-wealth-1-700x487.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/api_config_settings-robot-wealth-1-300x209.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/api_config_settings-robot-wealth-1-768x534.png 768w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/api_config_settings-robot-wealth-1.png 1436w\" data-sizes=\"(max-width: 1100px) 100vw, 1100px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1100px; aspect-ratio: 1100\/765;\" \/><\/figure>\n\n\n\n<p>If you want to have multiple TWS instances running on the same machine, you can configure each with a different API socket port number.<\/p>\n\n\n\n<p>You may wish to connect to TWS remotely. In that case, uncheck \u201cAllow connections from localhost only\u201d and add the relevant IP addresses to \u201cTrusted IPs\u201d. If you don\u2019t add these IPs, you\u2019ll have to manually authenticate each connection from a pop-up box in TWS (which kind of defeats the purpose of remote access).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the messaging framework<\/h2>\n\n\n\n<p>A Python client application using the IB API requires two threads of execution:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One for messages sent from TWS to the client application. This uses the&nbsp;<code>IBAPI.Ewrapper<\/code>&nbsp;interface, which you can use out of the box or override depending on how you want to handle these messages.<\/li>\n\n\n\n<li>One for messages sent from the client application to TWS. This uses the&nbsp;<code>IBAPI.EClientSocket<\/code>&nbsp;class, which you inherit from, and include your&nbsp;<code>IBApi.EWrapper<\/code>&nbsp;in the constructor parameters (so that the application can handle all the messages coming from TWS).<\/li>\n<\/ul>\n\n\n\n<p>The base class&nbsp;<code>Ewrapper<\/code>&nbsp;defines and implements functions for handling messages from TWS by simply logging them. You may wish to inherit from this class and override the methods depending on how you want to handle these messages.<\/p>\n\n\n\n<p>In the Python implementation of&nbsp;<code>EClient<\/code>, messages are processed using a&nbsp;<code>Queue<\/code>. This happens in an endless loop in&nbsp;<code>Eclient.run<\/code>. In other languages, you need a third thread of execution to handle this.<\/p>\n\n\n\n<p>Let\u2019s make this a bit more real with a Hello World example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hello World<\/h2>\n\n\n\n<p>In this example, we\u2019ll connect to TWS, request our account information, and print it to screen.<\/p>\n\n\n\n<p>Before writing any code, it\u2019s always worth thinking about the architecture of an IB API application, which is inherently a message-handling program.<\/p>\n\n\n\n<p>Remember that we handle our messages to and from TWS in separate threads, so ideally we would have some way of signalling between threads when a message has been received or processed.<\/p>\n\n\n\n<p>To do this, we\u2019ll use&nbsp;<code>threading.Event<\/code>, which is a simple way to control the flow of a program hat involves asynchronous operations and multiple threads.<\/p>\n\n\n\n<p><code>threading.Event<\/code>&nbsp;manages an internal flag that can be set to True with the&nbsp;<code>set()<\/code>&nbsp;method and reset to False with the&nbsp;<code>clear()<\/code>&nbsp;method. Other threads can wait for this flag to be set by calling the&nbsp;<code>wait()<\/code>&nbsp;method, which blocks until the flag becomes True.<\/p>\n\n\n\n<p>This mechanism is particularly useful for signaling between threads, allowing one thread to signal another that an event has occurred or a condition has been met \u2013 which is exactly what we need to do with our TWS messaging application.<\/p>\n\n\n\n<p>We\u2019ll use the&nbsp;<code>Eclient.reqAccountSummary<\/code>&nbsp;method to request our account information. If you look at the&nbsp;<a href=\"\/campus\/ibkr-api-page\/trader-workstation-api\/#requesting-account-summary\">documentation<\/a>&nbsp;for this function, you\u2019ll also find the&nbsp;<code>Ewrapper<\/code>&nbsp;methods that we need to override in order to handle the messages coming back from TWS.<\/p>\n\n\n\n<p>We also use the following methods from&nbsp;<code>Eclient<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>connect<\/code>&nbsp;\u2013 initiates a connection with TWS and triggers the&nbsp;<code>Ewrapper.nextValidId<\/code>&nbsp;callback once established. We\u2019ll use a&nbsp;<code>threading.Event<\/code>&nbsp;to signal when this callback is triggered and our connection is established (messages sent while the connection is being established can be lost).<\/li>\n\n\n\n<li><code>disconnect<\/code>&nbsp;\u2013 terminates the connection with TWS (but doesn\u2019t cancel in-flight orders), good practice to include this at the completion of your script.<\/li>\n\n\n\n<li><code>run<\/code>&nbsp;\u2013 processes the message queue in an infinite loop while connected.<\/li>\n<\/ul>\n\n\n\n<p>Here\u2019s the script for connecting to TWS, requesting our account information, and printing it to screen. I\u2019ve heavily commented it so that you can follow what\u2019s going on if you\u2019re new to this.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># %load ibkr-api\/account_summary.py\nfrom threading import Thread, Event\nimport time\nfrom typing import Any\nfrom ibapi.wrapper import EWrapper\nfrom ibapi.client import EClient\nfrom ibapi.common import *\nfrom ibapi.account_summary_tags import AccountSummaryTags\n\n\nclass ibapp(EClient, EWrapper):\n    def __init__(self):\n        EClient.__init__(self, self)\n        self.done = Event()  # use threading.Event to signal between threads\n        self.connection_ready = Event()  # to signal the connection has been established\n\n    # override Ewrapper.error\n    def error(\n        self, reqId: TickerId, errorCode: int, errorString: str, contract: Any = None\n    ):\n        print(\"Error: \", reqId, \" \", errorCode, \" \", errorString)\n        if errorCode == 502:  # not connected\n            # set self.done (a threading.Event) to True\n            self.done.set()\n\n    # override Ewrapper.accountSummary - method for receiving account summary\n    def accountSummary(\n        self, reqId: int, account: str, tag: str, value: str, currency: str\n    ):\n        # just print the account information to screen\n        print(\n            \"AccountSummary. ReqId:\",\n            reqId,\n            \"Account:\",\n            account,\n            \"Tag: \",\n            tag,\n            \"Value:\",\n            value,\n            \"Currency:\",\n            currency,\n        )\n\n    # override Ewrapper.accountSummaryEnd - notifies when account summary information has been received\n    def accountSummaryEnd(self, reqId: int):\n        # print to screen\n        print(\"AccountSummaryEnd. ReqId:\", reqId)\n        # set self.done (a threading.Event) to True\n        self.done.set()\n\n    # override Ewrapper.nextValidID - used to signal that the connection between application and TWS is complete\n    # returns the next valid orderID (for any future transactions)\n    # if we send messages before the connection has been established, they can be lost\n    # so wait for this method to be called\n    def nextValidId(self, orderId: int):\n        print(f\"Connection ready, next valid order ID: {orderId}\")\n        self.connection_ready.set()  # signal that the connection is ready\n\n\n# define our event loop - this will run in its own thread\ndef run_loop(app):\n    app.run()\n\n\n# instantiate an ibapp\napp = ibapp()\n\n# connect\napp.connect(\"127.0.0.1\", 7496, clientId=0)  # clientID identifies our application\n\n# start the application's event loop in a thread\napi_thread = Thread(target=run_loop, args=(app,), daemon=True)\napi_thread.start()\n\n# wait until the Ewrapper.nextValidId callback is triggered, indicating a successful connection\napp.connection_ready.wait()\n\n# request account summary\nprint(\"Requesting account summary\")\napp.reqAccountSummary(0, \"All\", AccountSummaryTags.AllTags)\n\n# wait for the account summary to finish (ie block until app.done - a threading.Event - becomes true)\napp.done.wait()\n\n# disconnect\napp.disconnect()<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Connection ready, next valid order ID: 1\nRequesting account summary\nError:  -1   2104   Market data farm connection is OK:usfarm.nj\nError:  -1   2104   Market data farm connection is OK:hfarm\nError:  -1   2104   Market data farm connection is OK:jfarm\nError:  -1   2104   Market data farm connection is OK:cashfarm\nError:  -1   2104   Market data farm connection is OK:eufarmnj\nError:  -1   2104   Market data farm connection is OK:usfarm\nError:  -1   2106   HMDS data farm connection is OK:euhmds\nError:  -1   2106   HMDS data farm connection is OK:cashhmds\nError:  -1   2106   HMDS data farm connection is OK:fundfarm\nError:  -1   2106   HMDS data farm connection is OK:ushmds\nError:  -1   2158   Sec-def data farm connection is OK:secdefnj\nAccountSummary. ReqId: 0 Account: DU* Tag:  AccountType Value: LLC Currency: \nAccountSummary. ReqId: 0 Account: DU* Tag:  Cushion Value: 1 Currency: \nAccountSummary. ReqId: 0 Account: DU* Tag:  LookAheadNextChange Value: 1709821800 Currency: \nAccountSummary. ReqId: 0 Account: DU* Tag:  AccruedCash Value: 0.00 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  AvailableFunds Value: 94012.52 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  BuyingPower Value: 109205.21 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  EquityWithLoanValue Value: 114919.02 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  ExcessLiquidity Value: 95913.11 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  FullAvailableFunds Value: 94012.52 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  FullExcessLiquidity Value: 95913.11 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  FullInitMarginReq Value: 20906.50 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  FullMaintMarginReq Value: 19005.91 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  GrossPositionValue Value: 38555.06 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  InitMarginReq Value: 20906.50 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  LookAheadAvailableFunds Value: 94012.52 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  LookAheadExcessLiquidity Value: 95913.11 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  LookAheadInitMarginReq Value: 20906.50 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  LookAheadMaintMarginReq Value: 19005.91 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  MaintMarginReq Value: 19005.91 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  NetLiquidation Value: 114919.02 Currency: USD\nAccountSummary. ReqId: 0 Account: DU* Tag:  TotalCashValue Value: 76363.96 Currency: USD\nAccountSummaryEnd. ReqId: 0<\/pre>\n\n\n\n<p>The output shows that after the connection was established, we requested our account summary. We get a few lines with error code 2104. These aren\u2019t actually errors, they\u2019re warning messages. From the list of&nbsp;<a href=\"https:\/\/interactivebrokers.github.io\/tws-api\/message_codes.html\">error codes<\/a>, we can see that 2104 means \u201cMarket data farm connection is OK\u201d.<\/p>\n\n\n\n<p>We also get some 2106\u2019s (A historical data farm is connected) and a 2158 (Sec-def data farm connection is OK).<\/p>\n\n\n\n<p>Then, we print out each item in our account summary (this is from a connection to a paper trading account).<\/p>\n\n\n\n<p>Finally, after our account summary has been processed, we print the account summary end message.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this article, you learned how to set up TWS to use the IB native Python API.<\/p>\n\n\n\n<p>You also learned that an application that uses the API to interact with TWS is, at its heart, a message-handling program.<\/p>\n\n\n\n<p>We saw that using&nbsp;<code>threading.Event<\/code>&nbsp;to signal between threads when a message has been received and\/or processed is a simple and effective way to manage the flow of information.<\/p>\n\n\n\n<p>We started with the simplest possible use case \u2013 connecting to TWS and requesting our account information. In future articles, we\u2019ll explore some more complex use cases.<\/p>\n\n\n\n<p>To consolidate your understanding, consider these next steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Have a look through the IB API&nbsp;<a href=\"\/campus\/ibkr-api-page\/trader-workstation-api\">documentation<\/a>&nbsp;to get an idea of the functionality (essentially, anything you can manually do in TWS, you can do via API).<\/li>\n\n\n\n<li>Also have a look at the source code for Eclient and Ewrapper. On Windows, they live in the directory C:\\TWS API\\source\\pythonclient\\ibapi (client.py, wrapper.py).<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>An application that interacts with IB\u2019s desktop trading applications via the API is essentially a message-handling program.<\/p>\n","protected":false},"author":271,"featured_media":203271,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,340,343,349,338,341],"tags":[851,865,15252,16807,16806,575,10383,595],"contributors-categories":[13676],"class_list":{"0":"post-203269","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-api-development","9":"category-programing-languages","10":"category-python-development","11":"category-ibkr-quant-news","12":"category-quant-development","13":"tag-algo-trading","14":"tag-github","15":"tag-ib_insync","16":"tag-ibapi-eclientsocket","17":"tag-ibapi-ewrapper","18":"tag-ibkr-api","19":"tag-miniconda","20":"tag-python","21":"contributors-categories-robot-wealth"},"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>Getting Started with the Interactive Brokers Native API<\/title>\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\/posts\/203269\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Started with the Interactive Brokers Native API\" \/>\n<meta property=\"og:description\" content=\"An application that interacts with IB\u2019s desktop trading applications via the API is essentially a message-handling program.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-12T16:39:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-21T14:05:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Kris Longmore\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kris Longmore\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 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\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Kris Longmore\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/79c2a2775a70a4da1accf0068d731933\"\n\t            },\n\t            \"headline\": \"Getting Started with the Interactive Brokers Native API\",\n\t            \"datePublished\": \"2024-03-12T16:39:32+00:00\",\n\t            \"dateModified\": \"2024-03-21T14:05:51+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/\"\n\t            },\n\t            \"wordCount\": 1795,\n\t            \"commentCount\": 0,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/03\\\/python-beehive-chart.jpg\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"GitHub\",\n\t                \"ib_insync\",\n\t                \"IBAPI.EClientSocket\",\n\t                \"IBAPI.Ewrapper\",\n\t                \"IBKR API\",\n\t                \"Miniconda\",\n\t                \"Python\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"IBKR API Development\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/\",\n\t            \"name\": \"Getting Started with the Interactive Brokers Native API | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/03\\\/python-beehive-chart.jpg\",\n\t            \"datePublished\": \"2024-03-12T16:39:32+00:00\",\n\t            \"dateModified\": \"2024-03-21T14:05:51+00:00\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/\"\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.com\\\/campus\\\/ibkr-quant-news\\\/getting-started-with-the-interactive-brokers-native-api\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/03\\\/python-beehive-chart.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/03\\\/python-beehive-chart.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Quant\"\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            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/79c2a2775a70a4da1accf0068d731933\",\n\t            \"name\": \"Kris Longmore\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/krislongmore\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Getting Started with the Interactive Brokers Native API","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\/posts\/203269\/","og_locale":"en_US","og_type":"article","og_title":"Getting Started with the Interactive Brokers Native API","og_description":"An application that interacts with IB\u2019s desktop trading applications via the API is essentially a message-handling program.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/","og_site_name":"IBKR Campus US","article_published_time":"2024-03-12T16:39:32+00:00","article_modified_time":"2024-03-21T14:05:51+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg","type":"image\/jpeg"}],"author":"Kris Longmore","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kris Longmore","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/"},"author":{"name":"Kris Longmore","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/79c2a2775a70a4da1accf0068d731933"},"headline":"Getting Started with the Interactive Brokers Native API","datePublished":"2024-03-12T16:39:32+00:00","dateModified":"2024-03-21T14:05:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/"},"wordCount":1795,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg","keywords":["Algo Trading","GitHub","ib_insync","IBAPI.EClientSocket","IBAPI.Ewrapper","IBKR API","Miniconda","Python"],"articleSection":["Data Science","IBKR API Development","Programming Languages","Python Development","Quant","Quant Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/","name":"Getting Started with the Interactive Brokers Native API | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg","datePublished":"2024-03-12T16:39:32+00:00","dateModified":"2024-03-21T14:05:51+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/getting-started-with-the-interactive-brokers-native-api\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg","width":1000,"height":563,"caption":"Quant"},{"@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\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/79c2a2775a70a4da1accf0068d731933","name":"Kris Longmore","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/krislongmore\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/03\/python-beehive-chart.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/203269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/271"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=203269"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/203269\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/203271"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=203269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=203269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=203269"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=203269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}