I want to develop a small application to get stock price from Google Finance automatically and store it in my local machine for future analysis.
Can anyone give me some clue how to get started?
I know some C#. Will it be suitable for this purpose?
Thank you in advance.
The Google Finance Gadget API has been officially deprecated since October 2012, but as of April 2014, it's still active:
http://www.google.com/finance/info?q=NASDAQ:ADBE
Note that if your application is for public consumption, using the Google Finance API is against Google's terms of service.
This gives a JSON response which can be parsed using a simple JSON parser in C# after chopping off the first two chars ('//').
For downloading historic data again, you could use the Google APIs.
http://www.google.com/finance/historical?q=NASDAQ:ADBE&startdate=Jan+01%2C+2009&enddate=Aug+2%2C+2012&output=csv
gives out a CSV of end of day stock prices from startdate to enddate. Use a simple CSV parser to get meaningful data out of this stored on your db. However, this format=csv option does not work for a few stock exchanges.
If you want to download historical data you can use the Google Finance API (which still works as of May 2016). You do not have to provide an end date, it will automatically fetch data from the start date (or later if the stock did not trade then) to the last full trade date:
http://www.google.com/finance/historical?q=NASDAQ:AAPL&startdate=Jan+01%2C+2000&output=csv
Remember that Google Finance API are for personal consumption ONLY. I suggest you their terms of service.
If you want to simply download the latest date (which could be useful to update your local db) you can use the googlefinance library developed by Hongtao Cai:
https://pypi.python.org/pypi/googlefinance
I have just implemented this with PHP. It might be useful.
<?php
echo readGoogle('AAPL', 'Aug+21%2C+2017', 'Aug+22%2C+2017');
function readGoogle($ticker, $startDate, $endDate) {
$fp = fopen("http://finance.google.com/finance/historical?q=".$ticker."&startdate=".$startDate."&enddate=".$endDate."&output=csv", 'r');
if (FALSE === $fp) return 'Can not open data.';
$buffer = '';
while (!feof($fp)) $buffer .= implode(',', (array)fgetcsv($fp, 5000));
fclose($fp);
return $buffer;
}
?>