0

i have tried to get indian NSE & BSE stock price data from Yahoo finance. I gone through some link in stackoverflow, It provide to get data in csv format. It seems only for non-indian stock market price. I need to get BSE (Bombay Stock Exchange) & NSE (National Stock Exchange) through Yahoo finance.

This is sample link

http://download.finance.yahoo.com/d/quotes.csv?s=BOBSL.BO,JAIPAN.BO,SANGHIIN.BO&f=snl1d1t1ohgdrx

when i try to get value it gives "N/A" in all value of the table.

How to get it real value of stock price?? I need to implement it in Java program further. any help appreciated.!!

This is my Java code.

package httpDownloader;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import stock.StockInTime;

public class HistoryHttpDownloader extends HttpDownloader {
    public static ArrayList<StockInTime> getHistoricalQuotes(String symbol,
            Date from, Date to) {
        String data = downloadFile(getHistoryURI(symbol, from, to));
        ArrayList<StockInTime> stockHistory = parseHistoryData(data);
        return stockHistory;
    }

    private static String getHistoryURI(String symbol, Date from, Date to) {
        Calendar fromDate = new GregorianCalendar();
        fromDate.setTime(from);
        Calendar toDate = new GregorianCalendar();
        toDate.setTime(to);
        String uri = "http://ichart.finance.yahoo.com/table.csv?s=";
        uri += symbol;
        uri += "&a=" + fromDate.get(Calendar.MONTH);
        uri += "&b=" + fromDate.get(Calendar.DAY_OF_MONTH);
        uri += "&c=" + fromDate.get(Calendar.YEAR);
        uri += "&d=" + toDate.get(Calendar.MONTH);
        uri += "&e=" + toDate.get(Calendar.DAY_OF_MONTH);
        uri += "&f=" + toDate.get(Calendar.YEAR);
        return uri += "&g=d";
    }

    public static ArrayList<StockInTime> parseHistoryData(String data) {
        ArrayList<StockInTime> stockHistory = new ArrayList<StockInTime>();
        String[] csvRows = data.split("\n");
        // First row contains headers, ignored
        for (int i = 1; i < csvRows.length; i++) {
            String[] stockInfo = csvRows[i].split(",");
            StockInTime stockPoint = new StockInTime(
                    convertToDate(stockInfo[0]), parseDouble(stockInfo[4]));
            stockHistory.add(stockPoint);
        }
        return stockHistory;
    }

    private static Date convertToDate(String sDate) {
        try {
            DateFormat dateformater = new SimpleDateFormat("yyyy-MM-dd");
            return dateformater.parse(sDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
Community
  • 1
  • 1
Rajan
  • 199
  • 1
  • 5
  • 20

1 Answers1

1

The problem is you aren't getting that BSE or NSE data back in the CSV from Yahoo, that's why you're having problems. If I change your URL to a garbage symbol, I get the same sort of "N/A" response: http://download.finance.yahoo.com/d/quotes.csv?s=I_AM_A_FAKE_SYMBOL&f=snl1d1t1ohgdrx". If you query with a valid symbol such as MSFT then you get a good CSV response.

You need to figure out how to get good data. For good data, you'll generally have to pay for it. You can see Yahoo stopped supporting this data recently: http://in.answers.yahoo.com/question/index?qid=20130711195331AAoMOCm.

mpurkeypile
  • 148
  • 5
  • I come through the link you are providing, It is possible to get data from yahoo in any other way? – Rajan Dec 20 '13 at 07:02
  • Not from Yahoo, but other providers will have it. (Typically you'll have to pay for this data.) – mpurkeypile Dec 20 '13 at 23:05
  • 1
    Finally the point is, we does't get BSE data as free of cost? – Rajan Dec 23 '13 at 10:38
  • Right- you'll typically have to pay for financial data. That's especially true if you plan on using it in a commercial environment. You get what you pay for to some extent. In this case, "free" leaves you no recourse if the provider (Yahoo) stops offering it. – mpurkeypile Dec 27 '13 at 16:45