public static YahooStockData Download(StockCode code, DateTime fromDate, DateTime toDate) { YahooStockData retData = null; string symbol = string.Format("{0}.{1}", code.Code, code.TradeCenter); symbol = symbol.Replace(".sh", ".ss"); string url = string.Format("http://table.finance.yahoo.com/table.csv?s={0}" + "&a={1}&b={2}&c={3}&d={4}&e={5}&f={6}&g=d&ignore=.csv", symbol, fromDate.Month - 1, fromDate.Day, fromDate.Year , toDate.Month - 1, toDate.Day, toDate.Year ); string text = HttpUtil.DownloadText(url); var lines = text.Split("\n".ToCharArray()); string firstLine = lines[0].Trim(); if (firstLine.Equals(sFirstLine)) { retData = new YahooStockData(); retData.Code = code; retData.DailyDataList = new List<StockDailyData>(); for (int idx = 1; idx < lines.Length; idx++) { #region parse single line var dataLine = lines[idx].Trim(); if (!string.IsNullOrEmpty(dataLine)) { var items = dataLine.Split(",".ToCharArray()); StockDailyData data = new StockDailyData(); data.Date = DateTime.Parse(items[0]); data.Open = decimal.Parse(items[1]); data.High = decimal.Parse(items[2]); data.Low = decimal.Parse(items[3]); data.Close = decimal.Parse(items[4]); data.Volumn = decimal.Parse(items[5]); data.AdjustClose = decimal.Parse(items[6]); retData.DailyDataList.Add(data); } #endregion } } return retData; }
/// <summary> /// /// </summary> /// <param name="stockCode"></param> /// <returns></returns> public static SinaStockData Download(StockCode stockCode) { string url=string.Format("http://hq.sinajs.cn/list={0}{1}",stockCode.TradeCenter,stockCode.Code); var text = HttpUtil.DownloadText(url,Encoding.GetEncoding("GBK")); return Parse(text); }
public static YahooStockData Download(StockCode code) { return Download(code, DateTime.Today.AddDays(-1), DateTime.Today); }
public static YahooStockData Download(StockCode code, DateTime fromDate) { return Download(code, fromDate, DateTime.Today); }