請求地址javascript
http://finance.yahoo.com/d/quotes.csv?s=<股票名稱>&f=<數據列選項> html
參數java
s — 表示股票名稱,多個股票之間使用英文加號分隔,如「XOM+BBDb.TO+JNJ+MSFT」,羅列了四個公司的股票:XOM, BBDb.TO, JNJ, MSFT。程序員
f — 表示返回數據列,如「snd1l1yr」。更詳細的參見附錄。api
示例服務器
http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=snd1l1yr ide
返回:google
"XOM","Exxon Mobil Corpo","10/7/2010",63.85,2.69,12.33url
"BBD-B.TO","BOMBARDIER INC., ","10/7/2010",5.27,1.90,N/Aspa
"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參數對照表
aAska2Average Daily Volumea5Ask Size
bBidb2Ask (Real-time)b3Bid (Real-time)
b4Book Valueb6Bid SizecChange & Percent Change
c1Changec3Commissionc6Change (Real-time)
c8After Hours Change (Real-time)dDividend/Shared1Last Trade Date
d2Trade DateeEarnings/Sharee1Error Indication (returned for symbol changed / invalid)
e7EPS Estimate Current Yeare8EPS Estimate Next Yeare9EPS Estimate Next Quarter
f6Float SharesgDay’s LowhDay’s High
j52-week Lowk52-week Highg1Holdings Gain Percent
g3Annualized Gaing4Holdings Gaing5Holdings Gain Percent (Real-time)
g6Holdings Gain (Real-time)iMore Infoi5Order Book (Real-time)
j1Market Capitalizationj3Market Cap (Real-time)j4EBITDA
j5Change From 52-week Lowj6Percent Change From 52-week Lowk1Last Trade (Real-time) With Time
k2Change Percent (Real-time)k3Last Trade Sizek4Change From 52-week High
k5Percebt Change From 52-week HighlLast Trade (With Time)l1Last Trade (Price Only)
l2High Limitl3Low LimitmDay’s Range
m2Day’s Range (Real-time)m350-day Moving Averagem4200-day Moving Average
m5Change From 200-day Moving Averagem6Percent Change From 200-day Moving Averagem7Change From 50-day Moving Average
m8Percent Change From 50-day Moving AveragenNamen4Notes
oOpenpPrevious Closep1Price Paid
p2Change in Percentp5Price/Salesp6Price/Book
qEx-Dividend DaterP/E Ratior1Dividend Pay Date
r2P/E Ratio (Real-time)r5PEG Ratior6Price/EPS Estimate Current Year
r7Price/EPS Estimate Next YearsSymbols1Shares Owned
s7Short Ratiot1Last Trade Timet6Trade Links
t7Ticker Trendt81 yr Target PricevVolume
v1Holdings Valuev7Holdings Value (Real-time)w52-week Range
w1Day’s Value Changew4Day’s Value Change (Real-time)xStock Exchange
yDividend 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