How to Access Stock Quotes Realtime through Google Finance
Tell me already, Where are the quotes?
http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOG
The above URL gives us the latest quote for Google Shares. The Google Finance URL structure is pretty simple. The Query string q= requires the symbol of the stock you are interested in. It is of the format Exchange:Symbol. Some examples of these query strings are
- Microsoft : NASDAQ:MSFT
- Apple : NASDAQ:AAPL
- Yahoo : NASDAQ:YHOO
- Reliance (NSE of India) : NSE:RELIANCE
- Pearson (London Stock Exchange) : LON:PSE
// [
{
"id": "694653"
,"t" : "GOOG"
,"e" : "NASDAQ"
,"l" : "581.84"
,"l_cur" : "581.84"
,"s": "0"
,"ltt":"4:00PM EDT"
,"lt" : "Mar 30, 4:00PM EDT"
,"c" : "+0.11"
,"cp" : "0.02"
,"ccol" : "chg"
}
]
Getting the Quotes from the above response is much simpler than scrapping a page.
UPDATE:
http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOG,NASDAQ:YHOO
You can get multiple quotes in a single request by comma separating the symbols on q parameter.
Will come back soon with a script that does something based on this realtime data from Google Finance.
UPDATE:The Code in Python
import urllib2
import json
import time
class GoogleFinanceAPI:
def __init__(self):
self.prefix = "http://finance.google.com/finance/info?client=ig&q="
def get(self,symbol,exchange):
url = self.prefix+"%s:%s"%(exchange,symbol)
u = urllib2.urlopen(url)
content = u.read()
obj = json.loads(content[3:])
return obj[0]
if __name__ == "__main__":
c = GoogleFinanceAPI()
while 1:
quote = c.get("MSFT","NASDAQ")
print quote
time.sleep(30)
The above code prints the Quote for Microsoft stock on NASDAQ every 30 seconds.
Meanwhile all ye mates try something interesting with the stock quotes
(Than making profits and losses :) )
Dont forget to ping me on your updates. Post a comment.
Thank you Google.
Watch out!
This service is going down in October, 2012.
http://googlecode.blogspot.com/2011/05/spring-cleaning-for-some-of-our-apis.html
This is not exactly API,
This is not exactly a documented API, but something the Google finance website uses. So I suppose we should be safe.
HI Arun
How can i fetch the GOLD price from google finance.
when i go for
"http://finance.google.co.uk/finance/info?client=ig&q=NASDAQ:GOLD" it will give me price of company name with GOLD.
I want price of Gold metal.
please help.
Thanks in advance.
Sir,
A lot of thanks for this post.It is really useful.I have a doubt.How can we get days open,high,low,and last price and volume in between trading hours?
may you help me
With thanks
Gilari Decosta
Dear arun, how to redirect that data to mysql... in a realtime basis..
This is awesome, it is exactly what I have been looking for. But I want to modify it to show stock options quotes, not just the primary equity quote. (I know C, and a bit of Ruby, so I should be able to modify the code.) But I need to know what the URL looks like to get an options quote, do you know that? Please share! Thanks!
Gold ounce price
How can i get the current gold ounce price like goldprice.org/live-gold-price.html ?
look up an equivalent Gold ETF
Look for the price of an equivalent Gold ETF fund price on google for your country.PHP Version
Here's how to collect stock prices using PHP :<?php //Obtain Quote Info - This collects the Microsoft Stock Info $quote = file_get_contents('http://finance.google.co.uk/finance/info?client=ig&q=NASDAQ:MSFT'); //Remove CR's from ouput - make it one line $json = str_replace("\n", "", $quote); //Remove //, [ and ] to build qualified string $data = substr($json, 4, strlen($json) -5); //decode JSON data $json_output = json_decode($data, true); //Un-remark print_r to see all array keys //print_r($json_output); //Output Stock price array key. echo "\n".$json_output['l']; ?>
PHP
Can this script be run in PHP using the Python in PHP (PiP)?
Thanks,
TRH
Can easily port the code
You can easily port the code to PHP, not sure why you want to run python inside php.Is there some way to get
Is there some way to get Volume also?
Were you able to get the Vol as well ?
Thanks
Programming Language
Thanks. Your URL to Google is exactly what I've been looking for. What language is "The Code" written in?
Python
Ooops totally missed out that I guess. The code for getting realtime stocks from google was written using Python.