我试图从雅虎财经获取印度 NSE 和 BSE 股票价格数据。我浏览了stackoverflow中的一些链接,它提供了以csv格式获取数据。这似乎只适用于非印度股市的价格。我需要通过雅虎金融获得 BSE(孟买证券交易所)和 NSE(国家证券交易所)。
这是示例链接
http://download.finance.yahoo.com/d/quotes.csv?s=BOBSL.BO,JAIPAN.BO,SANGHIIN.BO&f=snl1d1t1ohgdrx
当我尝试获取价值时,它在表的所有值中给出“N/A”。
如何获得股票价格的真实价值?我需要进一步在Java程序中实现它。任何帮助表示赞赏。!!
这是我的 Java 代码。
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;
}
}