Finance APIs

Article by on April 28, 2012, last modified on August 26, 2013

There 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.



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,^GSPC&ignore=.csv

However, there are many other parameters, such as date range, that you can pass as 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:*,SLV%22%29&env=store://

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:

Yahoo Finance API Libraries

A C# Example for YQL

A PHP Example for YQL

If you are writing PHP, here is an example snippet:

$tickers = array('GLD', 'SLV');
$url = '*'.implode(',', $tickers).'%22%29&env=store://';

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:

Older Articles »