/** * 获取股票分时数据 * * http://market.finance.sina.com.cn/downxls.php?date=2011-07-08&symbol=sh600900 获取代码为sh600900,在2011-07-08的成交明细,数据为xls格式。 http://vip.stock.finance.sina.com.cn/quotes_service/view/cn_price.php?symbol=sh600900 获得sh600900当日的分价表 http://market.finance.sina.com.cn/pricehis.php?symbol=sh600900&startdate=2011-08-17&enddate=2011-08-19 获得sh600900从2011-08-17到2011-08-19的分价表。 * */ public static DataTable getGuoPiaoTimeHisFromSina(string code,DateTime date) { if (String.IsNullOrEmpty(code)) { return null; } //雅虎历史数据 string url = "http://market.finance.sina.com.cn/downxls.php?date=" + date.Date.ToShortDateString() + "&symbol="+code; Console.WriteLine(url); HttpClient client = null; DataTable datatable = null; client = new HttpClient(url); Stream stream = null; try { stream = client.GetStream(); datatable = CSVFileHelper.OpenCSVFromSteam(code, stream); } catch (Exception e) { client.Reset(); Console.WriteLine("no data to get today"); } return datatable; }
/** * 获取股票,大盘历史数据 * * 直接在浏览器地址中数据网址即可 http://table.finance.yahoo.com/table.csv?s=股票代码 上证股票是股票代码后面加上.ss,深证股票是股票代码后面加上.sz 深市数据链接:http://table.finance.yahoo.com/table.csv?s=000001.sz 上市数据链接:http://table.finance.yahoo.com/table.csv?s=600000.ss 另外,上证综指代码:000001.ss,深证成指代码:399001.SZ,沪深300代码:000300.ss 例如查询中国石油的历史数据,直接在浏览器中输入:http://table.finance.yahoo.com/table.csv?s=601857.ss * */ public static DataTable getGuoPiaoHisDataFromYaoh(DateTime bdate, DateTime edate, string code) { if (String.IsNullOrEmpty(code)) { return null; } else { code = getYaohUrlCode(code); } //雅虎历史数据 string url = "http://table.finance.yahoo.com/table.csv?" + "a=" + (bdate.Month - 1).ToString() + "&b=" + bdate.Day.ToString() + "&c=" + bdate.Year.ToString() + "&d=" + (edate.Month - 1).ToString() + "&e=" + edate.Day.ToString() + "&f=" + edate.Year.ToString() + "&s=" + code; Console.WriteLine(url); HttpClient client = null; DataTable datatable = null; try { client = new HttpClient(url); datatable = CSVFileHelper.OpenCSVFromSteam(code, client.GetStream()); } catch (Exception e) { client.Reset(); throw e; } return datatable; }