{"id":137186,"date":"2022-05-06T11:00:49","date_gmt":"2022-05-06T15:00:49","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=137186"},"modified":"2023-01-19T18:16:47","modified_gmt":"2023-01-19T23:16:47","slug":"how-to-retrieve-equity-data-through-the-python-api","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/","title":{"rendered":"How to Retrieve Equity Data\u00a0through the Python API"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1000\" height=\"562\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png\" alt=\"\" class=\"wp-image-137190 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png 1000w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear-700x393.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear-300x169.png 300w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear-768x432.png 768w\" data-sizes=\"(max-width: 1000px) 100vw, 1000px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1000px; aspect-ratio: 1000\/562;\" \/><\/figure>\n\n\n\n<p>Following your TWS API Python based client development, next things to look into is equity data: order data retrieval, positions and completed orders. Arguably, this is the most important in all of the trading steps. We will look into the basics of what needs to be done to request such data in the following sections.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-is-connection-established\">Is connection established?<\/h3>\n\n\n\n<p>Assuming the connection is already established between your API client and TWS\/Gateway.<\/p>\n\n\n\n<p>If not, you can test with the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ibapi.client import EClient\nfrom ibapi.wrapper import EWrapper  \n\nclass IBapi(EWrapper, EClient):\n     def __init__(self):\n         EClient.__init__(self, self) \n\napp = IBapi()\napp.connect('127.0.0.1', 7496, 0)\napp.run()\n<\/code><\/pre>\n\n\n\n<p>If more attempts to reconnect are required, use the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\ntime.sleep(2)\napp.disconnect()\n<\/code><\/pre>\n\n\n\n<p>The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready. The sleep function is also required, as we are using asynchronous API, so the program won\u2019t wait for response and may continue working.<\/p>\n\n\n\n<p>Output will have several Market data farm connection statuses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Requesting Contract Information<\/h3>\n\n\n\n<p>This step is actually required to actually know what equity do you want to work with.<\/p>\n\n\n\n<p>All of the contract information you need for this step can be acquired via TWS.<\/p>\n\n\n\n<p>In watchlist, enter any stock you are interested in, for example AAPL. This will offer all of the available contracts having similar or exact names available in TWS.<\/p>\n\n\n\n<p>If you select Stock@SMART, the Apple Stock at SMART exchange will populate the watchlist. Please note, that SMART exchange value is IBKR\u2019s own system, that takes the best prices available from multiple traded exchanges, like NASDAQ, NYSE, etc.<\/p>\n\n\n\n<p>Right clicking the instrument -&gt; selecting Financial Information -&gt; clicking on Description will open a new window with all valid current contract information. We can use this data to populate the contract in our Python client.<\/p>\n\n\n\n<p>The following code snippet points at AAPL@SMART contract:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Create contract object\napple_contract = Contract()\napple_contract.symbol = 'AAPL'\napple_contract.secType = 'STK'\napple_contract.exchange = 'SMART'\napple_contract.currency = 'USD'<\/code><\/pre>\n\n\n\n<p>Now we can use this contract to start actually receiving the market data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Streaming market data<\/h3>\n\n\n\n<p>One of the requirements to start streaming any instrument\u2019s live data is having the correct market data subscription. Valid subscriptions can be checked in TWS with your live account by right clicking the instrument in the watchlist -&gt; Launch Market Data Subscription Manager.<\/p>\n\n\n\n<p>But, if you are on your paper account with no subscriptions and no intention to subscribe to any of the required packages, you can still use Delayed data. It is still live data, although delayed by 10-15-20 minutes depending on the exchange.<\/p>\n\n\n\n<p>To keep the text short, only the new lines would be added on top of the connection code snippet.<\/p>\n\n\n\n<p>Before you request any market data, first you may need to specify if it\u2019s live or delayed data you are after.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public virtual void marketDataType(int reqId, int marketDataType)\n        {\n            Console.WriteLine(\"MarketDataType. \"+reqId+\", Type: \"+marketDataType+\"\\n\");\n        }<\/code><\/pre>\n\n\n\n<p>The Market data type has 4 Ids:<\/p>\n\n\n\n<p>1 \u2013 Live<\/p>\n\n\n\n<p>2 \u2013 Frozen<\/p>\n\n\n\n<p>3 \u2013 Delayed<\/p>\n\n\n\n<p>4 \u2013 Delayed Frozen<\/p>\n\n\n\n<p>For more information about them please look into <a href=\"https:\/\/interactivebrokers.github.io\/tws-api\/market_data_type.html\">https:\/\/interactivebrokers.github.io\/tws-api\/market_data_type.html<\/a> article.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Request Market Data\napp.reqMktData(1, apple_contract, '236, 456', False, False, &#91;])<\/code><\/pre>\n\n\n\n<p>The composition of this line is in left to right order:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>tickerId<\/td><td>the request&#8217;s identifier<\/td><\/tr><tr><td>contract<\/td><td>the&nbsp;<a href=\"https:\/\/interactivebrokers.github.io\/tws-api\/classIBApi_1_1Contract.html\"><strong>Contract<\/strong><\/a>&nbsp;for which the data is being requested<\/td><\/tr><tr><td>genericTickList<\/td><td>Available list here: <a href=\"https:\/\/interactivebrokers.github.io\/tws-api\/tick_types.html\">https:\/\/interactivebrokers.github.io\/tws-api\/tick_types.html<\/a><\/td><\/tr><tr><td>snapshot<\/td><td>for users with corresponding real time market data subscriptions. A true value will return a one-time snapshot, while a false value will provide streaming data.<\/td><\/tr><tr><td>Regulatory<\/td><td>snapshot for US stocks requests NBBO snapshots for users which have \u201cUS Securities Snapshot Bundle\u201d subscription but not corresponding Network A, B, or C subscription necessary for streaming * market data. One-time snapshot of current market price that will incur a fee of 1 cent to the account per snapshot.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The market data is then delivered, depending on the tick type selected via tickPrice, tickSize, tickString or tickGeneric.<\/p>\n\n\n\n<p>TickPrice:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public virtual void tickPrice(int tickerId, int field, double price, TickAttrib attribs) \n        {\n            Console.WriteLine(\"Tick Price. Ticker Id:\" + tickerId + \", Field: \" + field + \", Price: \" + Util.DoubleMaxString(price) + \", CanAutoExecute: \" + attribs.CanAutoExecute + \n                \", PastLimit: \" + attribs.PastLimit + \", PreOpen: \" + attribs.PreOpen);\n        }<\/code><\/pre>\n\n\n\n<p>TickSize:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        public virtual void tickSize(int tickerId, int field, decimal size)\n        {\n            Console.WriteLine(\"Tick Size. Ticker Id:\" + tickerId + \", Field: \" + field + \", Size: \" + Util.DecimalMaxString(size));\n        }<\/code><\/pre>\n\n\n\n<p>TickGeneric:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        public virtual void tickGeneric(int tickerId, int field, double value)\n        {\n            Console.WriteLine(\"Tick Generic. Ticker Id:\" + tickerId + \", Field: \" + field + \", Value: \" + Util.DoubleMaxString(value));\n        }\n<\/code><\/pre>\n\n\n\n<p>tickString:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        public virtual void tickString(int tickerId, int tickType, string value)\n        {\n            Console.WriteLine(\"Tick string. Ticker Id:\" + tickerId + \", Type: \" + tickType + \", Value: \" + value);\n        }\n<\/code><\/pre>\n\n\n\n<p>The above functions return any given tick associated with the relative function. Without implementing above methods, the data will not be delivered.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Historical Data<\/strong><\/h3>\n\n\n\n<p>Obtaining historical data is done in similar fashion as requesting streaming market data.<\/p>\n\n\n\n<p>We will use Forex EUR.USD example to retrieve historical data. Because historical data is only available to market data subscription holders. Forex is an exception and it is available for free.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>eurusd_contract = Contract()\neurusd_contract.symbol = 'EUR'\neurusd_contract.secType = 'CASH'\neurusd_contract.exchange = 'IDEALPRO'\neurusd_contract.currency = 'USD'<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#Request historical candles\napp.reqHistoricalData(1, eurusd_contract, '', '1 W', '1 day', 'BID', 0, 1, False, &#91;])<\/code><\/pre>\n\n\n\n<p>The above function requests daily bars for the last week. Note how end data is not defined, thus this function will return last week of available daily bars.<\/p>\n\n\n\n<p>Below is the description of those properties:<\/p>\n\n\n\n<p>tickerId, A unique identifier which will serve to identify the incoming data.<\/p>\n\n\n\n<p>contract, The IBApi.Contract you are interested in.<\/p>\n\n\n\n<p>endDateTime, The request&#8217;s end date and time (the empty string indicates current present moment).<\/p>\n\n\n\n<p>durationString, The amount of time (or Valid Duration String units) to go back from the request&#8217;s given end date and time.<\/p>\n\n\n\n<p>barSizeSetting, The data&#8217;s granularity or Valid Bar Sizes<\/p>\n\n\n\n<p>whatToShow, The type of data to retrieve. See Historical Data Types<\/p>\n\n\n\n<p>useRTH, Whether (1) or not (0) to retrieve data generated only within Regular Trading Hours (RTH)<\/p>\n\n\n\n<p>formatDate, The format in which the incoming bars&#8217; date should be presented. Note that for day bars, only yyyyMMdd format is available.<\/p>\n\n\n\n<p>keepUpToDate, Whether a subscription is made to return updates of unfinished real time bars as they are available (True), or all data is returned on a one-time basis (False). Available starting with API v973.03+ and TWS v965+. If True, and endDateTime cannot be specified.<\/p>\n\n\n\n<p>Historical data then is returned via historicalData function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        public virtual void historicalData(int reqId, Bar bar)\n        {\n            Console.WriteLine(\"HistoricalData. \" + reqId + \" - Time: \" + bar.Time + \", Open: \" + Util.DoubleMaxString(bar.Open) + \", High: \" + Util.DoubleMaxString(bar.High) + \n                \", Low: \" + Util.DoubleMaxString(bar.Low) + \", Close: \" + Util.DoubleMaxString(bar.Close) + \", Volume: \" + Util.DecimalMaxString(bar.Volume) + \n                \", Count: \" + Util.IntMaxString(bar.Count) + \", WAP: \" + Util.DecimalMaxString(bar.WAP));\n        }<\/code><\/pre>\n\n\n\n<p>Please note, that when setting keepUpToData to true, you would need to implement historicalDataUpdate function. This is working in similar manner as reqMktData, that it sends all of the new data continuously.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public void historicalDataUpdate(int reqId, Bar bar)\n        {\n            Console.WriteLine(\"HistoricalDataUpdate. \" + reqId + \" - Time: \" + bar.Time + \", Open: \" + Util.DoubleMaxString(bar.Open) + \", High: \" + Util.DoubleMaxString(bar.High) + \n                \", Low: \" + Util.DoubleMaxString(bar.Low) + \", Close: \" + Util.DoubleMaxString(bar.Close) + \", Volume: \" + Util.DecimalMaxString(bar.Volume) + \n                \", Count: \" + Util.IntMaxString(bar.Count) + \", WAP: \" + Util.DecimalMaxString(bar.WAP));\n        }<\/code><\/pre>\n\n\n\n<p>If you have no keepUpToData specified, the historicalDataEnd must be called.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        public virtual void historicalDataEnd(int reqId, string startDate, string endDate)\n        {\n            Console.WriteLine(\"HistoricalDataEnd - \"+reqId+\" from \"+startDate+\" to \"+endDate);\n        }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.<\/p>\n","protected":false},"author":826,"featured_media":137190,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,340,343,349,338],"tags":[851,4873,1014,1015,865,5110,575,1013,595,11707],"contributors-categories":[13576],"class_list":{"0":"post-137186","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":"tag-algo-trading","13":"tag-backtesting","14":"tag-eclient","15":"tag-ewrapper","16":"tag-github","17":"tag-historical-data","18":"tag-ibkr-api","19":"tag-program-py","20":"tag-python","21":"tag-python-api","22":"contributors-categories-interactive-brokers"},"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.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Retrieve Equity Data\u00a0through the Python API<\/title>\n<meta name=\"description\" content=\"The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.\" \/>\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\/137186\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Retrieve Equity Data\u00a0through the Python API | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-06T15:00:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-19T23:16:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"562\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Roman Pavlov\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roman Pavlov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 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:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Roman Pavlov\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/44513d53e2b87544b3bdfad2d7af2af1\"\n\t            },\n\t            \"headline\": \"How to Retrieve Equity Data\u00a0through the Python API\",\n\t            \"datePublished\": \"2022-05-06T15:00:49+00:00\",\n\t            \"dateModified\": \"2023-01-19T23:16:47+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/\"\n\t            },\n\t            \"wordCount\": 929,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/python-blue-gear.png\",\n\t            \"keywords\": [\n\t                \"Algo Trading\",\n\t                \"backtesting\",\n\t                \"EClient\",\n\t                \"EWrapper\",\n\t                \"GitHub\",\n\t                \"historical data\",\n\t                \"IBKR API\",\n\t                \"Program.py\",\n\t                \"Python\",\n\t                \"Python API\"\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            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/\",\n\t            \"name\": \"How to Retrieve Equity Data\u00a0through the Python API | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/python-blue-gear.png\",\n\t            \"datePublished\": \"2022-05-06T15:00:49+00:00\",\n\t            \"dateModified\": \"2023-01-19T23:16:47+00:00\",\n\t            \"description\": \"The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/\"\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\\\/ibkr-quant-news\\\/how-to-retrieve-equity-data-through-the-python-api\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/python-blue-gear.png\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/05\\\/python-blue-gear.png\",\n\t            \"width\": 1000,\n\t            \"height\": 562,\n\t            \"caption\": \"Python\"\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\\\/44513d53e2b87544b3bdfad2d7af2af1\",\n\t            \"name\": \"Roman Pavlov\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/roman-pavlov\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Retrieve Equity Data\u00a0through the Python API","description":"The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.","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\/137186\/","og_locale":"en_US","og_type":"article","og_title":"How to Retrieve Equity Data\u00a0through the Python API | IBKR Quant Blog","og_description":"The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/","og_site_name":"IBKR Campus US","article_published_time":"2022-05-06T15:00:49+00:00","article_modified_time":"2023-01-19T23:16:47+00:00","og_image":[{"width":1000,"height":562,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png","type":"image\/png"}],"author":"Roman Pavlov","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Roman Pavlov","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/#article","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/"},"author":{"name":"Roman Pavlov","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/44513d53e2b87544b3bdfad2d7af2af1"},"headline":"How to Retrieve Equity Data\u00a0through the Python API","datePublished":"2022-05-06T15:00:49+00:00","dateModified":"2023-01-19T23:16:47+00:00","mainEntityOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/"},"wordCount":929,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png","keywords":["Algo Trading","backtesting","EClient","EWrapper","GitHub","historical data","IBKR API","Program.py","Python","Python API"],"articleSection":["Data Science","IBKR API Development","Programming Languages","Python Development","Quant"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/","url":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/","name":"How to Retrieve Equity Data\u00a0through the Python API | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/#primaryimage"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png","datePublished":"2022-05-06T15:00:49+00:00","dateModified":"2023-01-19T23:16:47+00:00","description":"The first part of the code snippet will establish the connection. The second part sends retries, if for example, the port was not ready.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/how-to-retrieve-equity-data-through-the-python-api\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png","width":1000,"height":562,"caption":"Python"},{"@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\/44513d53e2b87544b3bdfad2d7af2af1","name":"Roman Pavlov","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/roman-pavlov\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/05\/python-blue-gear.png","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/137186","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\/826"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=137186"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/137186\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/137190"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=137186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=137186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=137186"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=137186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}