Java 股票K线逻辑 代码

本文详细介绍了如何使用Java编程语言实现股票K线图的逻辑,涵盖了数据处理、图形绘制和关键指标计算等方面,旨在帮助开发者理解股票K线的生成过程。
摘要由CSDN通过智能技术生成
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 = 
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值