http://walsece.iteye.com/blog/169514
Stocks for some time, found that the current stock market software in many cases is not too easy to use, I like to see stocks in the real-time trading records, if at the same time pay more attention to the stock, I used the market software did not find the same time to watch a number of stock markets trading data functions, In addition, the use of current market software is not very convenient at work. So I intend to write a special market software, but the data source is the most difficult problem, after searching and unremitting efforts, found two ways:
Calling http://www.webxml.com.cn/zh_cn/web_services.aspx through WebService, the site offers free and chargeable services, but it's not practical to limit the number of requests per day for free.
Call Sina dedicated JS server to parse the data, this way I used for a long time, the speed is quite good, sometimes faster than the real-time data of the special market software, the following is the part of the code to get the data:
Java code
- 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 (",");
- //According to the corresponding data of the control
- }
- Bo.reset ();
- } catch (Exception e) {
- System.out.println (E.getmessage ());
- } finally {
- if (in = null) {
- In.close ();
- }
- }
- }
- } catch (Exception ex) {
- System.out.println (Ex.getmessage ());
- }
After the list of parameters for the relevant stock code, you can attach more than one stock code, where the Shanghai front Plus "sh", deep proof front plus "sz",
If you only need to obtain the basic data of stock trading, then add "S_", as below
S_sh000001,s_sz399001,s_sz399106 are as follows: Shanghai Composite, shen exponentially, the basic index data of deep-proof comprehensive means
The data format obtained is as follows:
var hq_str_sh600151= "Aerospace electromechanical, 14.49,14.57,14.37,14.86,14.10,14.37,14.38,13146411,190836199,1900,14.37,10601,14.36,16100,14.35,1700,14.34,6900,14.33,492 00,14.38,60400,14.39,25373,14.40,4500,14.41,10650,14.42,2008-03-07,15:05:32 ";
var hq_str_sz000830= "Lu Xi Chemical, 8.82,8.91,8.53,8.88,8.38,8.52,8.53,24754397,213611631.24,118400,8.52,38400,8.51,368623,8.50,19000,8.49,69300,8.48,170948 , 8.53,57160,8.55,44729,8.56,27300,8.57,32700,8.58,2008-03-07,15:20:51 ";
var hq_str_sh000001= "Shanghai Composite, 4315.808,4360.986,4300.515,4341.295,4265.829,0,0,56747402,92203521881,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2008-03-07 , 15:05:32 ";
var hq_str_s_sz399001= "Deep certificate exponentially, 15560.853,-135.272,-0.86,3500683,963757";
var hq_str_s_sz399106= "Deep-proof comprehensive means, 1369.839,-18.264,-1.32,4279649095,4557752";
After obtaining the data, according to the market software to correspond to the data, and then use swing to do an interface, hehe, so it is done, personal use for 2 months, the general situation is very useful.
How to get stock real-time trading data