Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

How to Get Realtime Stock Data From Google

1 min read

Sometime back we discussed about how to get Intraday backfill data from Google and this short article focus on how to get Realtime stock data from Google. Google provides realtime cash market/index/currency data for most of the markets in JSON format.

google realtime

 
Url format to retrive Realtime Quotes

http://www.google.com/finance/info?q=AAPL
http://www.google.com/finance/info?q=NSE:NIFTY

You can get multiple quotes in a single request by comma separating the symbols on q parameter.

http://finance.google.com/finance/info?client=ig&q=NSE:NIFTY,NSE:RELIANCE

sample JSON output format for Nifty Spot Index(India)

Google finance can return stock quotes using the JSON format, with can be read programming langugages like PHP,Python,Java..etc

// [ { “id”: “207437” ,”t” : “NIFTY” ,”e” : “NSE” ,”l” : “7,329.65” ,”l_fix” : “7329.65” ,”l_cur” : “Rs.7,329.65″ ,”s”: “0” ,”ltt”:”3:31PM GMT+5:30″ ,”lt” : “May 28, 3:31PM GMT+5:30″ ,”lt_dts” : “2014-05-28T15:31:28Z” ,”c” : “+11.65″ ,”c_fix” : “11.65” ,”cp” : “0.16” ,”cp_fix” : “0.16” ,”ccol” : “chg” ,”pcls_fix” : “7318” } ]

sample python code to fetch realtime stock data

from urllib import urlopen
import json
def googleQuote(ticker):
    url = '%s%s' % ('http://www.google.com/finance/info?q=', ticker)
    doc = urlopen(url)
    content = doc.read()
    quote = json.loads(content[3:])
    quote = float(quote[0][u'l'])
    return quote
if __name__ == "__main__":
    ticker = 'GOOG'
    print googleQuote(ticker)

To fetch the data every 30th second here is the python code. The below code prints the Quote for Reliance stock on NSE every 30 seconds.

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(“RELIANCE”,”NSE”)
print quote
time.sleep(30)

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

How to Retrieve Opening Balance, Total Turnover, Realized and…

This tutorial explores how to access the limits API functionality in Algomojo using python to retrieve the Account Balance, Total Turnover, Realized, UnRealized PNL,...
Rajandran R
1 min read

Introduction to Backtrader – Creating your First Trading Strategy…

Backtrader is an open-source python framework for backtesting, optimizing, and deploying live algorithmic trading strategies.
Rajandran R
54 sec read

Getting Started with Google Colab

Google Colab also known as Google Colaboratory is a product from Google Research which allows user to run their python code from their browser...
Rajandran R
1 min read

