logo资料库

sina股票接口,通过js取得数据.pdf

第1页 / 共16页
第2页 / 共16页
第3页 / 共16页
第4页 / 共16页
第5页 / 共16页
第6页 / 共16页
第7页 / 共16页
第8页 / 共16页
资料共16页,剩余部分请下载后查看
Andy's Andy's BlogBlogBlogBlog Andy's Andy's Blog » 技术 » 实时股票数据接口大全 实时股票数据接口大全 时间:2009-05-30 15:16:58 类别:技术 访问:4,214 views RSS 2.0 评论 实时股票数据接口大全 股票数据的获取目前有如下两种方法可以获取: 1. http/javascript 接口取数据 2. web-service 接口 1.http/javascript 1.http/javascript 1.http/javascript 1.http/javascript 接口取数据 1.1Sina 1.1Sina 1.1Sina 1.1Sina 股票数据接口 以大秦铁路(股票代码: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 应用例子: type="text/javascript"> var elements=hq_str_sh601006.split(","); document.write("current price:"+elements[3]); 这段代码输出大秦铁路(股票代码:601006)的当前股价 current price:14.20 如果你要同时查询多个股票,那么在 URL 最后加上一个逗号,再加上股票代码就可以了;比如你要一次查 询大秦铁路(601006)和大同煤业(601001)的行情,就这样使用 URL: http://hq.sinajs.cn/list=sh601003,sh601001 查询大盘指数,比如查询上证综合指数(000001): http://hq.sinajs.cn/list=s_sh000001 服务器返回的数据为: var hq_str_s_sh000001="上证指数,3094.668,-128.073,-3.97,436653,5458126"; 数据含义分别为:指数名称,当前点数,当前价格,涨跌率,成交量(手),成交额(万元); 查询深圳成指数: 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
1.21.21.21.2 Baidu&Google Baidu&Google Baidu&Google Baidu&Google 的财经数据 在 baidu, google 中搜索某只股票代码时,将会在头条显示此股票的相关信息,例如在 google 搜索601006 时, 第一条搜索结果如下图: 通过点击左边的图片我们发现会将此图片链接到 sina 财经频道上,也就是说 google 股票数据的获取也是 从 sina 获取。后经抓包分析,发现 google 也是采用1.1中介绍的接口。 Baidu 的股票数据来自 baidu 的财经频道 http://stock.baidu.com/ 1.31.31.31.3 其他方式 除了 sina,baidu 等网站提供股票信息外,其他网站也有类似的接口。我们分析了一款论坛上采用的股票 插件, 其中有关于实时股票数据获取的介绍,详见如下代码,其中可以看到有些数据来自 sina。 以下是 ASP 示例: <% ‘========================== ‘ file: stock_getdata.asp ‘ version: 1.0.0 ‘ copyright (c) czie.com all rights reserved. ‘ web: http://www.czie.com ‘========================== function gethttp(rurl) dim xml on error resume next set xml=server.createobject("Microsoft.XMLHTTP")
xml.open "get",rurl,false xml.send if not xml.readystate=4 or not xml.status=200 or err then gethttp="":exit function gethttp=xml.responsetext set xml=nothing end function function getstockdata(code) ‘0=股票名称,1=开盘价格,2=昨收盘价格,3=当前价格,4=最高价,5=最低价,30,31=更 新时间 dim checkcode,stockdata,stockdatasplit if len(code)<5 then stockdata="0,0,0,0,0,0,0,0,0,0,0,0":exit function checkcode=mid(code,len(code)-5,1) if int(checkcode)<=4 then stockdata=gethttp("http://hq.sinajs.cn/list=sz"&code&"") if not len(stockdata)=0 then stockdata=split(stockdata,chr(34))(1) end if if int(checkcode)>=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)&","&stockdat asplit(3)&","&stockdatasplit(4)&","&stockdatasplit(5)&","&formatdatetime(""&stockdatasplit(30)&" "&stockdatasplit(31)&"",0)&"" end if ‘0=股票名称,1=开盘价格,2=昨收盘价格,3=当前价格,4=最高价,5=最低价,6=更新时 间
getstockdata=stockdata end function function getstockimg(code) dim rndnum,addnum,checkcode,imgsource if len(code)<5 then exit function addnum=4 randomize:rndnum=cint(rnd*addnum) select case rndnum case 0 getstockimg="http://www.10jqka.com.cn/curve/kline/?code="&code&"" imgsource="http://www.10jqka.com.cn" case 1 getstockimg="http://stock.jrj.com.cn/htmdata/KLINE/"&code&".png" case 2 imgsource="http://stock.jrj.com.cn" checkcode=mid(code,len(code)-5,1) if int(checkcode)<=4 then getstockimg="http://image.sinajs.cn/newchart/daily/n/sz"&code&".gif" end if if int(checkcode)>=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 case 2 getastockimg="http://money.163.com/special/100.gif?C39" getastockimgb="http://money.163.com/special/101.gif?HrS" imgsource="http://www.163.com" getastockimg="http://www.10jqka.com.cn/curve/realtime/index2.php?code=1a0001&w=180&h=140"
分享到:
收藏