新浪行情

行情接口

http://hq.sinajs.cn/list=股票代码

以同花顺(股票代码:300033,股票市场:sz,深圳)为例,如果需要获取该股票的最新行情,只需如下调用接口: http://hq.sinajs.cn/list=sz300033

该接口会返回一串文本,比如:

1
var hq_str_sz300033="同花顺,52.100,53.150,50.990,52.400,50.880,50.990,51.000,4592538,235557372.010,2284,50.990,400,50.950,300,50.940,200,50.930,3900,50.920,1200,51.000,1300,51.270,10300,51.280,400,51.290,3902,51.300,2018-04-03,13:18:54,00";

该字符串由多个数据用逗号”,”拼接,按照程序员的思路,顺序号从0开始。 0:“同花顺”,股票名称;

1:“52.100”,今日开盘价;

2:“53.150”,昨日收盘价;

3:“50.990”,当前价格;

4:“52.400”,今日最高价;

5:“50.880”,今日最低价;

6:“50.990”,竞买价,即“买一”报价;

7:“51.000”,竞卖价,即“卖一”报价;

8:“4592538”,成交的股票数,由于股票交易以一百股为基本单位,所以在使用时,通常把该值除以一百;

9:“235557372.010”,成交金额,单位为“元”;

10:“2284”,“买一”申请4695股,即47手;

11:“50.990”,“买一”报价;

12:“400”,“买二”;

13:“50.950”,“买二”;

14:“300”,“买三”;

15:“50.940”,“买三”;

16:“200”,“买四”;

17:“50.930”,“买四”;

18:“3900”,“买五”;

19:“50.920”,“买五”;

20:“1200”,“卖一”申报3100股,即31手;

21:“51.000”,“卖一”报价

(22, 23), (24, 25), (26,27), (28, 29)分别为“卖二”至“卖四的情况”

30:“2018-04-03”,日期; 31:“13:18:54”,时间;

如需查询多个股票,只需要将股票代码用逗号拼接后调用该接口。 比如查询同花顺(股票代码:300033,股票市场:sz,深圳),贵州茅台(股票代码:600252,股票市场:sh,上海),复星医药(股票代码:600196,股票市场:sh,上海) http://hq.sinajs.cn/list=sz300033,sh600252,sh600196

1
2
3
var hq_str_sz300033="同花顺,52.100,53.150,51.090,52.400,50.880,51.080,51.090,4880945,250301808.510,10293,51.080,5900,51.070,1700,51.050,2300,51.040,200,51.030,49100,51.090,3047,51.100,1100,51.150,2000,51.180,300,51.250,2018-04-03,13:36:12,00";
var hq_str_sh600252="中恒集团,3.960,4.000,3.920,3.970,3.910,3.910,3.920,12745747,50199960.000,781400,3.910,789000,3.900,285600,3.890,337700,3.880,172300,3.870,297200,3.920,224400,3.930,144347,3.940,658503,3.950,390348,3.960,2018-04-03,13:36:14,00";
var hq_str_sh600196="复星医药,43.800,44.360,43.460,44.670,43.430,43.460,43.480,10789333,473126781.000,3900,43.460,9550,43.450,13400,43.440,22645,43.430,3300,43.420,12000,43.480,2500,43.490,6400,43.500,1500,43.520,600,43.530,2018-04-03,13:36:14,00";

返回的股票数据,股票与股票之间有“\n”换行符进行换行。返回股票行情数据的顺序与接口中拼接的股票代码顺序一致。而且不会去除重复股票代码。

比如: http://hq.sinajs.cn/list=sz300033,sz300033,sh600196

