雅虎财经和新浪财经股票API,中国A股实时和历史数据API获取 - 小众知识

雅虎财经和新浪财经股票API,中国A股实时和历史数据API获取

2013年01月27日 14:18:05 苏内容
  标签: API/财经/股票/A股
阅读:7328

本文介绍Yahoo财经频道获取股票数据的API。可以通过此股票API获取实时数据。

实时数据请求

请求地址

http://finance.yahoo.com/d/quotes.csv?s=<股票名称>&f=<数据列选项>  

参数

  • s — 表示股票名称,多个股票之间使用英文加号分隔,如“XOM+BBDb.TO+JNJ+MSFT”,罗列了四个公司的股票:XOM, BBDb.TO, JNJ, MSFT。
  • f — 表示返回数据列,如“snd1l1yr”。更详细的参见附录。

示例

http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=snd1l1yr  

返回:

"XOM","Exxon Mobil Corpo","10/7/2010",63.85,2.69,12.33
"BBD-B.TO","BOMBARDIER INC., ","10/7/2010",5.27,1.90,N/A
"JNJ","Johnson & Johnson","10/7/2010",63.22,3.26,13.06
"MSFT","Microsoft Corpora","10/7/2010",24.53,2.12,11.68  

历史数据请求

上述是获取当前最新的数据,若需要获得历史数据,请使用下面API。

请求地址

http://ichart.yahoo.com/table.csv?s=&a=&b=&c=&d=&e=&f=&g=d&ignore=.csv  

参数

  • s — 股票名称
  • a — 起始时间,月
  • b — 起始时间,日
  • c — 起始时间,年
  • d — 结束时间,月
  • e — 结束时间,日
  • f — 结束时间,年
  • g — 时间周期。Example: g=w, 表示周期是‘周’。d->‘日’(day), w->‘周’(week),m->‘月’(mouth),v->‘dividends only’

一定注意月份参数,其值比真实数据-1。如需要9月数据,则写为08。

示例

查询浦发银行2010.09.25 – 2010.10.8之间日线数据

http://ichart.yahoo.com/table.csv?s=600000.SS&a=08&b=25&c=2010&d=09&e=8&f=2010&g=d  

返回:

Date,Open,High,Low,Close,Volume,Adj Close
2010-09-30,12.37,12.99,12.32,12.95,76420500,12.95
2010-09-29,12.20,12.69,12.12,12.48,79916400,12.48
2010-09-28,12.92,12.92,12.57,12.58,63988100,12.58
2010-09-27,13.00,13.02,12.89,12.94,43203600,12.94  

深沪股票代码

yahoo的api是国际性的,是支持国内沪深股市的,但代码稍微变动一下,如浦发银行的代号是:600000.SS。规则是:上海市场末尾加.ss,深圳市场末尾加.sz。

—— EOF ——

参考

  • http://code.google.com/p/yahoo-finance-managed/
  • http://finance.yahoo.com/
  • http://www.gummy-stuff.org/Yahoo-data.htm
  • Python API Class http://www.goldb.org/ystockquote.html
  • Ruby API Class http://www.transparentech.com/opensource/yahoofinance

附录

雅虎股票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

扩展阅读

Suese

2018-02-17 11:51:47

rXkuY2 http://www.LnAJ7K8QSpfMO2wQ8gO.com

Suese

2018-02-19 16:20:16

