IMPORTANT: On 2 November 2017, Yahoo blocked access to the CSV API. No solution is yet
Editor's Note: This software is non-commercial and for personal use only. No support is available.
Yahoo! and Google both unofficially provide a free way to download stock quotes using an API.
Financial data can be downloaded in a CSV, imported into an existing Excel Spreadsheet, or downloaded in XML / JSON formatted data to display on a website using the Yahoo! Query Language (YQL) API.
Share price data can be imported into an existing Excel spreadsheet or downloaded in a JSON string for use on a website.
This article will cover two uses of the Yahoo! Finance API.
Displaying share price data on a website (even delayed data) usually requires a license from the relevant stock exchange/s.
The Google Finance API was officially deprecated in June 2011. It may cease to work at any time.
The Yahoo Finance API is not officially supported and prone to “glitches” and inaccurate data. Use for commercial reasons may result in a breach of Yahoo!’s T&Cs.
Yahoo! Finance provides the simplest way to import financial data into a spreadsheet. The data (including stock prices, indices and company fundamentals) can be automatically downloaded in a CSV by simply entering a URL into your browser’s address bar. The CSV can then be opened in Excel and manipulated as required.
Real-time data is limited to a few US exchanges and most countries have a 10-30min delay due to licensing restrictions.
Start with the base URL: http://download.finance.yahoo.com/d/quotes.csv
Add ?s= to your base URL followed by the stock symbols you want to download.
To download multiple companies at once, simply use the “+” sign in between the company codes.
The above URL will call:
• Australian All Ordinaries Index
• BHP Billiton Ltd in Australia
• BHP Billiton Ltd in UK
• Apple Inc. in USA.
How to Find the Correct Stock Code
All listed companies have a stock ticker between 1 and 4 characters. E.g. Apple has the stock ticker AAPL.
As there are multiple exchanges around the world, you must specify which exchange your code relates to by adding a suffix.
• Australian listed companies require the suffix “.AX” to be added to the companies stock code (e.g. BHP.AX).
• UK listed companies require the suffix “.L” to be added to the companies stock code (e.g. BLT.L).
Note: Most US listed companies do not require a suffix
Most stock indices use a “^" prefix prior to the index code along with a country identifier.
• The Australian All Ordinaries index has the prefix “^A” (e.g. ^AORD).
• The NASDAQ Composite uses the code “^IXIC”.
To find the correct suffix for a company or prefix for an index, visit https://finance.yahoo.com and start typing the name of the company into the “Look Up” box.
Add &f= to your URL string followed by the Yahoo! Tags for the data you want to download.
The above URL will fetch:
• Last Trade Date
• Last Trade Price
Applicable to the most recent trading day (including today).
|d1||Last trade Date|
|t1||Last trade Time|
|l1||Last trade Price|
|k3||Last trade Size|
|p2||Change in Percent|
|a2||Average Daily Volume|
52-week data only.
|k4||Change From 52-week High|
|j5||Change From 52-week Low|
|k5||% Change From 52-week High|
|j6||% Change From 52-week Low|
Dividend and Target Price data are not always available and often restricted to US listed companies.
|r1||Dividend Pay Date|
|t8||1 yr Target Price|
The 50 and 200 day moving averages are two of the most commonly used indicators in the finance industry.
|m3||50-day Moving Average|
|m4||200-day Moving Average|
|m5||Change From 200-day Moving Average|
|m6||Percent Change From 200-day Moving Average|
|m7||Change From 50-day Moving Average|
|m8||Percent Change From 50-day Moving Average|
Enter the above URL strong into your browser’s address bar and hit return/enter. The CSV will be automatically downloaded to your computer.
Excel provides a simple way to download financial data into a preconfigured spreadsheet at the click of a button.
Only advanced users can create a spreadsheet as Macros are required to download the data. For the less tech-savvy, here's a spreadsheet that will do the hard work for you.
You will get two warnings when you open the file:
1. The workbook contains Marcos (to process the data)
2. The workbook requires a data connection (to download data from the internet - duh!)
You must accept/enable both for the spreadsheet to work. The Macros are not password protected so you are free to view and manipulate all code anyway you like.
The Spreadsheet is in XLS so it’s backwards compatible to MS Excel 97. Saving it as an .XLSX will break the spreadsheet.
Don’t forget to add the correct suffix or prefix as detailed above.
A few caveats:
• Dow Jones data will not import due to licensing restrictions.
• Financial data (e.g. dividends, ratios and target prices) are often only available for US listed companies.
• Most exchanges have a delay on their data of 10 - 30mins.
• You’re limited to calling 200 codes at a time.
Enter the Yahoo! Tags for the information you want to download into cell C2. The data will be displayed in the order you specify in the Yahoo! Tag string. You will need to rename the column headers to match the order of the tags you specified in C2.
You can use the Yahoo Finance API to import data into Google Docs (Sheets) by using the =IMPORTDATA function. For example: