通过新浪网股票接口获取股票信息_第1页
通过新浪网股票接口获取股票信息_第2页
通过新浪网股票接口获取股票信息_第3页
通过新浪网股票接口获取股票信息_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、通过新浪网股票接口获取股票信息以下函数全是静态方法,可以在C#中直接调用using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.IO;using System.Data;using System.Text.RegularExpressions;namespace GzyFunctionLibrarypublic class GetStockInfopublic static string StockItems = new str

2、ing32 股票名字,今日开盘价,昨日收 盘价,当前价格,今日最高价,今日最低价,竞买价,即买一报价,竞卖价,即卖一报 价,成交的股票数,成交金额,买一申请多少股,买一报价,买二,买二,买三,买 三,买四,买四,买五,买五,卖一申报股数,卖一报价,卖二申报股数,卖二报价 ,卖三申报股数,卖三报价,卖四申报股数,卖四报价,卖五申报股数,卖五报价, 日期,时间;public static string PastStockItems = new string 指数名称,当前点数,涨跌点 数,涨跌率,成交量(手),成交额(万元);private static string url = HYPERLIN

3、K /list= /list=;private static string PastUrl = HYPERLINK /list=s_ /list=s_;/ /生成/ / / / private static string GetUrl(string StockID, int ValueType)string id = string.Empty;if (StockID = | StockID.Length != 6)return null;string dm = sh;if (StockID.Trim() = 000001)dm = sh; else if (StockID.Trim() = 3

4、99001) dm = sz;else if (StockID.Substring(0, 2) = 00)/深圳 dm = sz;else if (StockID.Substring(0, 2) = 60) dm = sh;else if (StockID.Substring(0, 2) = 51)/上海基金 dm = sh;switch (ValueType)case 0:return url + dm + StockID;case 1:return PastUrl + dm + StockID;default:return url + dm + StockID;/ /获取服务实时及历史信息

5、/ / / public static string GetValue(string url) try string StockValue;WebClient myWebClient = new WebClient();Stream myStream = myWebClient.OpenRead(url);StreamReader sr = new StreamReader(myStream, System.Text.Encoding.GetEncoding(gbk); string strHTML = sr.ReadToEnd();myStream.Close();sr.Close();in

6、t first = strHTML.IndexOf();strHTML = strHTML.Substring(first + 1, strHTML.Length - first - 4);StockValue = strHTML.Split(,); if (StockValue.Length = 2) return StockValue;elsereturn null;catch (Exception ex)return null;throw ex;/ /获取股票实时信息/ / / public static string GetRealValue(string StockId)return

7、 GetValue(GetUrl(StockId, 0);/ /获取股票历史信息/ / / public static string GetPastValue(string StockId)return GetValue(GetUrl(StockId, 1);public static DataTable getHis(string stockId)DataTable dt = new DataTable();dt.Columns.Add(StockId, typeof(string);dt.Columns.Add(iDate, typeof(DateTime);dt.Co山mns.Add(O

8、pening, typeof(double);dt.Co山mns.Add(MaxHight, typeof(double);dt.Co山mns.Add(Closing, typeof(double);dt.Columns.Add(MaxLow, typeof(double);stringurl=string.Format( HYPERLINK /corp/go.php/vMS_MarketHistory/stockid/%7b0%7d.p /corp/go.php/vMS_MarketHistory/stockid/0.p html, stockId);System.Net.WebClient wc = new WebClient();string Content = wc.DownloadString(url);stringreg=s*(As+)s+s*s*tdAd*(A*)s+tdAd *(A*)s+tdAd*(A*)s+tdAd*(A*)s+;MatchCollection result = Regex.Matches(Content, reg);foreach (Match item in result)DataRow dr = dt.NewRow();dr0 = stockId;dr1 = it

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论