示例#1
0
        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;
        }
示例#2
0
 /// <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);
 }
示例#3
0
 public static YahooStockData Download(StockCode code)
 {
     return Download(code, DateTime.Today.AddDays(-1), DateTime.Today);
 }
示例#4
0
 public static YahooStockData Download(StockCode code, DateTime fromDate)
 {
     return Download(code, fromDate, DateTime.Today);
 }