Real-time stock market acquisition

Source: Internet
Author: User
The following two methods can be used to obtain stock data:
1. Data retrieval through HTTP/JavaScript Interfaces
2. Web-Service Interface
1. Data retrieval through HTTP/JavaScript Interfaces
1.1sina stock data interface
Take the Daqin Railway (stock code: 601006) as an example. To get its latest market, you only need to access Sina's stock data.
Interface:
Http://hq.sinajs.cn/list=sh601006
This URL returns a string of text, for example:
VaR hq_str_sh601006 = "Daqin railway, 27.55, 27.25, 26.91, 27.55, 26.20, 26.91, 26.92,
22114263,589 listen 680, 4695, 26.91, 57590, 26.90, 14700, 26.89, 14300,
26.88, 15100, 26.87, 3100, 26.92, 8900, 26.93, 14230, 26.94, 25150, 26.95, 15220, 26.96, 15:05:32 ";
This string is concatenated by many pieces of data. Data of different meanings are separated by commas. According to the programmer's idea, the sequence number starts from 0.
0: "Daqin Railway", stock name;
1: "27.55", available today;
2: "27.25", closing price yesterday;
3: "26.91", current price;
4: "27.55", the highest price today;
5: "26.20", the lowest price today;
6: "26.91", bidding price, that is, "buy one" quotation;
7: "26.92", competitive price, that is, "sell one" quotation;
8: "22114263". The number of votes in the transaction. Because the stock transaction uses one hundred shares as the basic unit, this value is usually divided by one hundred during use;
9: "589824680", deal amount, unit: "Yuan", in order to be clear, usually "10 thousand yuan" as the unit of deal amount, so usually divide the value;
10: "4695", "buy one" apply for 4695 shares, that is, 47;
11: "26.91", "buy one" quotation;
12: "57590", "Buy two"
13: "26.90", "Buy two"
14: "14700", "Buy three"
15: "26.89", "Buy three"
16: "14300", "Buy Four"
17: "26.88", "Buy Four"
18: "15100", "Buy five"
19: "26.87", "Buy five"
20: "3100", "sell one", declare 3100 shares, that is, 31 hands;
21: "26.92", "buy one" quotation
(22, 23), (24, 25), (26, 27), (28, 29) are the situations from "selling two" to "selling four" respectively"
30: "2008-01-11", date;
31: "15:05:32", time;
A simple JavaScript Application Example:
Script Type = "text/JavaScript" src = "http://hq.sinajs.cn/list=sh601006" charset = "gb2312">/SCRIPT>
/JavaScript ">
VaR elements = hq_str_sh601006.split (",");
Document. Write ("current price:" + elements [3]);
This code outputs the current stock price of Daqin Railway (stock code: 601006)
Current Price: 14.20
If you want to query multiple stocks at the same time, add a comma at the end of the URL and the stock code. For example, you need to query Daqin Railway (601006) and Datong coal (601001) at a time) the URL is used as follows:
Http://hq.sinajs.cn/list=sh601003,sh601001
Query the index of the dashboard, for example, the Shanghai Composite Index (000001 ):
Http://hq.sinajs.cn/list=s_sh000001
The data returned by the server is:
VaR hq_str_s_sh000001 = "Shanghai Stock Index, 3094.668,-128.073,-3.97, 436653,5458126 ";
The data meanings are: Index name, current points, current price, rise/fall rate, transaction volume (hand), and transaction amount (10 million RMB );
Query Shenzhen index:
Http://hq.sinajs.cn/list=s_sz399001
You can request http://image.sinajs.cn/… to obtain the K-line and daily-line charts of a stock /.... /... /*. GIF: This URL is obtained. * indicates the stock code. For details, see the following:
View the daily K-line chart:
Http://image.sinajs.cn/newchart/daily/n/sh601006.gif

Time-sharing line query:
Http://image.sinajs.cn/newchart/min/n/sh000001.gif

Query the daily data records:
Http://image.sinajs.cn/newchart/daily/n/sh000001.gif

Weekly k query:
Http://image.sinajs.cn/newchart/weekly/n/sh000001.gif

Monthly kill query:
Http://image.sinajs.cn/newchart/monthly/n/sh000001.gif

