Get real time stock values using Yahoo Finance and Google Finance API in Liferay



This post will describes how you can retieve real time stock values in your application by using different services like Google , yahoo etc. I am aware about two ways by which we can retrive real time stock values. Lets go one by one.

1) Get real time stock values using Yahoo finance API

 Yahoo provides such a wonderful api to fetch stock data. Basically what they will do they will provide you one URL you need to pass your stock code with that URL and in resonse you will get current market price of that particular stock. Response of that service may be CSV file or Json string that things you need to mention in URL you are passing.

 Below is the example URL
http://finance.yahoo.com/d/quotes.csv?s=" +symbol + "&f=sl1d1t1c1ohgv&e=.csv
forget about the parameters in this URL right now as a response this URL will return stock data in comma separated manner.
 e.g
 "STOCK_SYMBOL", 29.55, "8/30/2011", "9:34am"

 How you can use this URL in Liferay ?
String text = HttpUtil.URLtoString("http://finance.yahoo.com/d/quotes.csv?s=" +symbol + "&f=sl1d1t1c1ohgv&e=.csv");
Use HttpUtil class of liferay to get response of the URL that you are passing. you can get more idea about this like how to pass parameter , whats the meaning of each and every parameter from this URL Yahoo Finance API

2) Get real time stock values using Google Finance

 Google finance is also a good api. Let see its example and the things will be more clear.

http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOG
Here in the above url NASDAQ:GOOG is the stock code of Google.Finance API In this URL you can pass the market details also like you can retrive stock values from NASDAQ, London Stock exchange , NSE etc. As a response this URL will return JSON String so you need to write some what amonut of pasrsing logic to parse JSON String How to use this URL in Liferay ? Same way as we did for Yahoo .....!! Go through this link for more description of parameters . Google Finance API

Next PostNewer Post Previous PostOlder Post Home