1
2
3
var hq_str_sz300033="同花顺,52.100,53.150,51.650,52.400,50.880,51.590,51.650,5112490,262191072.590,200,51.590,800,51.580,1000,51.570,4100,51.550,1100,51.540,1500,51.650,300,51.660,1200,51.670,500,51.680,2000,51.690,2018-04-03,13:40:42,00";
var hq_str_sz300033="同花顺,52.100,53.150,51.650,52.400,50.880,51.590,51.650,5112490,262191072.590,200,51.590,800,51.580,1000,51.570,4100,51.550,1100,51.540,1500,51.650,300,51.660,1200,51.670,500,51.680,2000,51.690,2018-04-03,13:40:42,00";
var hq_str_sh600196="复星医药,43.800,44.360,43.480,44.670,43.410,43.440,43.480,10962328,480641133.000,2500,43.440,7500,43.430,7400,43.420,27400,43.410,35100,43.400,6200,43.480,1200,43.500,200,43.510,400,43.530,100,43.570,2018-04-03,13:40:41,00";

会返回两次同花顺的行情数据。

大盘指数的数据会有所差别

三大指数的代码如下:

上证指数:s_sh000001

深证成指:s_sz399001

创业板指:s_sz399006

接口与股票行情接口一致,单返回数据内容有巨大差别。 http://hq.sinajs.cn/list=s_sh000001,s_sz399001,s_sz399006

返回数据如下:

1
2
3
var hq_str_s_sh000001="上证指数,3129.3559,-33.8231,-1.07,1093759,13684785";
var hq_str_s_sz399001="深证成指,10705.22,-147.728,-1.36,150649760,21374199";
var hq_str_s_sz399006="创业板指,1862.29,-37.966,-2.00,15198600,2675426";

数据含义分别为:指数名称,当前点数,当前价格,涨跌率,成交量(手),成交额(万元);

分时图

gif形式

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

其中*代表股票代码。

比如:同花顺的分时图

http://image.sinajs.cn/newchart/min/n/sz300033.gif 分时图

数据格式

http://vip.stock.finance.sina.com.cn/quotes\_service/view/CN\_TransListV2.php?symbol=股票代码&rn=时间戳

其中

symbol为股票代码,

rn为请求的时间戳。

该接口一次只能请求一个股票的分时图。

以同花顺为例: http://vip.stock.finance.sina.com.cn/quotes_service/view/CN_TransListV2.php?symbol=sz300033&rn=1522736353052

返回数据如下(由于数据过多,这里已经删除大部分数据)

