Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with Google Finance?

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.

like image 854
Edward D. Avatar asked Jul 17 '12 05:07

Edward D.


People also ask

Does Google Finance still work?

It's able to take REST requests, and it returns the desired data in JSON format. To reiterate, the Google Finance API is no longer supported by Google so it's undocumented and unreliable.

Is Google Finance free to use?

This is simple and free to set up — and even easier if you already have a Gmail address. Once you have secured your account, you can immediately set up your Google Finance portfolio.


3 Answers

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.

like image 66
rajaram_s Avatar answered Sep 21 '22 23:09

rajaram_s


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

like image 34
Henry Avatar answered Sep 19 '22 23:09

Henry


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;

}

?>
like image 42
grc Avatar answered Sep 18 '22 23:09

grc