The current data is obtained from the Sina interface, http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?symbol=sh600000&end_date= 20141120&begin_date=20120101
The return data is in XML format:
1 <?xml version= "1.0" encoding= "UTF-8"?>2 <control>3 <content d= " 2012-01-04 "o=" 8.540 "h=" 8.560 "c=" 8.410 "l=" 8.390 "v=" 342014 "bl=" "/>4 <content d=" 2012-01-05 "o=" 8.470 "h=" 8.820 "c=" 8.650 "l=" 8.470 "v=" 1321162 "bl=" "/>5 <content d=" 2012-01-06 "o=" 8.630 "h=" 8.780 "c=" 8.710 "l=" 8.620 "v=" 617787 "bl=" "/>6 <content d=" 2012-01-09 "o=" 8.720 "h=" 8.990 "c=" 8.950 "L=" 8.680 "v=" 801362 "bl=" "/>78 </control>
By using the above interface, you can obtain the data of the day K and encapsulate it to a list collection for saving.
The following code is the data collection of the week K by the data collection of day K.
1 2 /**3 * Data of week K is calculated by day K4 * @paramListday5 * @return6 */7 Public StaticList<lxklineentity> GetWeekLineData1 (list<lxklineentity>listday) {8List<lxklineentity> weeklist =NewArraylist<lxklineentity>();9 Try {Ten if(Listday! =NULL&& listday.size () > 0) {//first confirm that there is data One intSize =listday.size (); A -String begindate = listday.get (0). GetDate (); -String endDate = Listday.get (size-1). GetDate (); the - intWeeks = Getstockweeks (begindate, endDate);//Week number - - + for(inti = 0; i < weeks; i++) { - + ALxklineentity vo =NULL; at //get the best price, lowest price, close and open price - //the need to consider is that if this week is a break, then no data can be added. such as spring Festival and National Day -List<string> Liststr =NewArraylist<string>(); -string[] Day = Getweeksbyday (begindate);//The number of days to obtain this stock trading week based on the given time name type is 2014-11-29 - - inlist<lxklineentity> weekonelist =weekonelist =NewArraylist<lxklineentity>(); - to for(intj = 0; J < Day.length; J + +) {//iterate through the data of the week + - theString Day1 =Day[j]; * $ for(intk = 0; K < size; k++) {Panax NotoginsengString date =Listday.get (k). GetDate (); - if(Date.equals (day1)) { the //If the data for Day K has data for that day, then add that candlestick data . + Weekonelist.add (Listday.get (k)); A } the } + //calculate high and low prices close open - if(Weekonelist! =NULL&& weekonelist.size () > 0) {//If there's data this week , $VO =Newlxklineentity (); $ intLen =weekonelist.size (); -Vo.setopen (Weekonelist.get (0). Getopen ());//The opening price of the first day of the stock week -Vo.setclose (Weekonelist.get (len-1). Getclose ());//The last day of the stock week closes the grid the Doublehi = 0;//High Price - DoubleLo = 0;//Lowest PriceWuyi DoubleVA = 0;//Volume the for(intm = 0; M < Weekonelist.size (); m++) { - DoubleHigh =Weekonelist.get (M). Gethigh (); Wu DoubleLow =Weekonelist.get (M). Getlow (); - Doubleval =Weekonelist.get (M). Getvolume (); About if(High >hi) $Hi =High ; - if(Low <lo) -Lo =Low ; -VA + =Val; A } + Vo.setlow (LO); the Vo.sethigh (HI); - Vo.setvolume (VA); $ } the } theBegindate = GetDay (Day[6], 1); the if(Vo! =NULL) the Weeklist.add (VO); - } in } the}Catch(Exception e) { the e.printstacktrace (); About } the returnweeklist; the}
The operation efficiency of the above code can be optimized again.
You are welcome to propose amendments.
Contact qq:30338970
Email:[email protected]
Android stock data through the day K get week K data algorithm source code