From fc52c99639d8d817192985b295d39e6ba34484f8 Mon Sep 17 00:00:00 2001
From: zainali5120 <512061637@qq.com>
Date: Wed, 14 Oct 2020 21:19:48 +0800
Subject: [PATCH] 最高最低价

---
 src/main/java/com/xcong/excoin/modules/exchange/service/impl/HandleKlineServiceImpl.java |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/exchange/service/impl/HandleKlineServiceImpl.java b/src/main/java/com/xcong/excoin/modules/exchange/service/impl/HandleKlineServiceImpl.java
index e61a588..86891ac 100644
--- a/src/main/java/com/xcong/excoin/modules/exchange/service/impl/HandleKlineServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/exchange/service/impl/HandleKlineServiceImpl.java
@@ -49,7 +49,35 @@
                 newPrice=exchangeTrade.getPrice();
             }
         }
-
+        // 更新今日高地价
+        BigDecimal min=BigDecimal.ZERO;
+        BigDecimal max=BigDecimal.ZERO;
+        BigDecimal vol = BigDecimal.ZERO;
+        for (ExchangeTrade exchangeTrade : trades) {
+            if(exchangeTrade==null){
+                continue;
+            }
+            min=exchangeTrade.getPrice().min(min);
+            max=exchangeTrade.getPrice().max(max);
+            vol=vol.add(exchangeTrade.getAmount());
+        }
+        Object o = redisUtils.get(symbolUsdt);
+        if(o!=null){
+            Candlestick today =   (Candlestick)o;
+            today.setHigh(today.getHigh().max(max));
+            today.setLow(today.getLow().min(min));
+            today.setLow(today.getVolume().add(vol));
+            redisUtils.set(symbolUsdt,today);
+        }else{
+            Candlestick today =   new Candlestick();
+            today.setClose(newPrice);
+            today.setLow(newPrice);
+            today.setHigh(newPrice);
+            today.setHigh(today.getHigh().max(max));
+            today.setLow(today.getLow().min(min));
+            today.setLow(vol);
+            redisUtils.set(symbolUsdt,today);
+        }
         // 存入redis,websocket去取
         String key = "NEW_KINE_{}";
         key = StrUtil.format(key, symbolUsdt);
@@ -60,4 +88,5 @@
         }
 
     }
+
 }

--
Gitblit v1.9.1