Real-time Stock data interface

Source: Internet
Author: User
Tags stock prices

There are two ways to get the stock data now:
1. Http/javascript Interface Fetch data
2. Web-service interface
1.http/javascript Interface Fetch Data
1.1Sina Stock Data Interface
Take the Great Qin Railway (stock code: 601006) For example, if you want to get its latest market, just visit Sina's stock data
Interface:
http://hq.sinajs.cn/list=sh601006
This URL returns a string of text, for example:
var hq_str_sh601006= "Great Qin Railway, 27.55, 27.25, 26.91, 27.55, 26.20, 26.91, 26.92,
22114263, 589824680, 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, 2008-01-11, 15:05:32 ";
The string is stitched together by a lot of data, with different meanings separated by commas, and the sequence number starts with 0, according to the programmer's idea.
0: "Great Qin Railway", Stock name;
1: "27.55″, open today;
2: "27.25″, yesterday close;
3: "26.91″, current price;
4: "27.55″, today's highest price;
5: "26.20″, today's lowest price;
6: "26.91″, bid price, namely" buy one "offer;
7: "26.92″, bid price, namely" sell one "offer;
8: "22114263″, the number of shares traded, as the stock trading with 100 shares as the basic unit, so when used, the value is usually divided by 100;
9: "589824680″, deal amount, unit for" Yuan ", for a glance, usually" million "for the transaction amount of units, so usually the value divided by 10,000;
10: "4695″," "Buy a" application 4695 shares, that is, 47 lot;
11: "26.91″", "buy one" offer;
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, namely 31 lot;
21: "26.92″", "sell one" offer
(22, 23), (24, 25), (26,27), (28, 29) respectively "sell two" to "sell four"
30: "2008-01-11″, date;
31: "15:05:32″, time;
An example of a simple JavaScript application:
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 the Great Qin Railway (stock code: 601006)
Current price:14.20
If you want to query multiple shares at the same time, then add a comma at the end of the URL, plus the stock code on it, for example, you want to query the Da Qin Railway (601006) and Datong Coal (601001) quotes, so use the URL:
http://hq.sinajs.cn/list=sh601003,sh601001
Query the market index, 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 index, 3094.668,-128.073,-3.97,436653,5458126";
Data meanings are: Index name, current point, current price, rate of rise and fall, turnover (hand), turnover (million);
Query Szse Component number:
http://hq.sinajs.cn/list=s_sz399001
For stock candlestick Chart, the acquisition of daily charts and so on can be obtained by requesting http://image.sinajs.cn/..../.../*.gif this URL, where * represents the stock code, as described below:
View Daily Candlestick Chart:
Http://image.sinajs.cn/newchart/daily/n/sh601006.gif
(turn in case it's useful) ">
Time-sharing line query:
Http://image.sinajs.cn/newchart/min/n/sh000001.gif
(Turn in case it's useful) ">
Daily Candlestick Query:
Http://image.sinajs.cn/newchart/daily/n/sh000001.gif
(turn in case it's useful) ">
Weekly Candlestick Query:
Http://image.sinajs.cn/newchart/weekly/n/sh000001.gif
(turn in case it's useful) ">
Monthly candlestick Query:
Http://image.sinajs.cn/newchart/monthly/n/sh000001.gif
(turn in case it's useful) ">
1.2 Baidu&google's financial data
In Baidu, when searching for a stock ticker in Google, information about the stock is displayed in the headlines, such as when Google searches for 601006,
The first search results are as follows:
By clicking on the image on the left we find that the image is linked to the Sina Financial channel, which means that Google stock data acquisition is also obtained from Sina. After the capture packet analysis, found that Google is also used in 1.1 of the interface described.
Baidu's stock data from Baidu's financial channel
http://stock.baidu.com/
1.3 Other ways
In addition to Sina,baidu and other sites provide stock information, other sites also have similar interface. We analyzed the stock plugin used on a forum,
There is an introduction to real-time stock data acquisition, as shown in the following code, where you can see some data 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,0,0,0"
Else
Stockdatasplit=split (StockData, ",") stockdata= "" &exstock.checkstr (stockdatasplit (0)) & "," & Stockdatasplit (1) & "," &stockdatasplit (2) & "," &stockdatasplit (3) & "," &stockdatasplit (4) & "," &stockdatasplit (5) & "," &formatdatetime ("" &stockdatasplit () & "" &stockdatasplit ( ) & "", 0) & ""
End If
' 0= stock name, 1 = Open price, 2 = Last Close price, 3 = Current price, 4 = high price, 5 = Low 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 Chinastock's Web-service:
Http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx
China stock market Data WEB Service (all funds, bonds and shares supported in Shenzhen and Shanghai stock markets), the data is updated immediately. Output GIF tick chart, day/week/month Candlestick chart, timely market data (stock name, Market Time, latest price, yesterday close, this open, up and down, the lowest, highest, change, volume, turnover, bid price, bid bid, commission ratio, buy one-buy five, sell one-sell five). This Web service provides a few interfaces as follows:
2.1.1 Getstockimagebycode
GET Stock GIF Tick chart
Input:thestockcode = stock code, such as: sh000001
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 Chinese stock gif tick chart byte array
Input:thestockcode = stock code, such as: sh000001
Post/webservices/chinastockwebservice.asmx Http/1.1host:www.webxml.com.cncontent-type:text/xml; Charset=utf-8content-length:lengthsoapaction: "Http://WebXml.com.cn/getStockImageByteByCode" string
The returned data is as follows:
R0lgodlhiqisafcaaaaaaawl Bxkgbq4odhaqebsschuvfs4tdb8egqka9kopcdaazy4mfvgap2uyc0iqeuyubvwideasi1qnfx8agdu1nuozflgxd6cbwvy5fniwemq4gc0amlhdhpeadlvjm epksm1ihoubwpy3fzmyvy9igxrwiefmwgnyumpdpxjghqb8hk9eggbgx4lxiacoahhkmyt4m4vkjtstbv8a
2.1.3 Getstockimage_kbycode
Direct access to Chinese stock GIF day/week/month Candlestick Chart (545*300PIXEL/72DPI)
Input:thestockcode = Stock code
Thetype = Candlestick type (D: Day [Default], W: Week, M: Month),
Post/webservices/chinastockwebservice.asmx Http/1.1host:www.webxml.com.cncontent-type:text/xml; Charset=utf-8content-length:lengthsoapaction: "Http://WebXml.com.cn/getStockImage_kByCode" string string
For example, enter as shown:
The returned result is the weekly candlestick chart:
2.1.4 Getstockimage_kbytebycode
Get Chinese stock GIF day/week/month Candlestick Chart byte array
Input:thestockcode = stock code, such as: sh000001
Post/webservices/chinastockwebservice.asmx Http/1.1host:www.webxml.com.cncontent-type:text/xml; Charset=utf-8content-length:lengthsoapaction: "Http://WebXml.com.cn/getStockImage_kByteByCode" string string http/ 1.1 Okcontent-type:text/xml; Charset=utf-8content-length:length base64binary
For example, follow the input:
The returned result is the weekly candlestick chart byte array
r0lgodlhiqisafcaaaaaaawlbxkgbq4odhaqebsschuvfs4tdb8egqka9kopcdaazy4mfvgap2uyc0iqeuyubvwideasi1qnfx8agdu1nuozflgxd6cbwvy5f niwemq4gc0amlhdhpeadlvjmepksm1ihoubwpy3fzmyvy9igxrwiefmwgnyumpdpxjghqb8hk9eggbgx4lxiacoahhkmyt4m4vkjtstbv8a
2.1.5 Getstockinfobycode
Access to China stock market timely
Input:thestockcode = Stock code
Post/webservices/chinastockwebservice.asmx Http/1.1host:www.webxml.com.cncontent-type:text/xml; Charset=utf-8content-length:lengthsoapaction: "Http://WebXml.com.cn/getStockInfoByCode" string
Returns the value of a one-dimensional array of strings, string (24), with the structure: string (0) ticker symbol, string (1) Stock name, string (2) Quote time, String (3) latest price (Yuan), String (4) Last Close (yuan), string (5 ) today open (yuan), string (6) up (yuan), string (7) lowest (yuan), string (8) maximum (yuan), string (9) Change (%), string (10) volume (Lot), String (11) Turnover (million), String (12) bidding price (yuan), string (13) bid (yuan), string (14) commission (%), string (-string) (19) Buy one-buy five (yuan)/hand, String (-string) (24) Sell one- Sell five (yuan)/hand.
The Web service approach is similar to the current acquisition of DBWS data for concurrent projects, all of which fetch related data to the DBWS server through the SOAP protocol.
Using Yahoo to check Chinese stocks
Http://quote.yahoo.com/d/quotes.csv?s=MSFT&f=slc1wop
Back to Microsoft stock prices
"MSFT", "4:00pm- 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 return to Antai technology, There's usually a half-hour delay.
But S=000969.SZ this behind the SZ is the meaning of Shenzhen, Shanghai is the SS suffix

Real-time Stock data interface

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.