Finance APIs
Article by
on April 28, 2012, last modified on August 26, 2013There are two main free finance API's that I know of: Yahoo and Google. I prefer Yahoo's Finance API over Google's simply because it offers more data. Arguably, it could also be said that it is easier to use. However, I do not know what the terms of use on the APIs are.
Yahoo
Overview
There are two options I know of for Yahoo's Finance APIs: CSV and YQL. The CSV API is great for getting historical data and YQL is great for getting the latest data in bulk. As I will mention later, there are a few other alleged Yahoo APIs that I haven't tested out.
Yahoo CSV Finance API
As Vitalyson explained on a StackOverflow comment, you can send a request to Yahoo's CSV API and get historical data. For example,
http://ichart.finance.yahoo.com/table.csv?s=^GSPC&ignore=.csv
However, there are many other parameters, such as date range, that you can pass as gummy-stuff.org explains.
Yahoo YQL Finance API
You can send a YQL query to Yahoo's API which returns an XML document. An example query request looks like:
They also show how to do this in a post on the YQL blog.
Other Yahoo Finance APIs
As mentioned, there are several other alleged finance APIs that Yahoo has, but I haven't tested them:
- The following URL seems to be an API, and vikku.info has written some specs on it; example: http://download.finance.yahoo.com/d/quotes.csv?s=GLD&f=snl1c1p2&e=.csv
- Ben Simon wrote a good post on the following URL that also seems to be an API; example: http://finance.yahoo.com/d/quotes.csv?s=RHT+MSFT&f=sb2b3jk
- Apparently you can use what looks like Google's API through YQL: http://developer.yahoo.com/yql/console/?q=select%20*%20from%20google.igoogle.stock%20where%20stock%3D'ibm'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
- Here is a whole list of other CSV APIs: http://code.google.com/p/yahoo-finance-managed/wiki/CSVAPI
- Another Yahoo API for charts; example: http://chart.finance.yahoo.com/z?s=GOOG
- The Yahoo Finance feeds seems to be no longer in service: http://feeds.finance.yahoo.com/rss/2.0/headline (source)
Yahoo Finance API Libraries
A C# Example for YQL
http://www.jarloo.com/get-yahoo-finance-api-data-via-yql/
A PHP Example for YQL
If you are writing PHP, here is an example snippet:
$tickers = array('GLD', 'SLV'); $url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%22'.implode(',', $tickers).'%22%29&env=store://datatables.org/alltableswithkeys';
And then make an HTTP request to that URL in your code.
YahooFinanceAPI (for PHP)
I wrote a simple YahooFinanceAPI script on GitHub that supports YQL. I have not contributed to it in a long time, but I welcome any collaborators. Here is an example of how to use it:
$y = new YahooFinanceAPI; $tickers = array('SLV','GLD'); $data = $y->api($tickers);
Yahoo! Managed (for .NET)
There is a seemingly well put together program for Yahoo's webservice in general that includes the finance APIs on Google Code called Yahoo! Managed. It could also be used for code examples.
Google Finance API
Officially, it would seem that Google has discontinued their Finance API. However, they do have support for Google Finance data in their Google Docs using the GoogleFinance() function (example).
Also, Digitalpbk describes an API that seems to still work (example). In addition, it looks like their iGoogle API still works too (example).
Other Finance APIs
I have not tried any of these:
- Financial Content has a JSON API.
- open exchange rates
- a list of 25 others