package com.gustoboard.bm.rtdg.service.impl;
import com.gustoboard.bm.rtdg.mapper.TradeMapper;
import com.gustoboard.bm.rtdg.model.KTrade;
import com.gustoboard.bm.rtdg.model.Market;
import com.gustoboard.bm.rtdg.util.DateUtils;
import com.gustoboard.bm.rtdg.util.JacksonUtils;
import com.gustoboard.bm.rtdg.util.RedisEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 后期优化处理 通过 jprofile 调优后发现cpu利用率偏高 整体项目线上%12 左右有峰值
* 对于 15分钟内k线 的只需存入10天左右的数据 如果用户拖动到10天以后通过查询拼接5天一档
* 启动定时器线程来单独执行K线方法数据 错开其他统计定时器
* 这里提供代码逻辑
*/
@Service
public class KLineService {
@Autowired
private TradeMapper tradeMapper;
@Autowired
private RedisTemplate<String, String> redisTemplate;
private final static Logger logger = LoggerFactory.getLogger(KLineService.class);
// 1 5 15 30 60 2 4 6个 12 一天 3天 7天
private static final int[] time = {1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10080};
/**
* 30秒轮询一次
*/
@Scheduled(fixedRate = 30000)
public void TradeKLine() {
//redis 获取股票的id 和初始时间初始价格
String marketRedis = redisTemplate.opsForValue().get(RedisEnum.GUSTO.getDesc() + "market");
List<Market> integers = null;
if (null != marketRedis) {
integers = JacksonUtils.getObjectFromJson(marketRedis, ArrayList.class, Market.class);
} else {
integers =
Java 股票K线逻辑 代码
最新推荐文章于 2024-06-21 09:40:20 发布
本文详细介绍了如何使用Java编程语言实现股票K线图的逻辑,涵盖了数据处理、图形绘制和关键指标计算等方面,旨在帮助开发者理解股票K线的生成过程。
摘要由CSDN通过智能技术生成