日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

新浪的股票接口 c#

發布時間:2023/12/9 C# 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 新浪的股票接口 c# 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

需要注意的這個只是獲取單只股票

?代碼的用處,通過這個代碼有炒股的朋友就可以寫出簡單的自動止損和按一定價格入場的程序了。(國內正規券商不支持這種功能,可能是為了防止一些東西。)

我們先來看一下股票信息的類

?namespace Qianfa.net.Library.Entity
{
??? /*http://hq.sinajs.cn/list=sh600066? sh上海 sz深圳
???? * 0:”大秦鐵路”,股票名字;
?? 1:”27.55″,今日開盤價;
?? 2:”27.25″,昨日收盤價;
?? 3:”26.91″,當前價格;//時間結束后也就是收盤價了
?? 4:”27.55″,今日最高價;
?? 5:”26.20″,今日最低價;
?? 6:”26.91″,競買價,即“買一”報價;
?? 7:”26.92″,競賣價,即“賣一”報價;
?? 8:”22114263″,成交的股票數,由于股票交易以一百股為基本單位,所以在使用時,通常把該值除以一百;
?? 9:”589824680″,成交金額,單位為“元”,為了一目了然,通常以“萬元”為成交金額的單位,所以通常把該值除以一萬;
?? 10:”4695″,“買一”申請4695股,即47手;
?? 11:”26.91″,“買一”報價;
?? 12:”57590″,“買二”
?? 13:”26.90″,“買二”
?? 14:”14700″,“買三”
?? 15:”26.89″,“買三”
?? 16:”14300″,“買四”
?? 17:”26.88″,“買四”
?? 18:”15100″,“買五”
?? 19:”26.87″,“買五”
?? 20:”3100″,“賣一”申報3100股,即31手;
?? 21:”26.92″,“賣一”報價
?? (22, 23), (24, 25), (26,27), (28, 29)分別為“賣二”至“賣四的情況”
?? 30:”2008-01-11″,日期;
?? 31:”15:05:32″,時間;
?? */
??? public class StockInfo
??? {
??????? public string Name
??????? {
??????????? get;
??????????? set;
??????? }

??????? public decimal TodayOpen
??????? {
??????????? get;
??????????? set;
??????? }

??????? public decimal YesterdayClose
??????? {
??????????? get;
??????????? set;
??????? }

??????? public decimal Current
??????? {
??????????? get;
??????????? set;
??????? }

??????? public decimal High
??????? {
??????????? get;
??????????? set;
??????? }

??????? public decimal Low
??????? { get; set; }

??????? /// <summary>
??????? /// 竟買價 買1
??????? /// </summary>
??????? public decimal Buy
??????? { get; set; }

??????? /// <summary>
??????? /// 竟賣價 賣1
??????? /// </summary>
??????? public decimal Sell { get; set; }

??????? /// <summary>
??????? /// 成交數 單位股數 通常除于100成為手
??????? /// </summary>
??????? public int VolAmount { get; set; }

??????? /// <summary>
??????? /// 成交多少錢,單位元
??????? /// </summary>
??????? public decimal VolMoney { get; set; }

??????? /// <summary>
??????? /// 新浪是可以看到5個,5檔看盤 ,買1-買5
??????? /// </summary>
??????? public List<GoodsInfo> BuyList { get; set; }

??????? /// <summary>
??????? /// 賣1-賣5
??????? /// </summary>
??????? public List<GoodsInfo> SellList { get; set; }

??????? /// <summary>
??????? /// Date and Time
??????? /// </summary>
??????? public DateTime Time { get; set; }

??????? public override string ToString()
??????? {
??????????? return Name + ": " + VolAmount + ":" + Current;
??????? }
???????
??? }

/*現在爬文章的很多,原文在http://www.cnblogs.com/lovebanyi/archive/2010/05/02/1725874.html?*/
}

?

?

namespace Qianfa.net.Library
{

///股票數據獲取接口,你可以自己實現新浪yahoo...
??? public interface IDataService
??? {
???????? StockInfo GetCurrent(string stockCode);???
??? }
}

?

