通过新浪网股票接口获取股票信息

上传人:re****.1 文档编号:454056288 上传时间:2024-01-06 格式:DOCX 页数:4 大小:7.67KB
返回 下载 相关 举报
通过新浪网股票接口获取股票信息_第1页
第1页 / 共4页
通过新浪网股票接口获取股票信息_第2页
第2页 / 共4页
通过新浪网股票接口获取股票信息_第3页
第3页 / 共4页
通过新浪网股票接口获取股票信息_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《通过新浪网股票接口获取股票信息》由会员分享,可在线阅读,更多相关《通过新浪网股票接口获取股票信息(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 = http:/ s

3、tatic string PastUrl = http:/ /生成/ / / / 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() = 399001) dm = sz;else if (StockID.Substring(0, 2)

4、= 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;/ /获取服务实时及历史信息/ / / public static string GetValue(string url)

5、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();int first = strHTML.IndexOf();strHTML = strHTML.Su

6、bstring(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 GetValue(GetUrl(StockId, 0);/ /获取股票历史信息/ / / pu

7、blic 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(Opening, typeof(double);dt.Co山mns.Add(MaxHight, t

8、ypeof(double);dt.Co山mns.Add(Closing, typeof(double);dt.Columns.Add(MaxLow, typeof(double);stringurl=string.Format(http:/ 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 = item.Groups1.Value;/时间dr2 = item.Groups2.Value;/时间dr3 = item.Groups3.Value;/时间dr=item.Groups 4.Value;/时间dr5 = item.Groups5.Value;/时间return dt;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号