分享

Finance APIs

 maoj66 2014-03-10

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.

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 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:

http://query./v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%22GLD,SLV%22%29&env=store://datatables.org/alltableswithkeys

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

http://www./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./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:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多