Yahoo Finance API

Is there such a thing as the Yahoo Finance API?

Initial research into the fabled Yahoo Finance API reveals that this is a bit of a misnomer, because there are several ways in which financial quotes can be extracted from various yahoo sites, most (all?) of which are not officially approved for redistribution.

Nevertheless, screen-scrapers and developers of various ilk have reverse-engineered the yahoo finance portal which provides free financial quotes, and created poor-man financial data feeds for individual usage. In principle, this should be no different from checking the finance portal page compulsively with a browser, and should not violate the Yahoo terms of usage, if you are developing a personal app for private usage.

If you intend to make this app available to your large extended family, and all your myFace friends, or if you intend to develop a commercial application, I would recommend that you do further investigation on the legal requirements surrounding redistribution of this data.

There are three ways that I have found to extract quotes from yahoo:

  • Using the Yahoo Query Language web service
  • Using the CSV quote api
  • Hacking the yahoo finance portal streaming API

These are described in the following sections.

Accessing via the Yahoo Query Language (YQL) web service

A description and documentation on the YQL Web Service can be found in the API & Tools section of the Yahoo Developers Network.

In a nutshell, the YQL Web Service makes it possible to query and mash data from different sources across the internet, using a SQL-like syntax which will be intuitive to developers familiar with the Structured Query Language (SQL) used to query relational databases.

The following YQL statement, for example, makes it possible to retrieve financial quotes from the YQL Console:

select * from where symbol in (“YHOO”,”AAPL”,”GOOG”,”MSFT”)

To access the YQL Web Service, a Web application can call HTTP GET, passing the YQL statement as a URL parameter, for example: * from where symbol in (“YHOO”,”AAPL”,”GOOG”,”MSFT”)&env=

Of course, that won’t quite work because the query has to be url-encoded. See the link’s href attribute for the full url-encoded link. Using the command-line utility curl makes this simple:

$ curl
-d 'select * from where symbol in

The main drawback of this approach is that the quotes have to be polled repeatedly to detect price changes during the day.

The YQL service has a streaming feature that makes it possible to stream the data, if the underlying data source has been configured to provide this feature.

In order to access this feature, the following url would have to be requested instead:

Note the additional ‘streaming’ in the context path. An attempt at streaming financial quotes by invoking:

$ curl -s -o - -N

-d 'select * from where symbol in

was not successful. I infer this to mean that streaming of the data source has not been configured. Please comment if you are able to get this to work.

Streaming quotes by hacking

If you feel that you really must have streaming quotes, the blog post Bringing the yahoo finance stream to the shell provides a recipe on how to do that by hacking the web service on which the Yahoo Finance Portal relies to provide streaming financial data.

Note that the behavior of that api appears to be tightly coupled with the Yahoo Finance Portal, and not meant to be used as a stand-alone api. Use at your own risk.

Downloading quotes in CSV format via

Lastly, one can access an api at directly which returns data in a Comma Separated Values (CSV) format suitable for importing into a spreadsheet. This API seems to be an older api, and I would presume that most developers would prefer the more modern json/xml interface that YQL provides, described above. Nevetheless, I include it here for completeness.

The general idea is to send a query such as:
a LIST of STOCK SYMBOLS separated by "+"

for example:

This api is not officially documented by Yahoo, and used to be documented by Pietro Ponzo at:

Sadly, it appears that Pietro ran afoul of Yahoo’s Terms of Service, and had to take down this page.

So, there you go, two and a half ways to get free financial data for personal use from Yahoo. When it comes to financial data, it is possible to obtain recent financial price data for free when it comes to data that is already widely available. Nevertheless you will have to pay if you want to get the data more reliably, get realtime data, or get financial data from more exotic markets.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>