Get the latest stock and stock index quotes from Sina (. NET version)

Source: Internet
Author: User

Using the CTP to develop stock index futures options in the programmatic trading system, often use the index of the current points and the most close, in order to make the program can be automatically obtained, need to query through the network.
At present, in addition to the use of Python crawler Access can also be provided by Sina's JS Market server obtained, the latter is used in this article.
1, query stock index generally return contains the following fields:
Index name, current point, current price, rate of rise and fall, turnover (hand), turnover (million);
2, Query stock general return contains the following fields:
Stock name, today's open price, yesterday's close, current prices, today's highest price, today's lowest price, buy a price, sell a price, the number of shares traded, deal amount, buy a quantity, buy a price, ..., buy five, buy five, sell a quantity, sell a price, ..., sell five, buy five price, date, time

Since the stock index query returns no last close, it needs to be calculated by returning the current points and the rate of rise and fall.
Show Me Your code:

Public classSinastockindexhelper { Public Static DoubleGetthreeprecloseindex () {DoublePrecloseindex =0; Try { //Index Query rules: s_sh000001,s_sz399001,s_sz399106,s_sh000300: Shanghai Composite, shen-exponentially, Shen-syndrome, Shenzhen 300
//stock Query rules: sh601857,sz002230: PetroChina, Iflytek (with SH at the beginning to represent the Shanghai A shares, with the SZ beginning to represent the Shenzhen stock, followed by the corresponding stock code) stringURL ="http://hq.sinajs.cn/list=s_sh000300"; HttpWebRequest WebRequest=(HttpWebRequest) httpwebrequest.create (URL); HttpWebResponse Webreponse=(HttpWebResponse) WebRequest. GetResponse (); Stream Stream=Webreponse. GetResponseStream (); byte[] Rsbyte =NewByte[webreponse. ContentLength];//save Data in the streamStream. Read (Rsbyte,0, (int) Webreponse. ContentLength); Console.WriteLine (System.Text.Encoding.UTF8.GetString (Rsbyte,0, Rsbyte.length). ToString ()); stringTMP = System.Text.Encoding.UTF8.GetString (Rsbyte,0, Rsbyte.length). ToString (); string[] index = tmp. Split ('"'); string[] Datas = index[1]. Split (','); DoubleTodayindex =Double. Parse (datas[1]); DoubleIncreaserate =Double. Parse (datas[3]) / -; Precloseindex= Todayindex/(1+increaserate); stringPCI = Precloseindex. ToString ("F2"); Precloseindex=Double. Parse (PCI); } Catch(Exception exp) {Console.WriteLine (exp. Message); } returnPrecloseindex; } }

Get the latest stock and stock index quotes from Sina (. NET version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.