Using Yahoo's Finance API
It was surprisingly hard to find a simple straight forward stock API; this community built API hosted by Yahoo does the job.
Let's get to it.
Below is a complete URL example if you want to play on your own and figure it out.
Theres an awesome interactive dashboard that you should play with. If you still need a breakdown on what's happening, then keep reading.
Let's digest the url.
All urls have a
BASE and then
Parameter sequence starts with a
? and are delimited with an
So you would have something like:
This is the
Then comes the first parameter, the
QUERY. This query is not directly
SQL instead its something Yahoo calls Yahoo Query Language or
YQL. For the purposes of the activity; they are very similar and hence straightforward.
The above query translates into
SELECT * FROM yahoo.finance.quotes WHERE SYMBOL IN ("AAPL").
The reason the
%20's are there is because to send the space character through a browser it needs to be
URL Encoded, but you probably won't be needing to do that.
Note: We are selecting everything with
SELECT * ... but we can also select specific field(s). For the project we only really want
LastTradePriceOnly so we can say
SELECT LastTradePriceOnly ... and its way cleaner.
The final parameter is
&env=store://datatables.org/alltablewithkeys. So long as you include this you will be ok. The reason this is needed is because it's a community kept database so it needs a specific