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.
[wp_ad_camp_5]
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'
%
(
'<a href="http://www.google.com/finance/info?q=">http://www.google.com/finance/info?q=</a>'
, 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'
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 timeclass 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)
Hi,
Can we have this in a downloadable format like ms word.
Thanks,
No you have to do pre processing using programs like php,python to convert into usable format.
Thanks Rajandran sir for this useful info, but i want to know you that how can i add this on blogger blogspot please reply.
@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.
please sir, can you post how to get real time data of MT4
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
Sir ,plz tell abt free data provider for EIOD ,real time AND EOD data provider for mcx and nse
sir
how can i import this real time data in amibroker
plz suggest
thanx
you need build you own data importer.
Hi…How can I pull real time mcx commodity data just like you have done it for stocks.
Thanks
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
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
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.
where are we buy Historical data ?
Hello Sir,
I want to get only Last Traded Price & Last Traded Time ,Script.
Is there any way to do it..
With Regards
Ganesh
Hello sir ,
http://finance.google.com/finance/info?client=ig&q=NSE:NIFTY,NSE:RELIANCE
If I using the above link i got so many data. Is there any way to get exact Value Like Last Traded Price,
Last Traded Time .
With Regards
Ganesh
Hi Ganesh you can create you own csv file using Kimono Labs
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
Its a Json feed. You just parse the json feed and then process it. Iam not much comfortable with VB.Net mostly we do with php and python
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.
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
Thanks for the info Hemang!
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
How can I get stock symbols of google finance and yahoo finance for my code. ( E,g Google Finance NSE:RELIANCE ; Yahoo finance : yhoo
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 ?
Have a look at this project
http://nsetools.readthedocs.org
It is very simple to use, and written in python
Hello Rajandran,
Can you suggest me how to get nse options to google sheets
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.
Get a data vendor like esignal who provides data for BSE.
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.
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
That retrieves only the current stock price data not the historical stock prices though! For retrieving historical prices visit here
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.
How to get quote values like CLOSE,HIGH,LOW,OPEN,VOLUME realtime.What are the fullform of all the json keys. (example e = Exchange)
ANYONE KNOW API FOR INDIAN MUTUAL FUNDS ?
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!!
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.
I was using it successfully, but started getting (404 Not found) error today.
It looks like google has stopped this rest functionality.
Sample url:
http://finance.google.com/finance/info?q=NSE:NIFTY
This unofficial google finance API stopped since 6th Sep 2017.
Hi , Seems like http://finance.google.com/finance/info?client=ig&q=NSE:NIFTY,NSE:RELIANCE url is not working, need to know if there is some alternative
This unofficial google finance API stopped since 6th Sep 2017.
http://finance.google.com/finance/info?client=ig&q=NSE:NIFTY is not working at all.
Google quote API is down. There is no official announcement yet. Will update here if any.
Hi Rajandran,
Below google api not working,
http://finance.google.com/finance/info?client=ig&q=INDEXBOM:SENSEX,NSE:NIFTY
Please let us know if any alternatives
Thanks in advance.
-Sunil
Google quote API is down. There is no official announcement yet. Will update here if any.
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?
You need to retrieve programatically.
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
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
CAN I TRANSFER THIS DATA IN AMIBROKER?
This article is irrelevant now , cause GOOGLE has stopped responding to this URL
You should used MarketXLS.
They have regular updates and customer support.
It cost a little but it would save you time.
Hope it helps.
This no longer works. Can you please check, is there any other way to capture the google online feed?
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