Get the latest stock and stock index prices from Sina (. NET version), the latest market. net

Source: Internet
Author: User

Get the latest stock and stock index prices from Sina (. NET version), the latest market. net

In the procedural trading system that uses CTP to develop stock index futures options, the current points and closing of stock indexes are often used. In order to enable the program to automatically obtain the stock index, You need to query it through the network.
Currently, in addition to using Python for crawling, you can also use the JS quote server provided by sina. This article uses the latter.
1. the following fields are generally returned when you query the Stock Index:
Index name, current number of points, current price, rise/fall rate, transaction volume (hand), transaction amount (10 million RMB );
2. query a stock generally returns the following fields:
The name of the stock, which is opened today, closed yesterday, current price, current highest price, lowest price today, buy one price, sell one price, number of tickets sold, transaction amount, and purchase amount, buy one price ,..., buy five, buy five, sell one, sell one price ,..., five-volume purchase, five-price purchase, date, time

Because the stock index query does not return the limit close, you need to calculate the number of current points returned and the Rise/fall rate.
Show me your code:

Public class SinaStockIndexHelper {public static double GetThreePreCloseIndex () {double precloseindex = 0; try {// index query rules: s_sh000001, s_sz399001, s_sz399106, s_sh000300: Shanghai index, which is proved to be accurate, shenzhen Stock Index, Shanghai and Shenzhen 300, China
// Stock query rules: sh601857, sz002230: CNPC, KEDA xunfei (starting with sh, representing Shanghai Stock A shares, starting with sz, representing Shenzhen Stock, followed by the corresponding stock code) string url =" http://hq.sinajs.cn/list=s_sh000300 "; HttpWebRequest webrequest = (HttpWebRequest) HttpWebRequest. create (url); HttpWebResponse webreponse = (HttpWebResponse) webrequest. getResponse (); Stream stream = webreponse. getResponseStream (); byte [] rsByte = new Byte [webreponse. contentLength]; // save data in the stream. read (rsByte, 0, (int) webreponse. contentLength); Console. writeLine (System. text. encoding. UTF8.GetString (rsByte, 0, rsByte. length ). toString (); string tmp = System. text. encoding. UTF8.GetString (rsByte, 0, rsByte. length ). toString (); string [] index = tmp. split ('"'); string [] datas = index [1]. split (','); double todayindex = double. parse (datas [1]); double increaserate = double. parse (datas [3])/100; precloseindex = todayindex/(1 + increaserate); string pci = precloseindex. toString ("F2"); precloseindex = double. parse (pci);} catch (Exception exp) {Console. writeLine (exp. message) ;}return precloseindex ;}}

 

Related Article

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.