Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Devon Boyer
Devon Boyer
4,020 Points

API for Stock Market Data

Does anyone know a good API to get stock market data? I've tried to check out Yahoo Finance but I was not able to understand how to make it work at all. Anyone have any tips or advice? Thanks! (I am looking to build an iOS app with the data)

1 Answer

Devon I would suggest visiting http://www.jarloo.com/yahoo_finance/ .

Based on the article the Yahoo Finance API is rest based. Meaning you make a call to the base string http://finance.yahoo.com/d/quotes.csv followed by the query string ?s=<query>&f=<financial data>. Where <query> is the stock symbol you're looking to perform a lookup against and <financial data> would refer to the financial data you're seeking ie name, pricing, dividends, date etc. This same article includes a table of all the financial data you can retrieve.

The example URL in the article used http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=nab would retrieve the name, ask, and bid for the stock symbols APPL, GOOG, and MSFT in CSV format.

Additionally I would check out http://www.jarloo.com/get-yahoo-finance-api-data-via-yql/ to learn how to get data in XML or JSON as opposed to CSV. Note that the base string here is a bit different http://query.yahooapis.com/v1/public/yql?q= <YQL Statement>&env=store://datatables.org/alltableswithkeys . Where <YQL Statement> is based on Yahoo's Query Language. In the example in the article, the statement used to query the symbol AAPL stock information is select * from yahoo.finance.stocks where symbol=”aapl” .

Lastly, by default the URL http://query.yahooapis.com/v1/public/yql?q= <YQL Statement>&env=store://datatables.org/alltableswithkeys would return XML unless you add &format=json into the URL. Hope this betters your understanding of the Yahoo Finance API.

Devon Boyer
Devon Boyer
4,020 Points

Wow thank you for the amazingly detailed answer!! This definately helps ;)