Skip to content

Instantly share code, notes, and snippets.

@border
Created October 28, 2011 07:03
Show Gist options
  • Save border/1321781 to your computer and use it in GitHub Desktop.
Save border/1321781 to your computer and use it in GitHub Desktop.
Access Stock Quotes Realtime through Google Finance
import urllib2
import json
import time
# Form: http://digitalpbk.com/stock/google-finance-get-stock-quote-realtime
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)
@amejiarosario
Copy link

curl http://finance.google.com/finance/info\?client\=ig\&q\=CSCO

// [
{
"id": "99624"
,"t" : "CSCO"
,"e" : "NASDAQ"
,"l" : "29.82"
,"l_fix" : "29.82"
,"l_cur" : "29.82"
,"s": "0"
,"ltt":"1:46PM EDT"
,"lt" : "Jul 19, 1:46PM EDT"
,"lt_dts" : "2016-07-19T13:46:16Z"
,"c" : "-0.09"
,"c_fix" : "-0.09"
,"cp" : "-0.30"
,"cp_fix" : "-0.30"
,"ccol" : "chr"
,"pcls_fix" : "29.91"
}
]

@RobertDurfee
Copy link

Unfortunately, this no longer works. Google removed this feature or at least relocated it to a new URL (unknown to me).

@econofutmist
Copy link

It no longer works. But I wonder why Google doesn't want to share the data with people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment