Wednesday, December 30, 2009

Get Sensex Stock data From Yahoo Finace

StockData stockData = new StockData();
List StockDatalist = new List();
string serverUrl = @"http://in.finance.yahoo.com/d/quotes.csv?s=" + stockCode +"&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUrl);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream(),
Encoding.ASCII);

stockDataString = reader.ReadLine();
string[] stockDataContents = stockDataString.Split(',');

stockData.Code = stockCode;
stockData.Last = stockDataContents[1];
stockData.Date = stockDataContents[2];
stockData.Time = stockDataContents[3];
stockData.Change = stockDataContents[4];
stockData.Open = stockDataContents[5];
stockData.High = stockDataContents[6];
stockData.Low = stockDataContents[7];
stockData.Volume = stockDataContents[8];
stockData.MarketCapital = stockDataContents[9];
stockData.PreviousClose = stockDataContents[10];
stockData.PctChange = stockDataContents[11];
stockData.AnnRange = stockDataContents[12];
stockData.Earnings = stockDataContents[13];
stockData.PERatio = stockDataContents[14];
StockDatalist.Add(stockData);

response.Close();

return stockDataString;

1 comment:

  1. Dear,
    Could you please share thi application to baji.ip@gmail.com ?
    How can I add StockData reference here?

    ReplyDelete