views:

310

answers:

2

Hello,

I am trying to get the realtime stockquotes from google for some time now. First I try'd the finance api, but that didd'nt work out.

Then I saw this query and it seems to good to be true

http://www.google.com/finance/info?client=ig&q=goog

It must have some drawbacks that I am not aware off now.

Anyway, it does give realtime, at least that what it is says on the google finance page

Does anyone know if I can add more parameters for the query like + YAHOO (this is falty) so I can get more then one stock??

Also, is the output in json or do Y have to parse it differently? I was planning to do this with curl and ajax

thanks, Richard

+1  A: 

You can just add more ticker symbols with a comma, as in:

http://www.google.com/finance/info?client=ig&q=goog,msft

The response is indeed json. There is a good discussion on Stackoverflow about using the first-class Google Finance APIs to get stock quotes here: http://stackoverflow.com/questions/527703/google-financial-api-how-get-stock-quotes

Chris Clark
Thanks for the comma. I did came across that post, I remember, Anyway there is no real good tutorial, yet, about how to get stockquotes. The current tradevalue, etc. Not straighforward anyway.
Richard
+1  A: 

comma seperate your sybols. http://www.google.com/finance/info?client=ig&q=goog,osis

runrunraygun
Thanks, do you also perhaps know what makes the json valid, because I did ltrim($string,'/') to get rid of the forward slashes?
Richard
This worked I think $response= substr(trim($response), 2);
Richard
Someone suggested the slashes are to invalidate the json, forcing you to parse it somehow (as you have done above) as some kind of security thing, but I dunno about that sort of thing :)
runrunraygun
Thanks, I got an associative array I think, I am now reading the php manuel to extract a single value.
Richard
http://en.wikipedia.org/wiki/JSON#JavaScript_eval.28.29
runrunraygun
It's an array within an array, I have read that eval is never good, if you can do it in another way. So I will explore that first.
Richard