1.2 Baidu & Google financial data
When you search for a stock code in Baidu or Google, information about the stock is displayed in the headlines. For example, when you search for 601006,
The first search result is as follows:
By clicking the picture on the left, we found that this picture will be linked to the Sina financial channel, that is, the acquisition of Google stock data is also obtained from Sina. After packet capture analysis, we found that Google also adopted the interface described in 1.1.
Baidu stock data comes from Baidu's financial channel
Http://stock.baidu.com/
1.3 Other Methods
In addition to Sina, Baidu and other websites that provide stock information, other websites also have similar interfaces. We analyzed a stock plug-in used on the Forum,
For details about how to obtain real-time stock data, see the following code. Some data is from Sina.
The following is an example of ASP:
= 5 then
Stockdata = gethttp ("http://hq.sinajs.cn/list=sh" & code &"")
If not Len (stockdata) = 0 then stockdata = Split (stockdata, CHR (34) (1)
End if
If Len (stockdata) = 0 then
Stockdata = "0, 0, 0, 0, 0, 0, 0, 0, 0"
Else
Stockdatasplit = Split (stockdata, ",") stockdata = "" & exstock. checkstr (stockdatasplit (0) & "," & stockdatasplit (1) & "," & stockdatasplit (2) & "," & stockdatasplit (3 )&", "& stockdatasplit (4) &", "& stockdatasplit (5) &", "& formatdatetime (" & stockdatasplit (30) & "" & stockdatasplit (31) & "", 0 )&""
End if
'0 = stock name, 1 = opening price, 2 = closing price, 3 = current price, 4 = highest price, 5 = lowest price, 6 = Update Time
Getstockdata = stockdata
End Function
Function getstockimg (CODE)
Dim rndnum, addnum, checkcode, imgsource
If Len (CODE) = 5 then
Getstockimg = "http://image.sinajs.cn/newchart/daily/n/sh" & code & ". GIF"
End if
Imgsource = "http://finance.sina.com.cn"
Case 3
Getstockimg = "http://hq.gazxfe.com/stockchart/realline.chart? "& Code &" & 1003 & SZ 500 330"
Imgsource = "http://hq.gazxfe.com"
Case 4
Getstockimg = "http://chartse.stockstar.com/chartserver? Code = "& code &""
Imgsource = "http://www.stockstar.com /"
End select
Getstockimg = Split ("" & getstockimg & "|" & imgsource & "," | ")
End Function
Function getastockimg ()
Dim rndnum, addnum, checkcode
Dim getastockimgb, imgsource
Addnum = 6
Randomize: rndnum = CINT (RND * addnum)
Select case rndnum
Case 0
Getastockimg = "http: // 202.109.106.1/gifchartse/GIF/000001.gif"
Getastockimgb = "http: // 202.109.106.1/gifchartse/GIF/399001.gif"
Imgsource = "http://www.stockstar.com /"
Case 1
Getastockimg = "http://money.163.com/special/100.gif? C39"
Getastockimgb = "http://money.163.com/special/101.gif? HRs"
Imgsource = "http://www.163.com"
Case 2
Getastockimg = "http://www.10jqka.com.cn/curve/realtime/index2.php? Code = 1a0001 & W = 180 & H = 140"
Getastockimgb = "http://www.10jqka.com.cn/curve/realtime/index2.php? Code = 399001 & W = 180 & H = 140"
Imgsource = "http://www.10jqka.com.cn"
Case 3
Getastockimg = "http://chart.cnlist.com/stockchart/realline.chart? 1a0001 & 1002 & SZ 180 140"
Getastockimgb = "http://chart.cnlist.com/stockchart/realline.chart? 399001 & 1002 & SZ 180 140"
Imgsource = "http://chart.cnlist.com /"
Case 4
Getastockimg = "http://image.sinajs.cn/newchart/small/ish000001.gif? 1189176558328"
Getastockimgb = "http://image.sinajs.cn/newchart/small/isz399001.gif? 1189176558328"
Imgsource = "http://www.sinajs.cn"
Case 5
Getastockimg = "http: // 218.1.72.66/cgi/PIC/SH/realtime/ja000001164143.png"
Getastockimgb = "http: // 218.1.72.66/cgi/PIC/sz/realtime/ja399001164143.png"
Imgsource = "http://www.cnstock.com /"
Case 6
Getastockimg = "http: // 222.73.29.85/img/000001.png"
Getastockimgb = "http: // 222.73.29.85/img/399001.png"
Imgsource = "http://www.eastmoney.com /"
End select
Getastockimg = Split ("" & getastockimg & "|" & getastockimgb & "|" & imgsource & "", "| ")
End Function
%>
2. Web-Service Interface
2.1 Web-service of chinastock:
Http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx
China Stock Market Data Web Service (supporting all funds, bonds and stocks in Shenzhen and Shanghai stock markets), data is updated in real time. Output GIF time-sharing trend chart, daily/weekly/monthly K-line chart, and timely market data (stock name, market time, latest price, closing price, current opening, rising/falling value, lowest, highest, rising/falling, transaction volume, transaction volume, competitive price, competitive price, commission ratio, buy one-buy five, sell one-sell five ). This Web Service provides the following interfaces:
2.1.1 getstockimagebycode
Get stock GIF trend chart
Input: thestockcode = stock code, for example, sh120001
Post/WebServices/chinastockwebservice. asmx HTTP/1.1
HOST: www.webxml.com.cn
Content-Type: text/XML; charset = UTF-8
Content-Length: Length
Soapaction: "http://WebXml.com.cn/getStockImageByCode"


String


Output:
2.1.2 getstockimagebytebycode
Get the byte array of the GIF trend chart of Chinese stocks
Input: thestockcode = stock code, for example, sh120001
Post/WebServices/chinastockwebservice. asmx HTTP/1.1 HOST: www.webxml.com. cncontent-type: text/XML; charset = utf-8Content-Length: lengthsoapaction: "http://WebXml.com.cn/getStockImageByteByCode" String
The returned data is as follows:
Bytes
2.1.3 getstockimage_kbycode
Directly obtain the GIF daily/weekly/monthly K line chart of the Chinese Stock (545*300 pixel/72 dpi)
Input: thestockcode = stock code
Thetype = K line chart type (D: daily [Default], W: Week, M: month ),
Post/WebServices/chinastockwebservice. asmx HTTP/1.1 HOST: www.webxml.com. cncontent-type: text/XML; charset = utf-8Content-Length: lengthsoapaction: "http://WebXml.com.cn/getStockImage_kByCode" string
For example, enter as follows:
The returned result is the weekly K-line chart:
2.1.4 getstockimage_kbytebycode
Get the byte array of the China Stock GIF daily/weekly/monthly K-line chart
Input: thestockcode = stock code, for example, sh120001
Post/WebServices/chinastockwebservice. asmx HTTP/1.1 HOST: www.webxml.com. cncontent-type: text/XML; charset = utf-8Content-Length: lengthsoapaction: "http://WebXml.com.cn/getStockImage_kByteByCode" string HTTP/1.1 200 okcontent-type: text/XML; charset = utf-8Content-Length: length base64binary
For example, follow the input:
The returned result is a weekly K-line chart byte array.
Bytes
2.1.5 getstockinfobycode
Obtain timely quotations for Chinese stocks
Input: thestockcode = stock code
Post/WebServices/chinastockwebservice. asmx HTTP/1.1 HOST: www.webxml.com. cncontent-type: text/XML; charset = utf-8Content-Length: lengthsoapaction: "http://WebXml.com.cn/getStockInfoByCode" String
The returned value is a one-dimensional string array string (24). Its structure is string (0) stock code, string (1) stock name, string (2) market time, string (3) latest price (yuan), string (4) closing (yuan), string (5) current opening (yuan), string (6) Increase/fall (yuan), string (7) lowest (yuan), string (8) highest (yuan), string (9) Rise/fall (%), string (10) transaction volume (hand), string (11) transaction amount (10 million) string (12) price (yuan), string (13) price (yuan), string (14) Commission Ratio (%), string (15)-string (19) buy one-buy five (yuan)/hand, string (20)-string (24) sell one-sell five (yuan)/hand.
The Web service method is similar to the current project's dbws data acquisition. It uses the SOAP protocol to obtain relevant data from the dbws server.
Use Yahoo to check Chinese shares
Http://quote.yahoo.com/d/quotes.csv? S = MSFT & F = slc1wop
Back to Microsoft's stock price
"MSFT", "4: 00 pm- 30.70", + 1.04," 21.46-30.75 ", 29.77, 29.66
Http://quote.yahoo.com/d/quotes.csv? S = 000969.sz& F = slc1wop
This is returned by Antai technology, Generally, there is a latency of half an hour..
But the sz after S = 000969.sz is the meaning of Shenzhen, and Shanghai is the SS suffix.

 

Tags: stock data

 

 

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.