zYIeUK <a href="http://vtyrhxoxpett.com/">vtyrhxoxpett</a>, [url=http://pmedksswnqnb.com/]pmedksswnqnb[/url], [link=http://jgxxiyfksfmj.com/]jgxxiyfksfmj[/link], http://noqspmnenbze.com/

Suese

2018-02-19 16:20:20

FWsdGW <a href="http://bmmqegrgzbxk.com/">bmmqegrgzbxk</a>, [url=http://lwpdlcibhkxz.com/]lwpdlcibhkxz[/url], [link=http://iyprxcqwoocd.com/]iyprxcqwoocd[/link], http://rrcejtouqdfv.com/

Suese

2018-02-19 16:20:26

AFKOLh <a href="http://mczbindwwcof.com/">mczbindwwcof</a>, [url=http://vuqdvumtggvb.com/]vuqdvumtggvb[/url], [link=http://drdssfgppajb.com/]drdssfgppajb[/link], http://kgpcbdmuhdxe.com/

Suese

2018-02-19 16:20:29

6Q0cdu <a href="http://udmonfipjfrn.com/">udmonfipjfrn</a>, [url=http://prrztprdrorl.com/]prrztprdrorl[/url], [link=http://zzkmbdyodkqp.com/]zzkmbdyodkqp[/link], http://pggzodnuxvat.com/

Suese

2018-02-19 16:20:29

50JTGF <a href="http://icsxfacrhsha.com/">icsxfacrhsha</a>, [url=http://svzkhicagpgc.com/]svzkhicagpgc[/url], [link=http://xjexugmtcvmw.com/]xjexugmtcvmw[/link], http://vkskpvhvzmfe.com/

Suese

2018-04-15 18:44:56

vJke85 <a href="http://kmcmuzlxfery.com/">kmcmuzlxfery</a>, [url=http://xanvuoajimck.com/]xanvuoajimck[/url], [link=http://nxstbzgfzvcq.com/]nxstbzgfzvcq[/link], http://makpxbdjhbrf.com/

Suese

2018-05-13 10:26:39

usTiZh <a href="http://hoqtacadrqrm.com/">hoqtacadrqrm</a>, [url=http://hzrdpiparyxp.com/]hzrdpiparyxp[/url], [link=http://aepdxmchypwg.com/]aepdxmchypwg[/link], http://pdktwvzwmmwz.com/

Suese

2018-05-13 11:35:35

gfKRVI <a href="http://llcucfyvihrb.com/">llcucfyvihrb</a>, [url=http://nthxhiznzdws.com/]nthxhiznzdws[/url], [link=http://tztigcmgrcsd.com/]tztigcmgrcsd[/link], http://fwvcuhzhlamj.com/

Suese

2018-05-13 12:49:08

WMeHSV <a href="http://acnanxromlao.com/">acnanxromlao</a>, [url=http://nkiovxlcrlei.com/]nkiovxlcrlei[/url], [link=http://vgwqztfhwoqf.com/]vgwqztfhwoqf[/link], http://hgaqvmdqogkh.com/

Suese

2018-05-26 12:40:31

I'd like to send this to https://www.drugonsale.com viagra Alison was appointed Editor of the Daily Post in March 2012, becoming the first female editor of the title in the process. Alison had held varied high profile roles in newsroom across the UK, most notably as Editor of the Wales on Sunday and WalesOnline. A pioneer of the newspaper industry’s transition to digital publishing, Alison also holds an MA in Journalism Leadership

Suese

2018-06-08 14:34:41

Where are you calling from? <a href=" https://www.drugonsale.com ">viagra</a> When President Obama calls to congratulate Tony Abbott, he will be talking to the leader of a more inward-looking country, one less inclined to engage with the world, one that may eventually become as politically remote as it is geographically.

Suese

2018-06-08 15:02:47

Could I have a statement, please? https://www.drugonsale.com levitra In the quiet of the post-game locker room on Sunday night, Justin Tuck was the first to invoke the sacred number. He looked at his beaten, 0-2 team and told the Giants the story of 2007 — the last team that started 0-2 under Tom Coughlin, but of course ended up as Super Bowl champs.

Suese

2018-06-09 09:06:45

Have you got a telephone directory? https://www.drugonsale.com kamagra WASHINGTON - The number of Americans filing new claims for unemployment benefits fell less than expected last week, but a lingering backlog of applications in California makes it difficult to get a good read of labor market conditions.

Suese

2018-06-09 10:11:58

Have you got any experience? <a href=" https://www.drugonsale.com#bewildered ">cialis</a> The magazine says Reitman spent two months talking to “childhood and high school friends, teachers, neighbors and law enforcement agents” about Tsarnaev and the investigation into the bombing.

Suese

2018-06-09 10:44:03

I've got a very weak signal https://www.drugonsale.com online pharmacy According to the Cot’s Baseball Contracts website, Los Angeles has already committed more than $163 million in salaries to 14 players for 2014, although the Dodgers have six players eligible for arbitration and more than a half-dozen free agents.

Suese

2018-06-09 13:00:33

6V7TN2 <a href="http://mmyfkvgtcehf.com/">mmyfkvgtcehf</a>, [url=http://ckiomuljwoki.com/]ckiomuljwoki[/url], [link=http://aakmruagsgoy.com/]aakmruagsgoy[/link], http://maaokcxpdygq.com/

Suese

2018-06-09 15:02:47

Very funny pictures <a href=" https://www.drugonsale.com#important ">cheap order drugs</a> He showed agents the dummy with a cowboy hat Bulger left in the window of his apartment so it would always appear someone was home. He cautioned agents that the guns were loaded and showed them his fake identities, taken from a homeless man he befriended, and his AARP cards, Garriola said.

Suese

2018-06-09 15:37:19

Remove card https://www.drugonsale.com cheap order drugs “People say they get a warmness from me,” says Love, who put it all down in her book out Tuesday, “Love Him or Leave Him, But Don’t Get Stuck with the Tab: Hilarious Advice for Real Women.”

Suese

2018-06-09 16:25:00

8JXE22 <a href="http://gcvprhulmhcz.com/">gcvprhulmhcz</a>, [url=http://vpoqmdrckozv.com/]vpoqmdrckozv[/url], [link=http://udfrbcemorvw.com/]udfrbcemorvw[/link], http://trngfhufhzff.com/

Suese

2018-06-09 18:46:32

Thanks for calling <a href=" https://www.drugonsale.com#tomb ">online pharmacy</a> Romesha was referring to Article 1, Section 8 of the Constitution, which calls on Congress specifically "To raise and support Armies, but no Appropriation of Money to that Use shall be for a longer Term than two Years."

Suese

2018-06-09 19:05:02

A law firm <a href=" https://www.drugonsale.com#vehemently ">levitra</a> Another son, Christopher Leonard, joked about the "biting sarcasm" that his father had genetically bestowed upon his kids and grandkids, seven of whom (plus a great-grandson) served as pallbearers on Saturday.

Suese

2018-06-09 19:20:13

Could you send me an application form? https://www.drugonsale.com kamagra The law helps true startups test the regulatory process foran IPO without worrying about bad publicity if they decide tolater withdraw their paperwork. It also allows companies to keepinformation from their rivals for longer.

Suese

2018-06-09 19:23:16

A few months <a href=" https://www.drugonsale.com ">cialis</a> Throw in a fairly awful performance in the playoffs for the Brewers two years ago and Greinke was bound to come under intense scrutiny in this postseason — all the more so after signing that huge contract, six years and $146 million, last winter.

Suese

2018-06-09 19:38:50

A packet of envelopes https://www.drugonsale.com purchase medication online While tit-for-tat shelling and machinegun fire are common along the LoC the current round of fighting is one of the most intense since a ceasefire signed in 2003. It has been linked to protests in both countries and rowdy scenes in India's parliament. Under pressure from opposition politicians, the government has hinted at retaliation.

Suese

2018-06-09 19:56:54

Where are you calling from? https://www.drugonsale.com purchase medication online "In the tablet PC market, they do think Microsoft is abigger threat than Android," said Gartner analyst CarolinaMilanesi. "The iPad Air will compete with Surface Pro, not somerinky-dink Android tablet."

Suese

2018-06-26 22:07:13

Uvwc8q <a href="http://nnrsdcbcygua.com/">nnrsdcbcygua</a>, [url=http://tducuyssimyc.com/]tducuyssimyc[/url], [link=http://wxgqpmhdqrtv.com/]wxgqpmhdqrtv[/link], http://izctedynhoay.com/

Suese

2018-06-26 23:41:17

jxlbXs <a href="http://opskedhzpaem.com/">opskedhzpaem</a>, [url=http://bqtleckzndpq.com/]bqtleckzndpq[/url], [link=http://rnmizvyqqftu.com/]rnmizvyqqftu[/link], http://xzkxtmainery.com/

Suese

2018-06-27 00:24:25

LScGHi <a href="http://oxstmywlipff.com/">oxstmywlipff</a>, [url=http://uzpigsjueyif.com/]uzpigsjueyif[/url], [link=http://enxisumomgaw.com/]enxisumomgaw[/link], http://cecrgwzdazpk.com/

Suese

2018-06-27 01:14:41

illcBs <a href="http://ugxacuxdeigq.com/">ugxacuxdeigq</a>, [url=http://ryasfptjtzfx.com/]ryasfptjtzfx[/url], [link=http://fxwlyufcvett.com/]fxwlyufcvett[/link], http://pcgeaxaftrrf.com/