{"id":212,"date":"2019-11-10T01:02:27","date_gmt":"2019-11-10T00:02:27","guid":{"rendered":"http:\/\/market-and-us.com\/blog\/?p=212"},"modified":"2021-04-08T12:27:54","modified_gmt":"2021-04-08T10:27:54","slug":"how-to-get-historical-stock-data","status":"publish","type":"post","link":"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/","title":{"rendered":"How to get historical stock data"},"content":{"rendered":"\n<p>In the first three articles about coding with financial data (<a href=\"https:\/\/market-and-us.com\/blog\/how-to-code-a-backtest-60\/\">How to code a backtest<\/a>, <a href=\"https:\/\/market-and-us.com\/blog\/how-to-code-basic-stock-scanner-69\/\">How to code a basic stock scanner<\/a> and <a href=\"https:\/\/market-and-us.com\/blog\/how-to-code-indicators-117\/\">How to code the first indicators<\/a>) I did not mention how to get historical stock data.<\/p>\n\n\n\n<p>You will know about it after reading this article! \ud83d\ude42<\/p>\n\n\n\n<h2>Historical stock data<\/h2>\n\n\n\n<p><mark class=\"annotation-text annotation-text-yoast\" id=\"annotation-text-ee9c1eb4-fc9c-4a7f-9de6-abb5b936615c\"><\/mark>To create a candlestick chart you need <strong>four prices for each candle<\/strong>:<br>The price when market opened and closed, the high of the time period the candle represents and the low. In addition to that the volume is useful. It&#8217;s the <strong>number of shares traded<\/strong> in the time period (= 1 day, 1 week, 1 month, 1 minute, &#8230; per candle).<\/p>\n\n\n\n<p>For our example we use daily candles, so we need the date\/day, open, close, high, low and volume.<\/p>\n\n\n\n<p>You know from the other articles that the best module for data sets is <code>pandas<\/code>. You can simply import it in your code with<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas<\/code><\/pre>\n\n\n\n<h2>The 6 best sources for stock data<\/h2>\n\n\n\n<p>For collecting the data we have <strong>several possibilities<\/strong>:<\/p>\n\n\n\n<ol><li>Yahoo Data<\/li><li>IEX Cloud<\/li><li>Alpha Vantage<\/li><li>Quandl<\/li><li>Quantopian<\/li><li>IB API<\/li><\/ol>\n\n\n\n<p>To be honest, I tried all of them but I do not like all of them.<\/p>\n\n\n\n<p>In the beginning of my first <strong>financial applications in Python<\/strong> I used the Yahoo API but then they stopped this service and I searched for an alternative.<br><a href=\"https:\/\/medium.com\/alpha-vantage\/get-started-with-alpha-vantage-data-619a70c7f33a\" class=\"broken_link\">Alpha Vantage<\/a> should be one of the easiest but I didn&#8217;t get it run except some errors and the <a href=\"https:\/\/docs.quandl.com\/\">Quandl<\/a> system, website and data feeds seemed too complicated for me (<em>but maybe one of them is perfect for you<\/em>).<br><s>Quantopian has a very high quality and a helpful community but you have to use their own environment. I coded many backtests there but<\/s> I like to have my own data and my own code to know that every mistake is mine and not one of another system.<\/p>\n\n\n\n<p>Why I <strong>finally ended up with <\/strong><a href=\"https:\/\/finance.yahoo.com\/\"><strong>Yahoo<\/strong><\/a> and why I am also working with the <strong>most complicated API <\/strong>(<a href=\"https:\/\/www.interactivebrokers.com\/en\/index.php?f=5041\">Interactive Brokers API<\/a>), you will learn in the next sections.<\/p>\n\n\n\n<h2>What about Yahoo Finance?<\/h2>\n\n\n\n<p>Yes, you got it right. Yahoo stopped it&#8217;s API service but I am using Yahoo data again.<\/p>\n\n\n\n<p>You can enter a ticker symbol on the Yahoo Finance page and then after choosing the tab &#8220;<strong>Historical Data<\/strong>&#8221; you can select time period and frequency and download a <code>csv<\/code>-file like the ones we used for our last examples by clicking the little link called &#8220;Download Data&#8221;.<\/p>\n\n\n\n<p>And whenever data is displayed online or can be downloaded there are ways to<strong> do the steps automatically<\/strong> and &#8220;collect&#8221; the data in a variable.<\/p>\n\n\n\n<p>This isn&#8217;t legal in every context but because there are modules created for and Yahoo didn&#8217;t block anything like that, we can use it for some stocks. I wouldn&#8217;t recommend to load huge amounts of data because it isn&#8217;t an official API but you can use it <strong>for your own single charts<\/strong>, some <strong>calculations or our examples<\/strong>.<\/p>\n\n\n\n<p>But now enough words about the theory.<\/p>\n\n\n\n<h3>Get your candles from Yahoo<\/h3>\n\n\n\n<p>As I wrote above, there&#8217;s already a module (library) written for this purpose. It changed from <code>fix-yahoo-finance<\/code> (because it fixed the old API-library <code>pandas_datareader<\/code>) to <code><a href=\"https:\/\/pypi.org\/project\/yfinance\/\">yfinance<\/a><\/code>. <\/p>\n\n\n\n<p>Like every module you can add it (and same for <code>pandas<\/code>) simply by<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip3 install yfinance\npip3 install pandas<\/code><\/pre>\n\n\n\n<p>In our example we want <span style=\"text-decoration: underline;\">to fill in the Yahoo data for <\/span><strong><span style=\"text-decoration: underline;\">XOM<\/span><\/strong> into a <code>pandas DataFrame<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\n\nticker  = \"XOM\"\ndata    = yf.download(ticker, start=\"2018-11-08\", end=\"2019-11-08\")<\/code><\/pre>\n\n\n\n<p>To show the <span style=\"text-decoration: underline;\">last 5 or more rows<\/span> of our data and to check if the returned variable <code>data<\/code> is really a DataFrame, we can add these lines: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"Last 5 rows:\")\nprint(data.tail())\nprint(\"And the data type:\", type(data))<\/code><\/pre>\n\n\n\n<p>Because we always need to handle dates in our codes, I will now change the example to a version without the (disturbing) progress bar and <span style=\"text-decoration: underline;\">some date functions<\/span> but with exactly the same result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\nfrom datetime import datetime, timedelta\n\nticker      = \"XOM\"\n\ndate_format = \"%Y-%m-%d\"\ntoday       = datetime.now().strftime(date_format)\nfrom_date   = (datetime.now() - timedelta(days=365)).strftime(date_format)\n\ndata        = yf.download(ticker, start=from_date, end=today, progress=False)\n\nprint(\"Last 5 rows:\")\nprint(data.tail())\nprint(\"And the data type:\", type(data))<\/code><\/pre>\n\n\n\n<h3>More stock data&#8230;<\/h3>\n\n\n\n<p>If you need <span style=\"text-decoration: underline;\">more than one stock<\/span> for your calculations you can just enter several tickers like <code>\"XOM PG EDIT\"<\/code>. Here you have to work with <span style=\"text-decoration: underline;\">2 levels of columns<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import yfinance as yf\nfrom datetime import datetime, timedelta\n\nticker      = \"XOM PG EDIT\"\ndata        = yf.download(ticker, start=\"2018-11-08\", end=\"2019-11-08\", progress=False)\n\nprint(\"Last 5 rows:\")\nprint(data.tail())\nprint(\"And the data type:\", type(data))\n\nprint(data.Close.EDIT.tail())\nprint(data.Volume.XOM.tail())\nprint(data.columns)<\/code><\/pre>\n\n\n\n<p>Personally, I do not like this style of <code>DataFrame<\/code>. I prefer to use <code>yf.download()<\/code> several times. It&#8217;s a little bit slower but much <span style=\"text-decoration: underline;\">easier to handle<\/span> in my opinion.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>It&#8217;s simple and easy, isn&#8217;t it? That&#8217;s why <span style=\"text-decoration: underline;\">I like Yahoo<\/span> as a source for historical stock data <span style=\"text-decoration: underline;\">when I need just some ticker symbols<\/span>.<\/p><\/blockquote>\n\n\n\n<p>With the <code>DataFrame<\/code> full of price data you can <strong>do all the calculations<\/strong> you want and those you find here on <strong>Market and Us<\/strong>. Many of them will follow!<\/p>\n\n\n\n<h2>No limits? IB API!<\/h2>\n\n\n\n<p>Why do we <strong>need more<\/strong>? Isn&#8217;t it enough?<\/p>\n\n\n\n<p>No. You already read that Yahoo isn&#8217;t for bigger amounts of stock data. And what about the trading itself? <strong>Wouldn&#8217;t it be marvelous to scan for good setups and to set the calculated orders directly?<\/strong><\/p>\n\n\n\n<p>Of course! And that is what&#8217;s <strong>possible with the API of Interactive Brokers<\/strong> (IB).<br><em>To be correct I must mention that the IEX Cloud and Quantopian can both be used also to trade live. But you know: I do not like them. And I already use IB as my broker (= cheap, all in one place and an ugly antiquated trading software \ud83d\ude09 ; the app is getting better and better).<\/em><\/p>\n\n\n\n<p>I will <strong>just focus on handling historical data<\/strong> because that&#8217;s the title of this article. But because it isn&#8217;t easy to install the official API and to handle the objects, <strong>more articles<\/strong> about IB and its API will follow.<\/p>\n\n\n\n<h3>Tricks for the IB API<\/h3>\n\n\n\n<p>Nevertheless, a few important things:<\/p>\n\n\n\n<ul><li>Activate the <strong>Read-Only-Mode<\/strong> in your Setup. Then it isn&#8217;t possible to set orders or do anything what would change your portfolio.<\/li><li>TWS or the Gateway <strong>must be open<\/strong> for getting access to the API.<\/li><li>The official API (unlike the easier but less powerful module <code>ibPy<\/code>) is <strong>object-oriented<\/strong>. You cannot write the code from top to bottom. There are &#8220;Threads&#8221; running catching the data you want.<\/li><li>It&#8217;s much easier at the beginning to <strong>use a frame of code<\/strong> and add some features step by step than building everything for your own.<\/li><\/ul>\n\n\n\n<h3>The module importing section<\/h3>\n\n\n\n<p>For the IB API we need <span style=\"text-decoration: underline;\">more modules<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ibapi.wrapper import EWrapper\nfrom ibapi.client import EClient\nfrom ibapi.contract import Contract\nfrom ibapi.common import BarData, TickerId\n\nimport pandas as pd\nfrom datetime import datetime<\/code><\/pre>\n\n\n\n<p>The <code>EWrapper<\/code> and <code>EClient<\/code> are the <span style=\"text-decoration: underline;\">main classes<\/span> (<em>you will learn more about classes later in a separate article<\/em>) of the API. <code>Contract<\/code> is a data type (also a class) for contracts like stocks, currencies, futures and options. And <code>BarData<\/code> and <code>TickerId<\/code> are used for functions within our code.<br>To make it easier for later projects you can import all parts of a module with <code>from ibapi.common import *<\/code>.<br>The last two modules are well-known from above.<\/p>\n\n\n\n<h3>The main class for API projects<\/h3>\n\n\n\n<p>When you do not need the individual classes you can combine <code>EWrapper<\/code> and <code>EClient<\/code> to one class. Here is the <span style=\"text-decoration: underline;\">basic class<\/span> with the <code>__init__<\/code> function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class ibApp(EWrapper, EClient):\n    def __init__(self, ipaddress, portid, clientid):\n        EWrapper.__init__(self)\n        EClient.__init__(self, wrapper=self)\n\n        self.connect(ipaddress, portid, clientid)\n\n        self.data = pd.DataFrame(columns=&#91;'Open', 'High', 'Low', 'Close', 'Volume'])<\/code><\/pre>\n\n\n\n<p>Whenever a variable is declared as <code>ibApp<\/code> (you can use another name if you want), the <code>__init__<\/code> function is called. Here both basic classes (it&#8217;s called <span style=\"text-decoration: underline;\">inheritance<\/span>) are initialized, the function <code>connect<\/code> of the class <code>ibApp<\/code> is called (it&#8217;s in the library, so we do not need it here but we have to set three parameters: the IP address, the port and the client ID) and I already added the initialization of our <code>DataFrame<\/code> we want to get filled.<\/p>\n\n\n\n<p><strong>By using inherited classes you can add your own lines of code to the functions but you do not have to.<\/strong><\/p>\n\n\n\n<h3>And the main code<\/h3>\n\n\n\n<p>Yes, I call it the main code but it&#8217;s only the <span style=\"text-decoration: underline;\">outer frame<\/span> of the code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def main():\n    try:\n        app         = ibApp(\"127.0.0.1\", 7496, 999)\n\n        tickerId    = 4000\n        stock       = setContract(\"XOM\")\n        date_format = \"%Y%m%d %H:%M:%S\"\n        endDateTime = datetime.now().strftime(date_format)\n        duration    = \"1 Y\"\n        candleSize  = \"1 day\"\n\n        app.reqHistoricalData(tickerId, stock, endDateTime, duration, candleSize, \"TRADES\", 1, 1, False, &#91;]) \n\n        app.run()\n    except Exception as e:\n        print(\"It's a mistake, I am sorry ({}).\".format(str(e)))\n    finally:\n        app.disconnect()\n\nif __name__ == '__main__':\n    main()<\/code><\/pre>\n\n\n\n<p>To shorten the explanation:<br>Our main class is initialized with the parameters (<em>the port must be the same as entered in TWS\/Gateway setup!<\/em>), a contract and the start and end of our data stream are set, the <span style=\"text-decoration: underline;\">request as well as the app is started<\/span> and we catch some errors.<\/p>\n\n\n\n<p>For a better overview I <span style=\"text-decoration: underline;\">outsourced to set the contract<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def setContract(CSymbol, CSecType=\"STK\", CExchange=\"ISLAND\", CCurrency=\"USD\"):\n    stock = Contract()\n    stock.symbol = CSymbol\n    stock.secType = CSecType\n    stock.exchange = CExchange\n    stock.currency = CCurrency\n\n    return stock<\/code><\/pre>\n\n\n\n<p>An interesting point is the exchange of the contract. Instead of selecting the right exchange (like NYSE or NASDAQ) you simply set <code><span style=\"text-decoration: underline;\">\"ISLAND\"<\/span><\/code><span style=\"text-decoration: underline;\"> for US stocks<\/span>. For German stocks it&#8217;s <code>\"IBIS\"<\/code> (the former name for XETRA) most of the time. <\/p>\n\n\n\n<h3>But what about IB&#8217;s historical stock data?<\/h3>\n\n\n\n<p>The code can already be started, but nothing would happen. Okay, you&#8217;ll see some lines with the results of checking the market data. But what about the results of our request in the <code>__init__<\/code> function?<\/p>\n\n\n\n<p>Two functions (part of the <code>ibApp<\/code>-class) are called as a <span style=\"text-decoration: underline;\">result of our request<\/span> and we have to include them and add our own code elements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    def historicalData(self, reqId:int, bar: BarData):\n        row = &#91; bar.open, bar.high, bar.low, bar.close, bar.volume ]\n        self.data.loc&#91; datetime.strptime(bar.date, \"%Y%m%d\").strftime(\"%Y-%m-%d\") ] = row\n\n    def historicalDataEnd(self, reqId: int, start: str, end: str):\n        super().historicalDataEnd(reqId, start, end)\n\n        print(self.data.tail())\n        print(type(self.data))\n\n        self.done = True<\/code><\/pre>\n\n\n\n<p>Every moment one data package of a candle is received by our code the function <code>historicalData<\/code> is called. We can find the historical stock data for one candle in the variable <code>bar<\/code>.<br>So we sort this candle data as a <code>row<\/code> and add it to our <code>DataFrame<\/code> with the new formatted date as index.<\/p>\n\n\n\n<p>When this process is finished and all candles are received <code>historicalDataEnd<\/code> is called. And because in this moment we do not need anything anymore we can show the last 5 candles, the type of the variable as above and then tell the class that <span style=\"text-decoration: underline;\">we&#8217;re done<\/span> with everything and finish our program.<\/p>\n\n\n\n<p><strong>Complicated?<\/strong> Yes!<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>But you know already what&#8217;s possible with the IB API. It&#8217;s hard to understand the <strong>complex object-oriented and thread-controlled API system<\/strong>. For some challenges you have to change the source code of the module for yourself.<br>The complexity is based on <strong>almost direct access to the interactions with the IB servers<\/strong>. Therefore, the scope of all functions is enormous. <strong>Everything is possible!<\/strong><\/p><\/blockquote>\n\n\n\n<p>Of course, I will write more detailed articles about the parts of coding with the IB API. And more features will follow: Requesting <span style=\"text-decoration: underline;\">fundamental data<\/span>, details about your current <span style=\"text-decoration: underline;\">running trades<\/span> and <span style=\"text-decoration: underline;\">order setting<\/span>.<br>And to be informed about every new article and theme you should enter your email address in the form on the right and <strong>subscribe to our newsletter<\/strong>. We would be happy to send you the news!<\/p>\n\n\n\n<p>Happy coding with the two methods of this article!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the first three articles about coding with financial data (How to code a backtest, How to code a basic stock scanner and How to code the first indicators) I did not mention how to get historical stock data. You will know about it after reading this article! \ud83d\ude42 Historical stock data To create a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":231,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":""},"categories":[7],"tags":[49,50,20,55,48,25,52,53,54,21,29,51],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get historical stock data - The Market and Us<\/title>\n<meta name=\"description\" content=\"Here you can learn how to get historical stock data. Read about your possiblities like Yahoo, Interactive Brokers (IB) and others with concrete code\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get historical stock data - The Market and Us\" \/>\n<meta property=\"og:description\" content=\"Here you can learn how to get historical stock data. Read about your possiblities like Yahoo, Interactive Brokers (IB) and others with concrete code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/\" \/>\n<meta property=\"og:site_name\" content=\"The Market and Us\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-10T00:02:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-08T10:27:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/market-and-us.com\/blog\/wp-content\/uploads\/2019\/11\/robot-playing-piano.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"967\" \/>\n\t<meta property=\"og:image:height\" content=\"725\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"9 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/market-and-us.com\/blog\/#website\",\"url\":\"https:\/\/market-and-us.com\/blog\/\",\"name\":\"The Market and Us\",\"description\":\"Weekly Analysis of the Stock Market, Financial Coding and Online-Tools\",\"publisher\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/#\/schema\/person\/f32a93c5a88a9ec9a9595fff6179b097\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/market-and-us.com\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/market-and-us.com\/blog\/wp-content\/uploads\/2019\/11\/robot-playing-piano.jpg\",\"contentUrl\":\"https:\/\/market-and-us.com\/blog\/wp-content\/uploads\/2019\/11\/robot-playing-piano.jpg\",\"width\":967,\"height\":725,\"caption\":\"We can control our historical data like the robot the piano.\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#webpage\",\"url\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/\",\"name\":\"How to get historical stock data - The Market and Us\",\"isPartOf\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#primaryimage\"},\"datePublished\":\"2019-11-10T00:02:27+00:00\",\"dateModified\":\"2021-04-08T10:27:54+00:00\",\"description\":\"Here you can learn how to get historical stock data. Read about your possiblities like Yahoo, Interactive Brokers (IB) and others with concrete code\",\"breadcrumb\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/market-and-us.com\/blog\/\",\"url\":\"https:\/\/market-and-us.com\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#webpage\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#webpage\"},\"author\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/#\/schema\/person\/f32a93c5a88a9ec9a9595fff6179b097\"},\"headline\":\"How to get historical stock data\",\"datePublished\":\"2019-11-10T00:02:27+00:00\",\"dateModified\":\"2021-04-08T10:27:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#webpage\"},\"commentCount\":9,\"publisher\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/#\/schema\/person\/f32a93c5a88a9ec9a9595fff6179b097\"},\"image\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#primaryimage\"},\"keywords\":[\"candles\",\"candlesticks\",\"code\",\"explanation\",\"historical data\",\"how to code\",\"IB\",\"Interactive Brokers\",\"pandas\",\"Python\",\"stock\",\"Yahoo\"],\"articleSection\":[\"Knowledge\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/market-and-us.com\/blog\/how-to-get-historical-stock-data-212\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/market-and-us.com\/blog\/#\/schema\/person\/f32a93c5a88a9ec9a9595fff6179b097\",\"name\":\"Alexander\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/market-and-us.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/market-and-us.com\/blog\/wp-content\/uploads\/2019\/10\/redakteur-96x96.png\",\"contentUrl\":\"http:\/\/market-and-us.com\/blog\/wp-content\/uploads\/2019\/10\/redakteur-96x96.png\",\"caption\":\"Alexander\"},\"logo\":{\"@id\":\"https:\/\/market-and-us.com\/blog\/#personlogo\"},\"description\":\"Alexander bought his first stock in October 2009 without knowing about the luck for this point of time. In 2016 he started to trade, since 2017 he notes down watchlists and statistics every day and because he knows how to code since he was a child, he uses Python, PHP, HTML5 and JS for making the daily to-dos easier. Because many of his friends wanted him not to stop writing about the markets he started this blog to share his ideas and tools.\",\"sameAs\":[\"https:\/\/market-and-us.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yasr_visitor_votes":{"number_of_votes":0,"sum_votes":0,"stars_attributes":{"read_only":false,"span_bottom":false}},"_links":{"self":[{"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/posts\/212"}],"collection":[{"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":19,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":737,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/posts\/212\/revisions\/737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/media\/231"}],"wp:attachment":[{"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/market-and-us.com\/blog\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}