新浪的股票接口 c#.docx

上传人:b****6 文档编号:5738447 上传时间:2022-12-31 格式:DOCX 页数:5 大小:16.34KB
下载 相关 举报
新浪的股票接口 c#.docx_第1页
第1页 / 共5页
新浪的股票接口 c#.docx_第2页
第2页 / 共5页
新浪的股票接口 c#.docx_第3页
第3页 / 共5页
新浪的股票接口 c#.docx_第4页
第4页 / 共5页
新浪的股票接口 c#.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

新浪的股票接口 c#.docx

《新浪的股票接口 c#.docx》由会员分享,可在线阅读,更多相关《新浪的股票接口 c#.docx(5页珍藏版)》请在冰豆网上搜索。

新浪的股票接口 c#.docx

新浪的股票接口c#

新浪的股票接口c#

需要注意的这个只是获取单只股票

 代码的用处,通过这个代码有炒股的朋友就可以写出简单的自动止损和按一定价格入场的程序了。

(国内正规券商不支持这种功能,可能是为了防止一些东西。

我们先来看一下股票信息的类

 namespaceQ.Library.Entity

{

   /* 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″,时间;

  */

   publicclassStockInfo

   {

       publicstringName

       {

           get;

           set;

       }

       publicdecimalTodayOpen

       {

           get;

           set;

       }

       publicdecimalYesterdayClose

       {

           get;

           set;

       }

       publicdecimalCurrent

       {

           get;

           set;

       }

       publicdecimalHigh

       {

           get;

           set;

       }

       publicdecimalLow

       {get;set;}

       ///

       ///竟买价买1

       ///

       publicdecimalBuy

       {get;set;}

       ///

       ///竟卖价卖1

       ///

       publicdecimalSell{get;set;}

       ///

       ///成交数单位股数通常除于100成为手

       ///

       publicintVolAmount{get;set;}

       ///

       ///成交多少钱,单位元

       ///

       publicdecimalVolMoney{get;set;}

       ///

       ///新浪是可以看到5个,5档看盘,买1-买5

       ///

       publicListBuyList{get;set;}

       ///

       ///卖1-卖5

       ///

       publicListSellList{get;set;}

       ///

       ///DateandTime

       ///

       publicDateTimeTime{get;set;}

       publicoverridestringToString()

       {

           returnName+":

"+VolAmount+":

"+Current;

       }

        

   }

/*现在爬文章的很多,原文在 */

}

 namespaceQ.Library

{

///股票数据获取接口,你可以自己实现新浪yahoo...

   publicinterfaceIDataService

   {

        StockInfoGetCurrent(stringstockCode);   

   }

}

 

namespaceQ.DataServices

{

   publicclassSina:

IDataService

   {

       privateconststringdataurl="

       #regionIStockInfoMembers

       HttpClientclient;

       privateStockInfoPrevInfo;

       publicStockInfoGetCurrent(stringstockCode)

       {

           try

           {

               if(client==null)

               {

                   client=newHttpClient();

               }

               if(stockCode.Substring(0,2)=="60")//上海是600打头

               {

                   stockCode="sh"+stockCode;

               }

               elseif(stockCode.Substring(0,2)=="00")//深圳

               {

                   stockCode="sz"+stockCode;

               }

               elseif(stockCode.Substring(0,2)=="51")//上海基金

               {

                   stockCode="sh"+stockCode;

               }

               stringurl=string.Format(dataurl,stockCode);

               stringdata=client.DownloadString(string.Format(url,stockCode));

               PrevInfo=Parse(data);

               returnPrevInfo;

           }

           catch

           {

               returnPrevInfo;

           }

            

       }

       ///

       ///ParseSinadatatostockInfo

       ///

       ///

       ///

       publicstaticStockInfoParse(stringcontent)

       {

          //varhq_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";

           intstart=content.IndexOf('"')+1;

           intend=content.IndexOf('"',start);

           stringinput=content.Substring(start,end-start);

           string[]temp=input.Split(',');

           if(temp.Length!

=32)

           {

               returnnull;

           }

           StockInfoinfo=newStockInfo();

           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=newList(5);

           intindex=10;

           for(inti=0;i<5;i++)

           {

               GoodsInfogoods=newGoodsInfo();

               goods.State=GoodsState.Buy;

               goods.Amount=int.Parse(temp[index]);

               index++;

               goods.Price=decimal.Parse(temp[index]);

               index++;

               info.BuyList.Add(goods);

           }

           info.SellList=newList(5);

           for(inti=0;i<5;i++)

           {

               GoodsInfogoods=newGoodsInfo();

               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]);

           returninfo;

       }

       #endregion

   }

}

   publicclassGoodsInfo

   {

       publicintAmount

       {get;set;}

       publicdecimalPrice

       {

           get;

           set;

       }

       publicGoodsStateState{get;set;}

   }

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1