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)