视觉化KBARS日K(1)-java controller

1分K视觉化的功能昨天已经完成,
今天要尝试将1分K组成日K做展示,
我会示范一个土法炼钢的方式,
之後还会说更好的方法是什麽,
现在开始土法炼钢吧!

首先我们的思路是先算出我们总共要查询的KBARS资料是几天,
算出相差天数後,
用回圈一天一天加日期,
然後每个日期都呼叫我们的kbars python api,
再将取到的值做组装(包含回圈计算最高值和最低值),
最後回传到前台。

@RequestMapping(value = "/showDayKbar" , method = {RequestMethod.GET})
	String start_date = pRequest.getParameter("start_date") == null ? "" : pRequest.getParameter("start_date");
		String end_date = pRequest.getParameter("end_date") == null ? "" : pRequest.getParameter("end_date");
		String stock_code = pRequest.getParameter("stock_code") == null ? "" : pRequest.getParameter("stock_code");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm");
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd");
		
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.YEAR, Integer.valueOf(start_date.substring(0, 4)));
		ca.set(Calendar.MONTH, Integer.valueOf(start_date.substring(5, 7))-1);
		ca.set(Calendar.DATE, Integer.valueOf(start_date.substring(8, 10)));
		
		//计算相差天数
		Date fromDate1 = sdf.parse(start_date.substring(0, 10)+" 12:00");
		Date toDate1 = sdf.parse(end_date.substring(0, 10)+" 12:00");
		long from1 = fromDate1.getTime();
		long to1 = toDate1.getTime();
		int days = (int) ((to1 - from1) / (1000 * 60 * 60 * 24));
		JSONObject all_reesult = new JSONObject();
		JSONArray all_reesult1 = new JSONArray();
		
		Date date = ca.getTime();
		String dateStringParse = sdf2.format(date);
		for(int i = 0;i < (days+1);i++) {
			if(i != 0) {
				ca.add(Calendar.DATE, 1);
				date = ca.getTime();
				dateStringParse = sdf2.format(date);
			}
			
			String kbar_data = shioajiService.oneMinKbar(dateStringParse, dateStringParse, stock_code);
			JSONObject jSONObject = new JSONObject(kbar_data);
			if(jSONObject.getJSONArray("ts").length() > 0) {
				double temp_low = 0.0;
				double temp_high = 0.0;
				JSONArray data = new JSONArray();
				data.put(dateStringParse);
				for(int k = 0; k < jSONObject.getJSONArray("ts").length();k++) {
					if(k==0) {
						data.put(jSONObject.getJSONArray("Open").getDouble(k));
						temp_low = jSONObject.getJSONArray("Low").getDouble(k);
						temp_high = jSONObject.getJSONArray("High").getDouble(k);
					}else {
						temp_low = temp_low > jSONObject.getJSONArray("Low").getDouble(k) ? jSONObject.getJSONArray("Low").getDouble(k) : temp_low;
						temp_high = temp_high < jSONObject.getJSONArray("High").getDouble(k) ? jSONObject.getJSONArray("High").getDouble(k) : temp_high;
					}
					if((k+1) == jSONObject.getJSONArray("ts").length()) {

						data.put(jSONObject.getJSONArray("Close").getDouble(k));
						data.put(temp_low);
						data.put(temp_high);
					}
				}
				all_reesult1.put(data);
			}

		}
		Gson gson  = new Gson();
		model.addAttribute("kbar_data", all_reesult1);
		return "showKbarDayMA";
	}

明天就会展示日K的成果,
大家加油剩没几天了~


<<:  [Day 28] Crypto 小替换

>>:  Day 28 Exploitation Tools (searchsploit)

[DAY 29] Q&A 谘询系统 - 程序开发(Forms)

最後来到了回覆问题的页面啦 长得不是很好看,但还没想到怎麽修改它 (´◓Д◔`) 欢迎大家提供意见!...

利用 Grafana Operator 部署 Grafana 到 OpenShift,并建立客制化的 Dashboard。

在前篇文章中,我已经将 Grafana Operator 部署到 "brandon&quo...

[Day 13] SCSS 结合 Bootstrap 网页制作

前言 非常感谢六角学院在今年疫情最严重的5、6月份,提供了一系列的线上体验学习课程,能够从课程中,再...

Django - template filter and tags

context的内容: sub_dual = [{'start':1, 'end':2, 'text...

Day05 - 使用 Link 实作换页

Link 在了解了 Next.js 的三种路由方式後,接下来就让我们来聊聊怎麽在 component...