通過(guò)新浪網(wǎng)股票接口獲取股票信息_第1頁(yè)
通過(guò)新浪網(wǎng)股票接口獲取股票信息_第2頁(yè)
通過(guò)新浪網(wǎng)股票接口獲取股票信息_第3頁(yè)
通過(guò)新浪網(wǎng)股票接口獲取股票信息_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、通過(guò)新浪網(wǎng)股票接口獲取股票信息以下函數(shù)全是靜態(tài)方法,可以在C#中直接調(diào)用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 股票名字,今日開(kāi)盤(pán)價(jià),昨日收 盤(pán)價(jià),當(dāng)前價(jià)格,今日最高價(jià),今日最低價(jià),競(jìng)買(mǎi)價(jià),即買(mǎi)一報(bào)價(jià),競(jìng)賣(mài)價(jià),即賣(mài)一報(bào) 價(jià),成交的股票數(shù),成交金額,買(mǎi)一申請(qǐng)多少股,買(mǎi)一報(bào)價(jià),買(mǎi)二,買(mǎi)二,買(mǎi)三,買(mǎi) 三,買(mǎi)四,買(mǎi)四,買(mǎi)五,買(mǎi)五,賣(mài)一申報(bào)股數(shù),賣(mài)一報(bào)價(jià),賣(mài)二申報(bào)股數(shù),賣(mài)二報(bào)價(jià) ,賣(mài)三申報(bào)股數(shù),賣(mài)三報(bào)價(jià),賣(mài)四申報(bào)股數(shù),賣(mài)四報(bào)價(jià),賣(mài)五申報(bào)股數(shù),賣(mài)五報(bào)價(jià), 日期,時(shí)間;public static string PastStockItems = new string 指數(shù)名稱(chēng),當(dāng)前點(diǎn)數(shù),漲跌點(diǎn) 數(shù),漲跌率,成交量(手),成交額(萬(wàn)元);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;/ /獲取服務(wù)實(shí)時(shí)及歷史信息

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;/ /獲取股票實(shí)時(shí)信息/ / / 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論