获取股票实时交易数据的方法 - 小众知识

获取股票实时交易数据的方法

2013年01月27日 14:18:05 苏内容
  标签: 实时/股票/方法
阅读:7328
调用sina专门的js服务器来获得数据,速度飞快:

返回
var hq_str_sh600151="航天机电,7.08,7.09,6.95,7.08,6.90,6.95,6.96,4368014,30484831,2900,6.95,5700,6.94,11687,6.93,19700,6.92,28200,6.91,700,6.96,6000,6.97,26600,6.98,21701,6.99,104259,7.00,2012-06-12,15:03:05";
var hq_str_sz000830="鲁西化工,4.90,4.93,4.85,4.90,4.83,4.84,4.85,5637089,27390414.02,147400,4.84,123000,4.83,90200,4.82,103300,4.81,280200,4.80,37510,4.85,34949,4.86,27899,4.87,31500,4.88,75400,4.89,2012-06-12,15:05:52";
var hq_str_s_sh000001="上证指数,2289.791,-16.065,-0.70,599419,5529858";
var hq_str_s_sz399001="深证成指,9790.197,-59.573,-0.60,71142542,5714888";
var hq_str_s_sz399106="深证综指,942.182,-3.439,-0.36,49774192,5544763";
var hq_str_s_sz399107="深证A指,985.824,-3.544,-0.36,49558295,5535505";
var hq_str_s_sz399108="深证B指,621.687,-5.293,-0.84,215896,9258";

注:
上证指数(指数名称),2289.791(当前点数),-16.065(涨跌额),-0.70(涨跌幅度),599419(总手),5529858(成交金额)";
"航天机电,名称
7.08,今开
7.09,昨收
6.95,当前
7.08,今日最高
6.90,今日最低
6.95,竞买价,即买一报价
6.96,竞卖价,即卖一报价
4368014,成交的股票数量,应除以100
30484831,成交金额,单位为元
2900,6.95,买一申请股数(29手),买一报价
5700,6.94,买二申请,买二报价
11687,6.93,买三申请,买三报价
19700,6.92,买四申请,买四报价
28200,6.91,买五申请,买五报价
700,6.96,卖一申请,卖一报价
6000,6.97,卖二申请,卖二报价
26600,6.98,卖三申请,卖三报价
21701,6.99,卖四申请,卖四报价
104259,7.00,卖五申请,卖五报价
2012-06-12,日期
15:03:05 时间
一共31个值。

返回
var hq_str_s_sz399001="深证成指,9790.197,-59.573,-0.60,71142542,5714888";
var hq_str_s_sz399002="成份A指,10776.287,-64.126,-0.59,6351301,791833";
var hq_str_s_sz399003="成份B指,4425.993,-39.460,-0.88,59239,4837";
var hq_str_s_sz399010="深证700,3403.759,-8.677,-0.25,17953551,1896751";
var hq_str_s_sz399106="深证综指,942.182,-3.439,-0.36,49774192,5544763";
var hq_str_s_sz399107="深证A指,985.824,-3.544,-0.36,49558295,5535505";
var hq_str_s_sz399108="深证B指,621.687,-5.293,-0.84,215896,9258";



返回
var hq_str_s_sh000001="上证指数,2289.791,-16.065,-0.70,599419,5529858";
var hq_str_s_sh000002="A股指数,2398.401,-16.998,-0.70,597460,5512715";
var hq_str_s_sh000003="B股指数,232.017,1.908,0.83,1958,17143";
var hq_str_s_sh000004="工业指数,1952.040,-17.161,-0.87,306777,3263599";
var hq_str_s_sh000005="商业指数,2650.303,-18.454,-0.69,19013,166771";
var hq_str_s_sh000006="地产指数,3500.208,60.763,1.77,46296,287382";
var hq_str_s_sh000007="公用指数,3769.470,-40.401,-1.06,63828,372671";
var hq_str_s_sh000008="综合指数,1931.844,-10.102,-0.52,163504,1439434";