54 Replies to “How to Get Realtime Stock Data From Google”

  1. Thanks Rajandran sir for this useful info, but i want to know you that how can i add this on blogger blogspot please reply.

    1. @Ajay, You cannot add in your blogspot blog as it doesnt support custom programming like php, python. However if you hosted in your own server with little programming skills you can get the data.

  2. please sir, can you post how to get real time date of MT4 TO AMI Broker ? The two you published before not working, can you publish for window 7 please ?

    Thank you

  3. Sir ,plz tell abt free data provider for EIOD ,real time AND EOD data provider for mcx and nse

  4. Hi…How can I pull real time mcx commodity data just like you have done it for stocks.

    Thanks

  5. Hi Rajendran, Can I pull in Silver Mini Mcx data just like you have done it for stocks! Please let me know of your ideas
    Thanks

  6. Hi,
    Can we use this data for real time Algo trading ? Is it delayed data ? And how can I get historical (atleast 1 yrs) RT data to backtest my strategies ?

    Thanks and Regards,
    Pravin

  7. Pravin – For Algo Trading Live level 3 data is required which no data providers provide you can only take through exchange itself.

    Historical data can purchased from Exchanges it self.

  8. Hello Sir,
    I want to get only Last Traded Price & Last Traded Time ,Script.
    Is there any way to do it..

    With Regards
    Ganesh

      1. Sir,
        Thanx For Your Reply.
        I am Software Engineer. By Using VB.net , I Fetch RealTime Data as
        // [ { “id”: “3302534” ,”t” : “ABAN” ,”e” : “NSE” ,”l” : “759.60” ,”l_fix” : “759.60” ,”l_cur” : “Rs.759.60″ ,”s”: “0” ,”ltt”:”9:31AM GMT+5:30″ ,”lt” : “Sep 3, 9:31AM GMT+5:30″ ,”lt_dts” : “2014-09-03T09:31:48Z” ,”c” : “+9.00″ ,”c_fix” : “9.00” ,”cp” : “1.20” ,”cp_fix” : “1.20” ,”ccol” : “chg” ,”pcls_fix” : “750.6” } ,{ “id”: “11787956” ,”t” : ”

        Actually I need to fetch only t , L_Fix and lt DTs Parameter

        How to do It?
        With Regards
        Ganesh

  9. Hi,

    I am using above url to get real time data. I figured out all values except ”s”: “0” tag. Any idea what it stands for?

    Also, if we are using this url to get data for different markets, is there anyway to determine if markets are open or closed?

    Thanks.

    1. I figured out “s” tag, “s” stands for session possible values are “0” (zero) – normal market, “1” – pre-market and “2” – after hours.

      Still need to figure out, how to determine that market is closed … especially needed for markets where there is no pre-market or after hours trading

  10. Hi guys,
    some help required. I tried above script. when i run in python i am getting the following error.
    quote = c.get(“RELIANCE”, “NSE”)
    AttributeError: GoogleFinanceAPI instance has no attribute ‘get’

    Did i miss some thing. thanks in advance.
    srini

  11. How can I get stock symbols of google finance and yahoo finance for my code. ( E,g Google Finance NSE:RELIANCE ; Yahoo finance : yhoo

  12. How do I get data for few months
    For example if I want data for last 6 months .
    How should I modify the above command ?

  13. Hi,
    First of all thank you for such an informative site. My question is – how to get All 5000+ srcips on BSE and their last traded prices?
    This of course has to be in one shot every minute or so, not iteratively.

    Thank in advance.
    Regards,
    Anand.

  14. Kind attention Mr Lokesh Madan…..

    Dear sir, I am a practicing doctor and pretty much of a novice with regard to Algo trading in equity markets, though i have been trading since quite some time and have read about it quite a lot. I request your good-self to please suggest to me whether one could set up an independent algo trading co-located facility, if one were to have a broker’s license and what would be the approx costs.Any details about it is welcome.

  15. I use following code in my javascript and works perfectly fine.

    var googData = “http://finance.google.com/finance/info?client=ig&q=NSE:”+KEY.nseCode+””;
    $.get(googData, function(data){
    var jsonElement = data.replace(“//”,””).replace(“[“,””).replace(“]”,””);
    var jsonVar = JSON.parse(jsonElement);
    var instr = jsonVar.l;
    var pnum = instr.replace(“,”,””);
    var stPrice = parseInt(pnum);
    });

    -neo

    1. Hi What was the value substituted for KEY.nseCode. I want to get only last trade symbol voulme, StockExchange, earnings/share, divdend, AvgVol(3m). Any idea what is the google finance support for this requirement? Thanks in advance.

  16. How to get quote values like CLOSE,HIGH,LOW,OPEN,VOLUME realtime.What are the fullform of all the json keys. (example e = Exchange)

  17. Excelent work Rajandran, thanks a lot.

    I’m using it on php and it is working awesome, but I would like to get some other parameters like EPS and PERatio…is it possible to get them? Do you know how?

    Thanks a lot!!

  18. Dear Mr. Rajendran,
    Your work is very much interesting.
    I would like to integrate live chart OR end of the chart (NSE(FUTURE,CASH),MCX,SENSEX) in my web site. how to do it using iframe.
    Please help me.
    thanks in advance.

  19. Hi Rajandran, first of all, i would like to thank you for this post. I tried using above URLs but now i think it stopped working, so i tried using this link: https://www.google.com/finance/getprices?i=1&p=1d&f=d,o,h,l,c,v&df=cpct&x=NSE&q=VEDL,RELIANCE to get data of multiple stocks, but it returns merely this:

    EXCHANGE%3DNSE
    MARKET_OPEN_MINUTE=555
    MARKET_CLOSE_MINUTE=930
    INTERVAL=1
    COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
    DATA=

    Any solution on how do i retrieve data for multiple symbols?

      1. Hi Rajendran ,

        Programmatically when I tried it is not working .Was there any change in the URL parameters.

        Also Vedl/ IGL it is giving NYSE rates

        please verify and let us know .

        Regards,
        L

  20. HELLO,

    I NEED TO FILTER DATA IN REALTIME FROM GOOGLE FOR A PARTICULAR PRICE TREND FOR INTRADAY TRADE.

    COULD YOU PLEASE HELP HOW TO DO THAT

  21. You should used MarketXLS.
    They have regular updates and customer support.
    It cost a little but it would save you time.
    Hope it helps.

  22. This no longer works. Can you please check, is there any other way to capture the google online feed?

  23. Hi , These services are not in operation now, recently google has halted these services, Can any one please suggest any free/paid alternatives for this

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More