namespace Qianfa.net.DataServices
{
??? public class Sina : IDataService
??? {

??????? private const string dataurl = "http://hq.sinajs.cn/list=%7B0}";
??????? #region IStockInfo Members
??????? HttpClient client;
??????? private StockInfo PrevInfo;
??????? public StockInfo GetCurrent(string stockCode)
??????? {
??????????? try
??????????? {
??????????????? if (client == null)
??????????????? {
??????????????????? client = new HttpClient();
??????????????? }
??????????????? if (stockCode.Substring(0, 2) == "60")//上海是600打頭
??????????????? {
??????????????????? stockCode = "sh" + stockCode;
??????????????? }
??????????????? else if(stockCode.Substring(0,2)=="00")//深圳
??????????????? {
??????????????????? stockCode = "sz" + stockCode;
??????????????? }
??????????????? else if (stockCode.Substring(0, 2) == "51")//上海基金
??????????????? {
??????????????????? stockCode = "sh" + stockCode;
??????????????? }
??????????????? string url = string.Format(dataurl, stockCode);
??????????????? string data = client.DownloadString(string.Format(url, stockCode));
??????????????? PrevInfo = Parse(data);
??????????????? return PrevInfo;
??????????? }
??????????? catch
??????????? {
??????????????? return PrevInfo;
??????????? }
???????????
??????? }

??????? /// <summary>
??????? /// Parse Sina data to stock Info
??????? /// </summary>
??????? /// <param name="input"></param>
??????? /// <returns></returns>
??????? public static StockInfo Parse(string content)
??????? {
?????????? // var hq_str_sh600066 = "宇通客車,9.27,9.35,9.76,9.80,9.27,9.77,9.78,4567858,44306952,3100,9.77,1200,9.76,20500,9.75,1400,9.74,15300,9.73,10030,9.78,28093,9.79,156827,9.80,2800,9.81,6400,9.82,2009-01-09,15:03:32";
??????????? int start = content.IndexOf('"')+1;
??????????? int end = content.IndexOf('"',start);
??????????? string input = content.Substring(start, end - start);
??????????? string[] temp = input.Split(',');
??????????? if (temp.Length != 32)
??????????? {
??????????????? return null;
??????????? }
??????????? StockInfo info = new StockInfo();
??????????? info.Name = temp[0];
??????????? info.TodayOpen = decimal.Parse(temp[1]);
??????????? info.YesterdayClose = decimal.Parse(temp[2]);
??????????? info.Current = decimal.Parse(temp[3]);
??????????? info.High = decimal.Parse(temp[4]);
??????????? info.Low = decimal.Parse(temp[5]);
??????????? info.Buy = decimal.Parse(temp[6]);
??????????? info.Sell = decimal.Parse(temp[7]);
??????????? info.VolAmount = int.Parse(temp[8]);
??????????? info.VolMoney = decimal.Parse(temp[9]);
??????????? info.BuyList = new List<GoodsInfo>(5);
??????????? int index = 10;
??????????? for (int i = 0; i < 5; i++)
??????????? {
??????????????? GoodsInfo goods = new GoodsInfo();
??????????????? goods.State = GoodsState.Buy;
??????????????? goods.Amount = int.Parse(temp[index]);
??????????????? index++;
??????????????? goods.Price = decimal.Parse(temp[index]);
??????????????? index++;
??????????????? info.BuyList.Add(goods);
??????????? }
??????????? info.SellList = new List<GoodsInfo>(5);

??????????? for (int i = 0; i < 5; i++)
??????????? {
??????????????? GoodsInfo goods = new GoodsInfo();
??????????????? goods.State = GoodsState.Sell;
??????????????? goods.Amount = int.Parse(temp[index]);
??????????????? index++;
??????????????? goods.Price = decimal.Parse(temp[index]);
??????????????? index++;
??????????????? info.SellList.Add(goods);
??????????? }
??????????? info.Time = DateTime.Parse(temp[30] + " " + temp[31]);
??????????? return info;

??????? }

??????? #endregion
??? }
}

?

?
??? public class GoodsInfo
??? {
??????? public int Amount
??????? { get; set; }
??????? public decimal Price
??????? {
??????????? get;
??????????? set;
??????? }
??????? public GoodsState State { get; set; }
??? }

?如果你想要商業類型的股票接口可以可以跟我聯系哦。

http://www.qianfa.net/StockInfoSoft.aspx

轉載于:https://www.cnblogs.com/lovebanyi/archive/2010/05/02/1725874.html

總結

以上是生活随笔為你收集整理的新浪的股票接口 c#的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。