On 10/29/07, Gaurav Mishra <[EMAIL PROTECTED]> wrote:
>
> On 10/28/07, Anupam Jain <[EMAIL PROTECTED]> wrote:
> >
> > I recently implemented something like this for my company using plain
> and
> > simple google search. For example if you want to get stock quotes for
> Google
> > my little php app makes a web search for "GOOG stock" and the first
> result
> > is the Google stock data (complete with a graph) which can be easily
> parsed.
>
> can this be implemented for indian Stocks, AFAIK google finance does
> not provide indian stocks data


I use this URL http://www.nse-india.com/marketinfo/equities/cmquote_tab.jsp
This URL is the URL of a frame in the page that shows the prices.
the parameters you need to set are..
key=EQN
symbol=$scripCode
flag=0

These could either be set in the query String for a GET or as name value
pairs in  POST
e.g.
http://www.nse-india.com/marketinfo/equities/cmquote_tab.jsp?key=EQN&symbol=SBI&flag=0

Here is my fetchPrice code In java.  What i am essentially doing is fetching
price, removing the newlines then matching a regex to find the price.

public double fetchPrice(String scripCode) throws IOException {
        System.out.println("Fetching price for:" + scripCode);
        PostMethod method = new PostMethod(url);

        method.addParameter(new NameValuePair("key", scripCode + "EQN"));
        method.addParameter(new NameValuePair("symbol", scripCode));
        method.addParameter(new NameValuePair("flag", "0"));
        if ("true".equalsIgnoreCase(ConfigReader.getString("useproxy"))) {
            HostConfiguration configuration = new HostConfiguration();
            configuration.setProxy("proxy.url", 80);
            client.executeMethod(configuration, method);
        }else {
            client.executeMethod(method);
        }
        String response = new String(method.getResponseBody());

        if (response.indexOf("Last Price") != -1) {
            System.out.println("Last Price Exists");
            response = response.substring(response.indexOf("Last Price"))
                    .trim().replaceAll("\n", " ").toLowerCase();

        } else {
            System.err.println("Incorrect response:" + response);
        }
        Pattern p = Pattern.compile("^last.*?(\\d+\\.\\d+).*$");
        Matcher m = p.matcher(response);
        double returnVal = 0.0;
        if (m.matches()) {
            System.err.println("Correct Response received");
            returnVal = Double.parseDouble(m.group(1));
            System.out.println("Last price:" + returnVal);

        }
        method.releaseConnection();
        return returnVal;
    }

I have a list of  about 120-130 stock symbols that this site uses that you
will need to pass in the symbol parameter. So if anyone wants it, I could
send across those symbols.

Hope it helps
-- 
Puneet
http://sahyog.blogspot.com/
_______________________________________________
ilugd mailinglist -- ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd
Next Event: http://freed.in - September 28-29, 2007
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi 
http://www.mail-archive.com/ilugd@lists.linux-delhi.org/

Reply via email to