返回
var hq_str_sh600151="航天机电,7.08,7.09,6.95,7.08,6.90,6.95,6.96,4368014,30484831,2900,6.95,5700,6.94,11687,6.93,19700,6.92,28200,6.91,700,6.96,6000,6.97,26600,6.98,21701,6.99,104259,7.00,2012-06-12,15:03:05";
var hq_str_sh600152="维科精华,6.89,7.10,6.94,6.97,6.48,6.83,6.84,17509035,116787535,4900,6.83,19900,6.82,3500,6.81,38800,6.80,100,6.79,26700,6.84,4000,6.85,1400,6.86,14500,6.89,13600,6.90,2012-06-12,15:03:05";
var hq_str_sh600153="建发股份,7.47,7.52,7.62,7.68,7.46,7.61,7.62,15063933,113836559,537575,7.61,77600,7.60,102600,7.59,93900,7.58,133299,7.57,41400,7.62,39800,7.63,129349,7.64,193540,7.65,130400,7.66,2012-06-12,15:03:05";
var hq_str_sz000830="鲁西化工,4.90,4.93,4.85,4.90,4.83,4.84,4.85,5637089,27390414.02,147400,4.84,123000,4.83,90200,4.82,103300,4.81,280200,4.80,37510,4.85,34949,4.86,27899,4.87,31500,4.88,75400,4.89,2012-06-12,15:05:52";


指数的格式
"s_sh"+"000001"

股票代码    股票名称
000001  上证指数
000002  A股指数
000003  B股指数
000004  工业指数
000005  商业指数
000006  地产指数
000007  公用指数
000010  上证180
000011  沪市基金
000012  国债指数
000013  企债指数
000015  红利指数
000016  上证50
000017  新 综 指
000019  治理指数
000042  上证央企
000043  超 大 盘
000049  上证民企
000054  上证海外
000055  上证地企
000056  上证国企
000057  全指成长
000058  全指价值
000059  全R成长
000060  全R价值
000061  沪企债30
000062  上证沪企
000063  上证周期
000064  非周期
000066  上证商品
000067  上证新兴
000300  沪深300
000926  中证央企(上)
000927  央企100(上)
000964  中证新兴
000999  两岸三地


"s_sz"+"399001"

399001  深证成指
399002  成份A指
399003  成份B指
399004  深证100R
399006  创业板指
399101  中小板综
399102  创业板综
399106  深证综指
399107  深证A指
399108  深证B指
399110  农林指数
399120  采掘指数
399130  制造指数
399131  食品指数
399132  纺织指数
399133  木材指数
399134  造纸指数
399135  石化指数
399136  电子指数
399137  金属指数
399138  机械指数
399139  医药指数
399140  水电指数
399150  建筑指数
399160  运输指数
399170  IT指数
399180  批零指数
399190  金融指数
399200  地产指数
399210  服务指数
399220  传播指数
399300  沪深300
399305  深市基金
399323  深证红利
399352  深报综指
399369  CBN-兴业
399481  企债指数
399606  创业板R
399926  中证央企(深)
399927  央企100(深)