1
var trade_item_list = new Array(); trade_item_list[0] = new Array('14:19:51', '100', '51.300', 'UP'); trade_item_list[1] = new Array('14:19:48', '1000', '51.300', 'UP'); trade_item_list[2] = new Array('14:19:45', '200', '51.290', 'DOWN'); trade_item_list[3] = new Array('14:19:42', '300', '51.300', 'UP'); trade_item_list[4] = new Array('14:19:39', '200', '51.300', 'UP'); trade_item_list[5] = new Array('14:19:36', '100', '51.300', 'UP'); trade_item_list[6] = new Array('14:19:30', '1000', '51.300', 'UP'); trade_item_list[7] = new Array('14:19:24', '300', '51.300', 'UP'); trade_item_list[8] = new Array('14:19:21', '300', '51.290', 'DOWN'); trade_item_list[9] = new Array('14:19:18', '100', '51.290', 'DOWN'); trade_item_list[10] = new Array('14:19:15', '400', '51.300', 'UP'); trade_item_list[11] = new Array('14:19:09', '1000', '51.300', 'UP'); trade_item_list[12] = new Array('14:19:03', '500', '51.300', 'UP'); trade_item_list[13] = new Array('14:18:57', '1400', '51.300', 'UP'); trade_item_list[14] = new Array('14:18:54', '2800', '51.300', 'UP'); trade_item_list[15] = new Array('14:18:48', '2600', '51.290', 'DOWN'); trade_item_list[16] = new Array('14:18:39', '1500', '51.290', 'UP'); trade_item_list[17] = new Array('14:18:33', '100', '51.290', 'UP'); trade_item_list[18] = new Array('14:18:30', '300', '51.290', 'UP'); trade_item_list[19] = new Array('14:18:27', '800', '51.290', 'DOWN'); trade_item_list[20] = new Array('14:18:21', '1000', '51.300', 'UP');   trade_item_list[2510] = new Array('09:38:27', '3900', '51.550', 'EQUAL'); trade_item_list[2511] = new Array('09:38:24', '11900', '51.500', 'DOWN'); trade_item_list[2512] = new Array('09:38:21', '2700', '51.600', 'UP'); trade_item_list[2513] = new Array('09:38:18', '6200', '51.500', 'DOWN'); trade_item_list[2514] = new Array('09:38:15', '6100', '51.600', 'DOWN'); trade_item_list[2515] = new Array('09:38:12', '5800', '51.600', 'DOWN'); trade_item_list[2516] = new Array('09:38:09', '1500', '51.600', 'DOWN'); trade_item_list[2517] = new Array('09:38:06', '2200', '51.700', 'UP'); trade_item_list[2518] = new Array('09:38:03', '3500', '51.600', 'DOWN'); trade_item_list[2519] = new Array('09:38:00', '1908', '51.700', 'DOWN'); trade_item_list[2520] = new Array('09:37:57', '3192', '51.700', 'DOWN'); trade_item_list[2521] = new Array('09:37:54', '3800', '51.710', 'DOWN'); trade_item_list[2522] = new Array('09:37:51', '3600', '51.750', 'EQUAL'); trade_item_list[2523] = new Array('09:37:48', '3400', '51.710', 'DOWN'); trade_item_list[2524] = new Array('09:37:45', '3400', '51.800', 'UP'); trade_item_list[2525] = new Array('09:37:42', '11800', '51.800', 'DOWN'); trade_item_list[2526] = new Array('09:37:39', '1900', '51.890', 'UP'); trade_item_list[2527] = new Array('09:37:36', '2900', '51.800', 'DOWN'); trade_item_list[2528] = new Array('09:37:33', '3700', '51.900', 'UP'); trade_item_list[2529] = new Array('09:37:30', '10000', '51.900', 'UP'); trade_item_list[2530] = new Array('09:37:27', '1300', '51.850', 'EQUAL'); trade_item_list[2531] = new Array('09:37:24', '5600', '51.810', 'DOWN'); trade_item_list[2532] = new Array('09:37:21', '4800', '51.900', 'UP'); trade_item_list[2533] = new Array('09:37:18', '12200', '51.900', 'DOWN'); trade_item_list[2534] = new Array('09:37:15', '3600', '51.930', 'UP'); trade_item_list[2535] = new Array('09:37:12', '2800', '51.900', 'DOWN'); trade_item_list[2536] = new Array('09:37:09', '2300', '51.900', 'DOWN'); trade_item_list[2537] = new Array('09:37:06', '100', '51.930', 'EQUAL'); trade_item_list[2538] = new Array('09:37:03', '67400', '51.900', 'DOWN'); trade_item_list[2539] = new Array('09:37:00', '600', '51.980', 'UP'); trade_item_list[2540] = new Array('09:36:57', '1200', '51.940', 'EQUAL'); trade_item_list[2541] = new Array('09:36:54', '5000', '51.930', 'DOWN'); trade_item_list[2542] = new Array('09:36:51', '400', '51.980', 'DOWN'); trade_item_list[2543] = new Array('09:36:48', '200', '52.000', 'UP'); trade_item_list[2544] = new Array('09:36:45', '200', '52.010', 'EQUAL'); trade_item_list[2545] = new Array('09:36:42', '12900', '52.030', 'UP'); trade_item_list[2546] = new Array('09:36:39', '300', '52.010', 'EQUAL'); trade_item_list[2547] = new Array('09:36:36', '15200', '52.040', 'EQUAL'); trade_item_list[2548] = new Array('09:36:33', '7800', '52.010', 'DOWN'); trade_item_list[2549] = new Array('09:36:30', '1100', '52.070', 'UP'); trade_item_list[2550] = new Array('09:36:27', '4300', '52.010', 'DOWN'); trade_item_list[2551] = new Array('09:36:24', '200', '52.030', 'DOWN'); trade_item_list[2552] = new Array('09:36:21', '1900', '52.030', 'DOWN'); trade_item_list[2553] = new Array('09:36:18', '1700', '52.040', 'DOWN'); trade_item_list[2554] = new Array('09:36:15', '1300', '52.080', 'EQUAL'); trade_item_list[2555] = new Array('09:36:12', '9100', '52.110', 'UP'); trade_item_list[2556] = new Array('09:36:09', '4600', '52.110', 'UP'); trade_item_list[2557] = new Array('09:36:06', '1100', '52.110', 'UP'); trade_item_list[2558] = new Array('09:36:03', '1200', '52.110', 'DOWN'); trade_item_list[2559] = new Array('09:36:00', '1700', '52.120', 'DOWN'); trade_item_list[2560] = new Array('09:35:57', '800', '52.130', 'DOWN'); trade_item_list[2561] = new Array('09:35:54', '2000', '52.100', 'DOWN'); trade_item_list[2562] = new Array('09:35:51', '1000', '52.110', 'DOWN'); trade_item_list[2563] = new Array('09:35:48', '900', '52.110', 'DOWN'); trade_item_list[2564] = new Array('09:35:45', '1800', '52.100', 'DOWN'); trade_item_list[2565] = new Array('09:35:39', '2300', '52.110', 'DOWN'); trade_item_list[2566] = new Array('09:35:36', '500', '52.170', 'UP'); trade_item_list[2567] = new Array('09:35:33', '6900', '52.110', 'DOWN'); trade_item_list[2568] = new Array('09:35:30', '200', '52.170', 'DOWN'); trade_item_list[2569] = new Array('09:35:27', '2000', '52.170', 'DOWN'); trade_item_list[2570] = new Array('09:35:24', '3100', '52.170', 'UP'); trade_item_list[2571] = new Array('09:35:21', '6000', '52.100', 'UP'); trade_item_list[2572] = new Array('09:35:18', '1200', '52.100', 'UP'); trade_item_list[2573] = new Array('09:35:15', '1300', '52.070', 'DOWN'); trade_item_list[2574] = new Array('09:35:12', '2600', '52.070', 'DOWN'); trade_item_list[2575] = new Array('09:35:09', '3000', '52.110', 'UP'); trade_item_list[2576] = new Array('09:35:06', '100', '52.100', 'UP'); trade_item_list[2577] = new Array('09:35:03', '900', '52.100', 'EQUAL'); trade_item_list[2578] = new Array('09:35:00', '2600', '52.070', 'DOWN'); trade_item_list[2579] = new Array('09:34:57', '600', '52.110', 'UP'); trade_item_list[2580] = new Array('09:34:54', '600', '52.100', 'DOWN'); trade_item_list[2581] = new Array('09:34:51', '7500', '52.110', 'DOWN'); trade_item_list[2582] = new Array('09:34:48', '6800', '52.210', 'EQUAL'); trade_item_list[2583] = new Array('09:34:45', '2800', '52.200', 'DOWN'); trade_item_list[2584] = new Array('09:34:42', '3800', '52.200', 'DOWN'); trade_item_list[2585] = new Array('09:34:36', '5800', '52.200', 'DOWN'); trade_item_list[2586] = new Array('09:34:33', '200', '52.230', 'DOWN'); trade_item_list[2587] = new Array('09:34:27', '1500', '52.230', 'UP'); trade_item_list[2588] = new Array('09:34:24', '3400', '52.190', 'DOWN'); trade_item_list[2589] = new Array('09:34:21', '1100', '52.200', 'UP'); trade_item_list[2590] = new Array('09:34:18', '9600', '52.200', 'DOWN'); trade_item_list[2591] = new Array('09:34:15', '1100', '52.230', 'UP'); trade_item_list[2592] = new Array('09:34:12', '1000', '52.230', 'EQUAL'); trade_item_list[2593] = new Array('09:34:09', '3400', '52.250', 'EQUAL'); trade_item_list[2594] = new Array('09:34:06', '1600', '52.300', 'UP'); trade_item_list[2595] = new Array('09:34:03', '1100', '52.300', 'UP'); trade_item_list[2596] = new Array('09:34:00', '1300', '52.300', 'UP'); trade_item_list[2597] = new Array('09:33:57', '7900', '52.300', 'DOWN'); trade_item_list[2598] = new Array('09:33:54', '4500', '52.320', 'DOWN'); trade_item_list[2599] = new Array('09:33:51', '5500', '52.400', 'UP'); trade_item_list[2600] = new Array('09:33:48', '2100', '52.380', 'UP'); trade_item_list[2601] = new Array('09:33:45', '500', '52.380', 'EQUAL'); trade_item_list[2602] = new Array('09:33:42', '1700', '52.400', 'UP'); trade_item_list[2603] = new Array('09:33:39', '1300', '52.400', 'UP'); trade_item_list[2604] = new Array('09:33:33', '400', '52.400', 'EQUAL'); trade_item_list[2605] = new Array('09:33:27', '100', '52.300', 'UP'); trade_item_list[2606] = new Array('09:33:24', '300', '52.230', 'DOWN'); trade_item_list[2607] = new Array('09:33:21', '4800', '52.210', 'EQUAL'); trade_item_list[2608] = new Array('09:33:18', '1300', '52.200', 'DOWN'); trade_item_list[2609] = new Array('09:33:12', '3500', '52.200', 'DOWN'); trade_item_list[2610] = new Array('09:33:09', '16000', '52.200', 'UP'); trade_item_list[2611] = new Array('09:33:06', '1500', '52.200', 'UP'); trade_item_list[2612] = new Array('09:33:03', '4100', '52.180', 'DOWN'); trade_item_list[2613] = new Array('09:33:00', '4900', '52.200', 'UP'); trade_item_list[2614] = new Array('09:32:57', '10500', '52.180', 'DOWN'); trade_item_list[2615] = new Array('09:32:54', '600', '52.190', 'UP'); trade_item_list[2616] = new Array('09:32:51', '6300', '52.180', 'DOWN'); trade_item_list[2617] = new Array('09:32:48', '11000', '52.180', 'DOWN'); trade_item_list[2618] = new Array('09:32:45', '1300', '52.180', 'UP'); trade_item_list[2619] = new Array('09:32:42', '7700', '52.170', 'DOWN'); trade_item_list[2620] = new Array('09:32:39', '300', '52.180', 'UP'); trade_item_list[2621] = new Array('09:32:36', '2400', '52.170', 'DOWN'); trade_item_list[2622] = new Array('09:32:33', '100', '52.180', 'UP'); trade_item_list[2623] = new Array('09:32:27', '1500', '52.180', 'UP'); trade_item_list[2624] = new Array('09:32:24', '10500', '52.070', 'DOWN'); trade_item_list[2625] = new Array('09:32:21', '800', '52.110', 'EQUAL'); trade_item_list[2626] = new Array('09:32:18', '2800', '52.100', 'DOWN'); trade_item_list[2627] = new Array('09:32:15', '1700', '52.110', 'UP'); trade_item_list[2628] = new Array('09:32:12', '300', '52.100', 'DOWN'); trade_item_list[2629] = new Array('09:32:09', '4300', '52.100', 'DOWN'); trade_item_list[2630] = new Array('09:32:06', '3000', '52.100', 'UP'); trade_item_list[2631] = new Array('09:32:00', '108', '52.080', 'DOWN'); trade_item_list[2632] = new Array('09:31:57', '7800', '52.080', 'UP'); trade_item_list[2633] = new Array('09:31:54', '1700', '52.000', 'DOWN'); trade_item_list[2634] = new Array('09:31:51', '500', '52.030', 'DOWN'); trade_item_list[2635] = new Array('09:31:48', '8700', '52.080', 'UP'); trade_item_list[2636] = new Array('09:31:45', '500', '52.030', 'UP'); trade_item_list[2637] = new Array('09:31:42', '600', '52.030', 'UP'); trade_item_list[2638] = new Array('09:31:39', '2000', '51.930', 'DOWN'); trade_item_list[2639] = new Array('09:31:36', '5700', '52.000', 'EQUAL'); trade_item_list[2640] = new Array('09:31:33', '3600', '52.030', 'UP'); trade_item_list[2641] = new Array('09:31:30', '2800', '52.030', 'EQUAL'); trade_item_list[2642] = new Array('09:31:27', '8200', '51.930', 'DOWN'); trade_item_list[2643] = new Array('09:31:24', '2500', '52.050', 'DOWN'); trade_item_list[2644] = new Array('09:31:21', '1100', '52.050', 'UP'); trade_item_list[2645] = new Array('09:31:18', '900', '52.030', 'DOWN'); trade_item_list[2646] = new Array('09:31:15', '1500', '52.030', 'DOWN'); trade_item_list[2647] = new Array('09:31:12', '1100', '52.030', 'DOWN'); trade_item_list[2648] = new Array('09:31:09', '11500', '52.030', 'UP'); trade_item_list[2649] = new Array('09:31:06', '600', '51.930', 'UP'); trade_item_list[2650] = new Array('09:31:03', '500', '51.920', 'DOWN'); trade_item_list[2651] = new Array('09:31:00', '5900', '51.920', 'DOWN'); trade_item_list[2652] = new Array('09:30:57', '7700', '51.920', 'UP'); trade_item_list[2653] = new Array('09:30:54', '7000', '51.920', 'UP'); trade_item_list[2654] = new Array('09:30:51', '2200', '51.920', 'UP'); trade_item_list[2655] = new Array('09:30:48', '6400', '51.920', 'DOWN'); trade_item_list[2656] = new Array('09:30:45', '9900', '51.900', 'DOWN'); trade_item_list[2657] = new Array('09:30:42', '3600', '52.010', 'EQUAL'); trade_item_list[2658] = new Array('09:30:39', '9300', '52.080', 'UP'); trade_item_list[2659] = new Array('09:30:36', '7900', '52.060', 'UP'); trade_item_list[2660] = new Array('09:30:33', '7200', '51.920', 'DOWN'); trade_item_list[2661] = new Array('09:30:30', '7800', '52.060', 'UP'); trade_item_list[2662] = new Array('09:30:27', '4300', '52.060', 'UP'); trade_item_list[2663] = new Array('09:30:24', '7400', '51.920', 'DOWN'); trade_item_list[2664] = new Array('09:30:21', '3800', '52.000', 'DOWN'); trade_item_list[2665] = new Array('09:30:18', '7400', '52.050', 'UP'); trade_item_list[2666] = new Array('09:30:15', '8500', '52.000', 'UP'); trade_item_list[2667] = new Array('09:30:12', '2300', '52.000', 'UP'); trade_item_list[2668] = new Array('09:30:09', '2700', '52.000', 'UP'); trade_item_list[2669] = new Array('09:30:06', '44100', '51.990', 'DOWN'); trade_item_list[2670] = new Array('09:30:03', '9000', '52.100', 'UP'); trade_item_list[2671] = new Array('09:25:03', '21100', '52.100', 'EQUAL'); var trade_INVOL_OUTVOL=[2615432.5,3118257.5];

