From 038c7e5b9c8338103496d40ffb0122b3f61a5185 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 29 May 2026 12:19:47 +0800
Subject: [PATCH] 1
---
trading-order-admin/src/main/java/com/yami/trading/api/controller/KlineController.java | 69 +++++++++++++++++++++++++++-------
1 files changed, 54 insertions(+), 15 deletions(-)
diff --git a/trading-order-admin/src/main/java/com/yami/trading/api/controller/KlineController.java b/trading-order-admin/src/main/java/com/yami/trading/api/controller/KlineController.java
index 8f10a7a..082e20c 100644
--- a/trading-order-admin/src/main/java/com/yami/trading/api/controller/KlineController.java
+++ b/trading-order-admin/src/main/java/com/yami/trading/api/controller/KlineController.java
@@ -2,6 +2,8 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yami.trading.bean.data.domain.Kline;
+import com.yami.trading.bean.data.domain.Realtime;
+import com.yami.trading.bean.data.dto.BeforeClose;
import com.yami.trading.bean.ico.domain.Ico;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.domain.Result;
@@ -9,6 +11,8 @@
import com.yami.trading.common.util.DateUtils;
import com.yami.trading.common.web.ResultObject;
import com.yami.trading.huobi.data.AdjustmentValueCache;
+import com.yami.trading.huobi.data.DataCache;
+import com.yami.trading.huobi.data.internal.DataDBService;
import com.yami.trading.huobi.data.internal.KlineService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.etf.MarketService;
@@ -47,6 +51,9 @@
private DataService dataService;
@Autowired
private IcoService icoService;
+
+ @Autowired
+ private DataDBService dataDBService;
@ApiOperation(value = "行情")
@GetMapping(HOBI + "getKline.action")
@@ -97,44 +104,49 @@
}
}
- BigDecimal currentValue = AdjustmentValueCache.getCurrentValue().get(symbol);
+ /*BigDecimal currentValue = AdjustmentValueCache.getCurrentValue().get(symbol);
if (currentValue != null) {
data.forEach(kline -> {
- if (kline.getClose().compareTo(kline.getLow()) >= 0 && kline.getClose().compareTo(kline.getHigh()) <= 0) {
- kline.setClose(kline.getClose().add(currentValue));
+ *//*logger.info("==currentValue==close:{}, low:{}, high:{}, open:{}, currentValue:{}",
+ kline.getClose(), kline.getLow(), kline.getHigh(), kline.getOpen(), currentValue);*//*
+ if (!kline.isAdjusted()){
+ if (kline.getClose().compareTo(kline.getLow()) >= 0 && kline.getClose().compareTo(kline.getHigh()) <= 0) {
+ kline.setClose(kline.getClose().add(currentValue));
+ }
+ kline.setOpen(kline.getOpen().add(currentValue));
+ kline.setLow(kline.getLow().add(currentValue));
+ kline.setHigh(kline.getHigh().add(currentValue));
+ kline.setAdjusted(true);
}
- kline.setOpen(kline.getOpen().add(currentValue));
- kline.setLow(kline.getLow().add(currentValue));
- kline.setHigh(kline.getHigh().add(currentValue));
});
- }
+ }*/
return Result.succeed(this.build(data, line, symbol));
} catch (Exception e) {
logger.error("getKline error", e);
- throw new YamiShopBindException("k线图获取失败");
+ throw new YamiShopBindException("");
}
}
private List<Map<String, Object>> build(List<Kline> data, String line, String symbol) {
+ Collections.sort(data);
+ // 相同时间戳保留最新一条(进行中K线会覆盖缓存中的旧数据)
+ Map<Long, Kline> latestByTs = new LinkedHashMap<>();
+ for (Kline kline : data) {
+ latestByTs.put(kline.getTs(), kline);
+ }
+ data = new ArrayList<>(latestByTs.values());
Collections.sort(data);
int len = data.size();
for (int i = 1; i < len; i++) {
data.get(i).setOpen(data.get(i - 1).getClose());
}
-
- Set<Long> tsSet = new HashSet<Long>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Item bySymbol = itemService.findBySymbol(symbol);
for (int i = 0; i < data.size(); i++) {
Kline kline = data.get(i);
Long ts = kline.getTs();
- if (tsSet.contains(ts)) {
- continue;
- } else {
- tsSet.add(ts);
- }
String fake = bySymbol.getFake();
// if("1".equalsIgnoreCase(fake)){
// klineService.smoothlyKline(kline, 0.99);
@@ -168,6 +180,33 @@
map.put("high", high.setScale(decimal, RoundingMode.HALF_UP));
map.put("low", low.setScale(decimal, RoundingMode.HALF_UP));
map.put("volume", kline.getVolume());
+
+ if (i == data.size() - 1) {
+ Realtime realtime = DataCache.getLatestRealTime(symbol);
+ if (realtime != null && realtime.getClose() != null) {
+ close = realtime.getClose();
+ map.put("close", close.setScale(decimal, RoundingMode.HALF_UP));
+ if (close.compareTo(high) > 0) {
+ high = close;
+ }
+ if (close.compareTo(low) < 0) {
+ low = close;
+ }
+ }
+ BeforeClose beforeClose = dataDBService.getBeforeClose(kline.getSymbol(), line, ts, realtime);
+ if (beforeClose != null) {
+ if (beforeClose.getMaxClose() != null
+ && beforeClose.getMaxClose().compareTo(BigDecimal.ZERO) > 0) {
+ high = beforeClose.getMaxClose();
+ }
+ if (beforeClose.getMinClose() != null
+ && beforeClose.getMinClose().compareTo(BigDecimal.ZERO) > 0) {
+ low = beforeClose.getMinClose();
+ }
+ }
+ map.put("high", high.setScale(decimal, RoundingMode.HALF_UP));
+ map.put("low", low.setScale(decimal, RoundingMode.HALF_UP));
+ }
list.add(map);
}
return list;
--
Gitblit v1.9.3