返回
fortune_hq({"cna":[["上证指数","2289.79","-16.06","-0.70%","http://q.stock.sohu.com/zs/000001/index.shtml"],["深证成指","9790.20","-59.57","-0.60%","http://q.stock.sohu.com/zs/399001/index.shtml"],["中小板综","5253.22","-13.70","-0.26%","http://q.stock.sohu.com/zs/399101/index.shtml"]],"cnb":[["B股指数","232.02","1.91","0.83%","http://q.stock.sohu.com/zs/000003/index.shtml"],["成份B指","4425.99","-39.46","-0.88%","http://q.stock.sohu.com/zs/399003/index.shtml"]],"cnf":[["沪市基金","3824.81","-21.85","-0.57%","http://q.stock.sohu.com/zs/000011/index.shtml"],["深市基金","4601.38","-25.05","-0.54%","http://q.stock.sohu.com/zs/399305/index.shtml"]],"hk":[["恒生指数","18872.56","-81.07","-0.43%","http://q.stock.sohu.com/hk/HSI/index.shtml"],["国企指数","9519.53","-55.27","-0.58%","http://q.stock.sohu.com/hk/HSCEI/index.shtml"],["红筹指数","3789.30","-3.77","-0.10%","http://q.stock.sohu.com/hk/HSCCI/index.shtml"]],"us":[["道琼斯工业指数","12411.23","-142.97","-1.14%","http://q.stock.sohu.com/us/index.shtml?DJI"],["纳斯达克综合指数","2809.73","-48.69","-1.70%","http://q.stock.sohu.com/us/index.shtml?IXIC"],["标准普尔500指数","1312.39","3.46","0.26%","http://q.stock.sohu.com/us/index.shtml?GSPC"]]})

 
http://hq.stock.sohu.com/hqindex/finaceindex/financeindexhq2.js
返回
PEAK_ODIA(['financeindexhq',[['zs_000001','上证指数','2289.79','-16.06','-0.70%','http://q.stock.sohu.com/zs/000001/index.shtml'],['zs_399001','深证成指','9790.20','-59.57','-0.60%','http://q.stock.sohu.com/zs/399001/index.shtml'],['zs_399101','中小板综','5253.22','-13.70','-0.26%','http://q.stock.sohu.com/zs/399101/index.shtml'],['zs_000003','B股指数','232.02','+1.91','0.83%','http://q.stock.sohu.com/zs/000003/index.shtml'],['zs_399003','成份B指','4425.99','-39.46','-0.88%','http://q.stock.sohu.com/zs/399003/index.shtml'],['zs_000011','沪市基金','3824.81','-21.85','-0.57%','http://q.stock.sohu.com/zs/000011/index.shtml'],['zs_399305','深市基金','4601.38','-25.05','-0.54%','http://q.stock.sohu.com/zs/399305/index.shtml'],['HSI','恒生指数','18872.56','-81.07','-0.43%','http://q.stock.sohu.com/hk/HSI/index.shtml'],['HSCCI','红筹指数','3789.30','-3.77','-0.10%','http://q.stock.sohu.com/hk/HSCCI/index.shtml'],['HSCEI','国企指数','9519.53','-55.27','-0.58%','http://q.stock.sohu.com/hk/HSCEI/index.shtml']])



 
http://hq.stock.sohu.com/hqindex/finaceindex/financeindexhq.js
返回

PEAK_ODIA(['financeindexhq',[['zs_000001','上证指数','2289.79','-16.06','-0.70%','http://q.stock.sohu.com/zs/000001/index.shtml'],['zs_399001','深证成指','9790.20','-59.57','-0.60%','http://q.stock.sohu.com/zs/399001/index.shtml'],['zs_399101','中小板综','5253.22','-13.70','-0.26%','http://q.stock.sohu.com/zs/399101/index.shtml'],['zs_000003','沪市B股','232.02','+1.91','0.83%','http://q.stock.sohu.com/zs/000003/index.shtml'],['zs_399003','成份B指','4425.99','-39.46','-0.88%','http://q.stock.sohu.com/zs/399003/index.shtml'],['zs_000011','沪市基金','3824.81','-21.85','-0.57%','http://q.stock.sohu.com/zs/000011/index.shtml'],['zs_399305','深市基金','4601.38','-25.05','-0.54%','http://q.stock.sohu.com/zs/399305/index.shtml'],['HSI','恒生指数','18872.56','-81.07','-0.43%','http://q.stock.sohu.com/hk/HSI/index.shtml'],['HSCEI','国企指数','9519.53','-55.27','-0.58%','http://q.stock.sohu.com/hk/HSCEI/index.shtml'],['HSCCI','红筹指数','3789.30','-3.77','-0.10%','http://q.stock.sohu.com/hk/HSCCI/index.shtml']],[[['cn_600401','海润光伏','7.99','10.06%'],['cn_600978','宜华木业','5.27','7.55%'],['cn_600777','新潮实业','5.35','6.36%'],['cn_600596','新安股份','6.62','6.09%'],['cn_600657','信达地产','5.01','5.92%']],[['cn_601339','N百隆','12.33','-9.34%'],['cn_601908','京运通','8.60','-7.13%'],['cn_600495','晋西车轴','12.30','-6.32%'],['cn_600158','XD中体产','6.99','-6.30%'],['cn_600470','六国化工','10.42','-6.21%']],[['cn_002683','N宏大   ','16.00','10.65%'],['cn_000736','重庆实业','10.85','10.04%'],['cn_002499','科林环保','21.43','10.01%'],['cn_300147','香雪制药','8.37','9.99%'],['cn_300266','兴源过滤','19.07','9.98%']],[['cn_002238','天威视讯','14.74','-9.40%'],['cn_002685','N华重机 ','9.08','-9.11%'],['cn_002682','N龙洲   ','9.76','-7.92%'],['cn_300136','信维通信','15.36','-7.69%'],['cn_002616','长青集团','17.45','-6.03%']]],[['25','S板','8','10.16','+0.12','0.65%','111101','9321','cn_600733','S*ST前锋','18.26','+0.87','5.00%'],['22','房地产','143','7.69','+0.05','0.65%','14823974','1117434','cn_000736','重庆实业','10.85','+0.99','10.04%'],['59','医药板块','188','16.54','+0.16','0.63%','6170241','874796','cn_300147','香雪制药','8.37','+0.76','9.99%'],['39','ST板块','139','7.18','+0.02','0.56%','3426392','203147','cn_600074','ST中达','3.07','+0.15','5.14%'],['291','重庆板块','27','10.57','+0.03','0.40%','1374186','139496','cn_000736','重庆实业','10.85','+0.99','10.04%']]])
---------------------------------------------
http://hq.sinajs.cn/list=s_sh000001 上证指数

http://hq.sinajs.cn/list=s_sz399001 深证成指

http://hq.sinajs.cn/list=int_hangseng 恒生指数

http://hq.sinajs.cn/list=s_sz399300 沪生300

http://hq.sinajs.cn/list=int_dji 道琼斯

http://hq.sinajs.cn/list=int_nasdaq 纳斯达克

http://hq.sinajs.cn/list=int_sp500 标普500

http://hq.sinajs.cn/list=int_ftse 英金融时报指数

---------------------------------------------------------
期货
http://hq.sinajs.cn/rn=1318986550609&list=hf_CL,hf_GC,hf_SI,hf_CAD,hf_ZSD,hf_S,hf_C,hf_W
返回

var hq_str_hf_CL="83.3500,0.7860,83.3400,83.3500,83.4300,81.0700,22:47:46,82.7000,81.2700,17929,0,0,2012-06-12";
var hq_str_hf_GC="1608.4000,0.7265,1608.3000,1608.4000,1611.6000,1587.0000,22:47:46,1596.8000,1597.1000,17965,0,0,2012-06-12";
var hq_str_hf_SI="28.7500,0.4893,28.7400,28.7500,28.9500,28.3100,22:47:44,28.6100,28.5000,7509,0,0,2012-06-12";
var hq_str_hf_CAD="7392.5000,-0.2133,7390.5000,7392.2998,7444.2998,7328.2998,22:47:46,7408.2998,7368.0000,12568,1,1,2012-06-12";
var hq_str_hf_ZSD="1886.0000,-0.2116,1886.0000,1888.3000,1893.3000,1874.3000,22:47:34,1890.0000,1885.0000,3502,1,2,2012-06-12";
var hq_str_hf_S="1428.5000,0.2632,1428.0000,1428.5000,1449.2500,1416.2500,22:47:46,1424.7500,1426.7500,5144,0,0,2012-06-12";
var hq_str_hf_C="584.5000,-1.2669,584.5000,584.7500,598.5000,575.5000,22:47:45,592.0000,593.5000,3509,0,0,2012-06-12";
var hq_str_hf_W="622.7500,-1.2292,622.7500,623.0000,639.5000,618.2500,22:47:45,630.5000,628.5000,2433,0,0,2012-06-12";
外汇
http://hq.sinajs.cn/rn=1318986628214&list=USDCNY,USDHKD,EURCNY,GBPCNY,USDJPY,EURUSD,GBPUSD,
返回

var hq_str_USDCNY="16:58:22,6.3705,6.3673,6.3692,32,6.3694,6.3782,6.3685,6.3705,美元人民币";
var hq_str_USDHKD="22:48:57,7.7594,7.7596,7.7599,2,7.7601,7.7601,7.7531,7.7594,美元港元";
var hq_str_EURCNY="22:44:55,7.9453,7.9478,7.8917,25,7.9491,7.9725,7.8917,7.9453,欧元人民币";
var hq_str_GBPCNY="22:44:55,9.9032,9.9057,9.7923,25,9.8649,9.9103,9.7923,9.9032,英镑人民币";
var hq_str_USDJPY="22:48:56,79.50,79.50,79.38,0,79.38,79.69,79.15,79.50,美元日元";
var hq_str_EURUSD="22:48:57,1.2468,1.2468,1.2467,0,1.2469,1.2529,1.2441,1.2468,欧元美元";
var hq_str_GBPUSD="22:48:57,1.5537,1.5542,1.5471,5,1.5469,1.5557,1.5454,1.5537,英镑美元";
--------------
日K线
http://image.sinajs.cn/newchart/daily/n/sh601006.gif
周K线

http://image.sinajs.cn/newchart/weekly/n/sh601006.gif

月K线
http://image.sinajs.cn/newchart/monthly/n/sh601006.gif
分时图

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


这是一个人(http://blog.csdn.net/jiangxinyu/article/details/6150476)写的java获得数据的代码:
String url = "http://hq.sinajs.cn/list=sh600151,sz000830,s_sh000001,s_sz399001,s_sz399106";
        try {
            URL u = new URL(url);
            byte[] b = new byte[256];
            InputStream in = null;
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            while (true) {
                try {
                    in = u.openStream();
                    int i;
                    while ((i = in.read(b)) != -1) {
                        bo.write(b, 0, i);
                    }
                    String result = bo.toString();
                    String[] stocks = result.split(";");
                    for (String stock : stocks) {
                        String[] datas = stock.split(",");
                        //根据对照自己对应数据
                    }
                    bo.reset();
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                } finally {
                    if (in != null) {
                        in.close();
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }


 
搜狐证券
http://q.stock.sohu.com/index.shtml
扩展阅读