banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

Use Sina API to access the data interface of Sina Finance's stock market (real-time quotes, K-line, etc.).

title: "Using Sina API to Retrieve Securities Stock Data Interface from Sina Finance (Real-time K-line, etc.)"
date: "2012-06-19"
categories:

  • "sourceandcoding"
    tags:
  • "api"
  • "html"
  • "javascript"
  • "sina"
  • "internet"
  • "shares"
  • "securities"

Found a financial API of Sina API online, marking it for future reference.
http://market.finance.sina.com.cn/downxls.php?date=2011-07-08&symbol=sh600900
Get the transaction details of sh600900 on 2011-07-08, the data is in xls format.
http://vip.stock.finance.sina.com.cn/quotes\_service/view/cn\_price.php?symbol=sh600900
Obtain the price table of sh600900 for the day.
http://market.finance.sina.com.cn/pricehis.php?symbol=sh600900&startdate=2011-08-17&enddate=2011-08-19
Obtain the price table of sh600900 from 2011-08-17 to 2011-08-19.

Taking Daqin Railway (stock code: 601006) as an example, if you want to get its latest market information, just access Sina's stock data interface: http://hq.sinajs.cn/list=sh601006. This URL will return 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, 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";
This string is composed of many data concatenated together, with different meanings separated by commas. According to the programmer's mindset, the sequence number starts from 0.
0: "Daqin Railway", stock name;
1: "27.55", today's opening price;
2: "27.25", yesterday's closing price;
3: "26.91", current price;
4: "27.55", today's highest price;
5: "26.20", today's lowest price;
6: "26.91", bid price, i.e. "buy one" quote;
7: "26.92", ask price, i.e. "sell one" quote;
8: "22114263", number of shares traded, since stock trading is based on a unit of one hundred shares, usually this value is divided by one hundred when used;
9: "589824680", transaction amount, in "yuan", for clarity, usually this value is divided by ten thousand to represent the transaction amount in "ten thousand yuan";
10: "4695", "buy one" applies for 4695 shares, i.e. 47 lots;
11: "26.91", "buy one" quote;
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" applies for 3100 shares, i.e. 31 lots;
21: "26.92", "sell one" quote;
(22, 23), (24, 25), (26,27), (28, 29) represent "sell two" to "sell four" situations respectively;
30: "2008-01-11", date;
31: "15:05:32", time;
This interface is very convenient for JavaScript programs. The usual usage is to statically or dynamically insert it into the page:

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, simply add a comma at the end of the URL, followed by the stock codes. For example, if you want to query the market information of Daqin Railway (601006) and Datong Coal Industry (601001) at once, use this URL:
http://hq.sinajs.cn/list=sh601003,sh601001
However, if you want to query the market index, the situation will be different. For example, to query the Shanghai Composite Index (000001), use the following URL:
http://hq.sinajs.cn/list=s\_sh000001. The data returned by the server is:
var hq_str_s_sh000001="Shanghai Composite Index, 3094.668, -128.073, -3.97, 436653, 5458126";
The data meanings are respectively: index name, current points, current price, rate of change, trading volume (in lots), trading amount (in ten thousand yuan);
The URL for querying the Shenzhen Component Index is:
http://hq.sinajs.cn/list=s\_sz399001
For obtaining K-line charts, daily charts, etc. of stocks, you can use the request http://image.sinajs.cn/…./…/\*.gif, where * represents the stock code.

See below for details:
Daily K-line:
http://image.sinajs.cn/newchart/daily/n/sh000001.gif

Minute chart:
http://image.sinajs.cn/newchart/min/n/sh000001.gif

Daily K-line:
http://image.sinajs.cn/newchart/daily/n/sh000001.gif

Weekly K-line:
http://image.sinajs.cn/newchart/weekly/n/sh000001.gif

Monthly K-line:
http://image.sinajs.cn/newchart/monthly/n/sh000001.gif

Original article link:
http://mizarrr.blog.163.com/blog/static/1651594112011101882538362/

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.