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?sh601006this urlwill return a string of records, 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;
This interface is very convenient for javascript programs. It is usually used to insert static or dynamic pages:
<SCRIPT type = "text/JavaScript" src = "http://hq.sinajs.cn/list=sh601006" charset = "gb2312">
</SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR elements = hq_str_sh601006.split (",");
Document. Write ("current price:" + elements [3]);
</SCRIPT>
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
However, if you want to query the index of the dashboard, the situation may be different. For example, to query the Shanghai Composite Index (000001), use the following URL:
Data returned by the http://hq.sinajs.cn/list=s_sh000001 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 );
The URL of the Shenzhen index is:
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
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
<? XML version = "1.0" encoding = "UTF-8"?>
<Soap: envelope xmlns: xsi = "The http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "The http://www.w3.org/2001/XMLSchema" xmlns: Soap = "The http://schemas.xmlsoap.org/soap/envelope/">
<Soap: Body>
<Getstockimagebycode xmlns = "http://WebXml.com.cn/">
<Thestockcode> string </thestockcode>
</Getstockimagebycode>
</Soap: Body>
</Soap: envelope>
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" <? XML version = "1.0" encoding = "UTF-8"?> <Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/soap/envelope/"> <soap: body> <getstockimagebytebycode xmns = "http://WebXml.com.cn/"> <thestockcode> string </thestockcode> </getstockimagebytebycode> </soap: Body> </soap: envelope>
The returned data is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Base64binary xmlns = "http://WebXml.com.cn/"> Encoding
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" <? XML version = "1.0" encoding = "UTF-8"?> <Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/soap/envelope/"> <soap: body> <getstockimage_kbycode xmlns = "http://WebXml.com.cn/"> <thestockcode> string </thestockcode> <thetype> string </thetype> </getstockimage_kbycode> </soap: body> </soap: envelope>
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" <? XML version = "1.0" encoding = "UTF-8"?> <Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/soap/envelope/"> <soap: body> <getstockimage_kbytebycode xmlns = "http://WebXml.com.cn/"> <thestockcode> string </thestockcode> <thetype> string </thetype> </getstockimage_kbytebycode> </soap: body> </soap: envelope> HTTP/1.1 200 okcontent-type: text/XML; Cha Rset = utf-8Content-Length: length <? XML version = "1.0" encoding = "UTF-8"?> <Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/soap/envelope/"> <soap: body> <strong xmlns = "http://WebXml.com.cn/"> <getstockimage_kbytebycoderesult> base64binary </getstockimage_kbytebycoderesult> </strong> </soap: Body> </soap: envelope> according to input
:
The returned result is a weekly K-line chart byte array.
<? XML version = "1.0" encoding = "UTF-8"?>
<Base64binary xmlns = "http://WebXml.com.cn/"> Encoding
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" <? XML version = "1.0" encoding = "UTF-8"?> <Soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/soap/envelope/"> <soap: body> <getstockinfobycode xmlns = "http://WebXml.com.cn/"> <thestockcode> string </thestockcode> </getstockinfobycode> </soap: Body> </soap: the value returned by envelope> 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", "PM-<B> 30.70 </B>", + 1.04, "21.46-30.75", 29.77, 29.66
Http://quote.yahoo.com/d/quotes.csv? S = 000969.sz& F = slc1wop
This returned result is generally a latency of half an hour.
But what does the sz after S = 000969.sz mean?
Shenzhen :)
Shanghai stock market is an SS suffix