数据含义分别为:时间,当前成交量,当前价格,涨跌符号。

某分钟的价格取该分钟内的最后一个价格。

比如:09:30分的价格有从09:30:03到09:30:57共19个价格,则09:30的价格取09:30:57的价格51.920。

某分钟的成交量为该分钟内所有成交量的和。比如09:30分的成交量为从09:30:03到09:30:57共19个成交量之和。

某分钟的持有量为该分钟内所有持有量的和。当前持有量=当前成交量*涨跌符号;(UP为1,DOWN为-1,EQUAL为0)。

某分钟的持有量为正,则柱状图为红色;为负,则柱状图为绿色;为0,则柱状图为灰色。

以下为小编使用正则处理该数据的代码:

由于该接口返回的数据是从现在往前排列,所以最后的ArrayList需要调用Collections.reverse(list)方法反转一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    public ArrayList<NewMinutesBean> parseSinaMinutes(String str) {
ArrayList<NewMinutesBean> list = new ArrayList<>();
if (TextUtils.isEmpty(str)) {
return list;
}

String time, preTime = null, upDownFlag;
float priceCur;
long numCur;
long holdingVol, holdingVolFlag;

NewMinutesBean minutesBean = null;

String sinaRegex = "(\\('(.*?')\\, '(\\d*?)'\\, '(.*?)'\\, '(\\w*?)'\\));";
Pattern pattern = Pattern.compile(sinaRegex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
int index = 0;
String startTime = "09:30";
String endTime = "15:00";
long millisStart = hourToMillis(startTime);
long millisEnd = hourToMillis(endTime);
while (matcher.find()) {
time = matcher.group(2).substring(0, 5);
if (index == 240 && !time.equalsIgnoreCase(preTime)) {
break;
}
long millisNow = hourToMillis(time);
if (millisNow > millisEnd) {
break;
}

upDownFlag = matcher.group(5);
switch (upDownFlag) {
case "UP":
holdingVolFlag = 1;
break;
case "DOWN":
holdingVolFlag = -1;
break;
case "EQUAL":
holdingVolFlag = 0;
break;
default:
holdingVolFlag = 0;
}
priceCur = NumberUtils.parseFloat(matcher.group(4));
numCur = NumberUtils.parseLong(matcher.group(3));
holdingVol = numCur * holdingVolFlag;

if (!time.equalsIgnoreCase(preTime) && millisNow >= millisStart) {
minutesBean = new NewMinutesBean(time, priceCur, numCur, holdingVol);
list.add(minutesBean);
if (index == 0) {
lowestPrice = hightestPrice = priceCur;
}
if (priceCur > hightestPrice) {
hightestPrice = priceCur;
}

if (priceCur < lowestPrice) {
lowestPrice = priceCur;
}

index++;
} else {
if (minutesBean != null) {
minutesBean.setTradingVol(minutesBean.getTradingVol() + numCur);
if (millisNow >= millisStart)
minutesBean.setHoldingVol(minutesBean.getHoldingVol() + holdingVol);
}
}
preTime = time;
}
//反转数据
Collections.reverse(list);

return list;
}


SimpleDateFormat dataFormat;

private long hourToMillis(String startTime) {
if(dataFormat==null){
dataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
}
return dataFormat.parse("2018-04-02 "+startTime).getTime();
}

NewMinutesBean.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class NewMinutesBean {

private String time;
private float price;
private long tradingVol;
private long holdingVol;

public NewMinutesBean(String time) {
this.time = time;
}

public NewMinutesBean() {
}

public NewMinutesBean(String time, float price, long tradingVol, long holdingVol) {
this.time = time;
this.price = price;
this.tradingVol = tradingVol;
this.holdingVol = holdingVol;
}

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}

public float getPrice() {
return price;
}

public void setPrice(float price) {
this.price = price;
}

public long getTradingVol() {
return tradingVol;
}

public void setTradingVol(long tradingVol) {
this.tradingVol = tradingVol;
}

public long getHoldingVol() {
return holdingVol;
}

public void setHoldingVol(long holdingVol) {
this.holdingVol = holdingVol;
}

@Override
public String toString() {
return "NewMinutesBean{" +
"time='" + time + '\'' +
", price=" + price +
", tradingVol=" + tradingVol +
", holdingVol=" + holdingVol +
'}';
}
}

K线图

对于股票的K线图的获取可以通过请求http://image.sinajs.cn/newchart/…/n/_.gif此URL获取. _

_其中_代表股票代码, …代表K线图类型。

详见如下:

日K:daily

周K:weekly

月K:monthly

查看日K线图:

http://image.sinajs.cn/newchart/daily/n/sz300033.gif 日K

查看周K线图:

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

查看月K线图: http://image.sinajs.cn/newchart/monthly/n/sz300033.gif 月K

最近二十天左右的每5分钟数据

http://money.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_MarketData.getKLineData?symbol=sz300033&scale=5&ma=5&datalen=1023 (参数:股票编号、分钟间隔(5、15、30、60)、均值(5、10、15、20、25)、查询个数点(最大值242))

坚持原创技术分享,您的支持是对我最大的鼓励!