本文介绍Yahoo财经频道获取股票数据的API。可以通过此股票API获取实时数据。
返回:
上述是获取当前最新的数据,若需要获得历史数据,请使用下面API。
一定注意月份参数,其值比真实数据-1。如需要9月数据,则写为08。
查询浦发银行2010.09.25 – 2010.10.8之间日线数据
返回:
yahoo的api是国际性的,是支持国内沪深股市的,但代码稍微变动一下,如浦发银行的代号是:600000.SS。规则是:上海市场末尾加.ss,深圳市场末尾加.sz。
—— EOF ——
雅虎股票API f参数对照表
a | Ask | a2 | Average Daily Volume | a5 | Ask Size |
b | Bid | b2 | Ask (Real-time) | b3 | Bid (Real-time) |
b4 | Book Value | b6 | Bid Size | c | Change & Percent Change |
c1 | Change | c3 | Commission | c6 | Change (Real-time) |
c8 | After Hours Change (Real-time) | d | Dividend/Share | d1 | Last Trade Date |
d2 | Trade Date | e | Earnings/Share | e1 | Error Indication (returned for symbol changed / invalid) |
e7 | EPS Estimate Current Year | e8 | EPS Estimate Next Year | e9 | EPS Estimate Next Quarter |
f6 | Float Shares | g | Day’s Low | h | Day’s High |
j | 52-week Low | k | 52-week High | g1 | Holdings Gain Percent |
g3 | Annualized Gain | g4 | Holdings Gain | g5 | Holdings Gain Percent (Real-time) |
g6 | Holdings Gain (Real-time) | i | More Info | i5 | Order Book (Real-time) |
j1 | Market Capitalization | j3 | Market Cap (Real-time) | j4 | EBITDA |
j5 | Change From 52-week Low | j6 | Percent Change From 52-week Low | k1 | Last Trade (Real-time) With Time |
k2 | Change Percent (Real-time) | k3 | Last Trade Size | k4 | Change From 52-week High |
k5 | Percebt Change From 52-week High | l | Last Trade (With Time) | l1 | Last Trade (Price Only) |
l2 | High Limit | l3 | Low Limit | m | Day’s Range |
m2 | Day’s Range (Real-time) | m3 | 50-day Moving Average | m4 | 200-day Moving Average |
m5 | Change From 200-day Moving Average | m6 | Percent Change From 200-day Moving Average | m7 | Change From 50-day Moving Average |
m8 | Percent Change From 50-day Moving Average | n | Name | n4 | Notes |
o | Open | p | Previous Close | p1 | Price Paid |
p2 | Change in Percent | p5 | Price/Sales | p6 | Price/Book |
q | Ex-Dividend Date | r | P/E Ratio | r1 | Dividend Pay Date |
r2 | P/E Ratio (Real-time) | r5 | PEG Ratio | r6 | Price/EPS Estimate Current Year |
r7 | Price/EPS Estimate Next Year | s | Symbol | s1 | Shares Owned |
s7 | Short Ratio | t1 | Last Trade Time | t6 | Trade Links |
t7 | Ticker Trend | t8 | 1 yr Target Price | v | Volume |
v1 | Holdings Value | v7 | Holdings Value (Real-time) | w | 52-week Range |
w1 | Day’s Value Change | w4 | Day’s Value Change (Real-time) | x | Stock Exchange |
y | Dividend Yield |
Sina股票数据接口
以大秦铁路(股票代码:601006)为例,如果要获取它的最新行情,只需访问新浪的股票数据
接口:http://hq.sinajs.cn/list=sh601006这个url会返回一串文本,例如:
var hq_str_sh601006="大秦铁路, 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";
这个字符串由许多数据拼接在一起,不同含义的数据用逗号隔开了,按照程序员的思路,顺序号从0开始。
0:”大秦铁路”,股票名字;
1:”27.55″,今日开盘价;
2:”27.25″,昨日收盘价;
3:”26.91″,当前价格;
4:”27.55″,今日最高价;
5:”26.20″,今日最低价;
6:”26.91″,竞买价,即“买一”报价;
7:”26.92″,竞卖价,即“卖一”报价;
8:”22114263″,成交的股票数,由于股票交易以一百股为基本单位,所以在使用时,通常把该值除以一百;
9:”589824680″,成交金额,单位为“元”,为了一目了然,通常以“万元”为成交金额的单位,所以通常把该值除以一万;
10:”4695″,“买一”申请4695股,即47手;
11:”26.91″,“买一”报价;
12:”57590″,“买二”
13:”26.90″,“买二”
14:”14700″,“买三”
15:”26.89″,“买三”
16:”14300″,“买四”
17:”26.88″,“买四”
18:”15100″,“买五”
19:”26.87″,“买五”
20:”3100″,“卖一”申报3100股,即31手;
21:”26.92″,“卖一”报价
(22, 23), (24, 25), (26,27), (28, 29)分别为“卖二”至“卖四的情况”
30:”2008-01-11″,日期;
31:”15:05:32″,时间;
这个接口对于JavaScript程序非常方便,通常的使用方式为,静态或动态地在页面中插入:
<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>
这段代码输出大秦铁路(股票代码:601006)的当前股价
current price:14.20
如果你要同时查询多个股票,那么在URL最后加上一个逗号,再加上股票代码就可以了;比如你要一次查询大秦铁路(601006)和大同煤业(601001)的行情,就这样使用URL:
http://hq.sinajs.cn/list=sh601003,sh601001
但如果你要查询大盘指数,情况会有不同,比如查询上证综合指数(000001),使用如下URL:
http://hq.sinajs.cn/list=s_sh000001 服务器返回的数据为:
var hq_str_s_sh000001="上证指数,3094.668,-128.073,-3.97,436653,5458126";
数据含义分别为:指数名称,当前点数,当前价格,涨跌率,成交量(手),成交额(万元);
查询深圳成指的URL为:
http://hq.sinajs.cn/list=s_sz399001
对于股票的K线图,日线图等的获取可以通过请求http://image.sinajs.cn/…./…/*.gif此URL获取,其中*代表股票代码,详见如下:
查看日K线图:
http://image.sinajs.cn/newchart/daily/n/sh601006.gif
分时线的查询:
http://image.sinajs.cn/newchart/min/n/sh000001.gif
日K线查询:
http://image.sinajs.cn/newchart/daily/n/sh000001.gif
周K线查询:
http://image.sinajs.cn/newchart/weekly/n/sh000001.gif
月K线查询:
http://image.sinajs.cn/newchart/monthly/n/sh000001.gif