How to get stock real-time trading data

Source: Internet
Author: User

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:

    1. 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.

    2. 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
  1. String url = "http://hq.sinajs.cn/list=sh600151,sz000830,s_sh000001,s_sz399001,s_sz399106";
  2. try {
  3. URL u = new URL (URL);
  4. byte[] B = new byte[256];
  5. InputStream in = null;
  6. Bytearrayoutputstream bo = new Bytearrayoutputstream ();
  7. While (true) {
  8. try {
  9. in = U.openstream ();
  10. int i;
  11. While ((i = In.read (b))! =-1) {
  12. Bo.write (b, 0, I);
  13. }
  14. String result = Bo.tostring ();
  15. string[] stocks = Result.split (";");
  16. For (String stock:stocks) {
  17. string[] datas = Stock.split (",");
  18. //According to the corresponding data of the control
  19. }
  20. Bo.reset ();
  21. } catch (Exception e) {
  22. System.out.println (E.getmessage ());
  23. } finally {
  24. if (in = null) {
  25. In.close ();
  26. }
  27. }
  28. }
  29. } catch (Exception ex) {
  30. System.out.println (Ex.getmessage ());
  31. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.