From 640ccb9229224642515527daf87f308a7aa9bdf4 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 10 Jun 2026 11:47:26 +0800
Subject: [PATCH] 1

---
 trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/AbstractGetDataJob.java |   78 +++++++++++++++++++++++++++++++-------
 1 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/AbstractGetDataJob.java b/trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/AbstractGetDataJob.java
index 579aa4b..b4fdac9 100644
--- a/trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/AbstractGetDataJob.java
+++ b/trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/AbstractGetDataJob.java
@@ -24,7 +24,7 @@
 
 public abstract class AbstractGetDataJob implements Runnable {
     public static volatile boolean first = true;
-    protected static Logger logger = LoggerFactory.getLogger(StockGetDataJob.class);
+    protected static Logger logger = LoggerFactory.getLogger(AbstractGetDataJob.class);
     /**
      * 数据接口调用间隔时长(毫秒)
      */
@@ -66,7 +66,15 @@
                     }
                     Integer frequency = AdjustmentValueCache.getFrequency().get(symbol);
                     if (frequency == null) {
-                        frequency = (int) Arith.div(Arith.mul(delayValue.getSecond(), 1000.0D), this.interval);
+                        double rawFrequency = Arith.div(Arith.mul(delayValue.getSecond(), 1000.0D), this.interval);
+                        // 判断是否有小数部分
+                        if (rawFrequency > (int) rawFrequency) {
+                            // 有小数(如333.333)→ +1
+                            frequency = (int) rawFrequency + 1;
+                        } else {
+                            // 无小数(如500.0)→ 不+1
+                            frequency = (int) rawFrequency;
+                        }
                         AdjustmentValueCache.getFrequency().put(symbol, frequency);
                     }
                     if (frequency <= 1) {
@@ -86,16 +94,21 @@
                         List<BigDecimal> adjustments = AdjustmentValueCache.getPreAllocatedAdjustments().get(symbol);
                         Integer currentIndex = AdjustmentValueCache.getCurrentAdjustmentIndex().get(symbol);
 
-                        // 首次执行:生成含正负值的调整序列
+                        // 首次执行:生成调整序列(小幅调整用等额分步,确保合计等于目标值)
                         if (adjustments == null || currentIndex == null) {
-                            //分几段执行
-                            int nums = Math.max(10, frequency / 10);
-                            List<BigDecimal> result = RandomNumbersGenerator.generateNumbers(delayValue.getValue(), nums, decimal + 4);
-                            for (int i = 0; i < result.size(); i++) {
-                                if (adjustments == null) {
-                                    adjustments = new ArrayList<>();
+                            if (delayValue.getValue().abs().compareTo(new BigDecimal("2")) <= 0) {
+                                adjustments = buildEqualAdjustments(delayValue.getValue(), frequency, decimal);
+                            } else {
+                                int nums = Math.max(10, frequency / 10);
+                                List<BigDecimal> result = RandomNumbersGenerator.generateNumbers(delayValue.getValue(), nums, decimal + 4);
+                                adjustments = new ArrayList<>();
+                                for (int i = 0; i < result.size(); i++) {
+                                    int count = frequency / nums;
+                                    if (i == result.size() - 1) {
+                                        count += frequency % nums;
+                                    }
+                                    adjustments.addAll(generateRandomAdjustments(result.get(i), count, decimal));
                                 }
-                                adjustments.addAll(generateRandomAdjustments(result.get(i), frequency / 10, decimal));
                             }
                             currentIndex = 0;
                             AdjustmentValueCache.getPreAllocatedAdjustments().put(symbol, adjustments);
@@ -184,12 +197,19 @@
             realtime.setTs(Long.valueOf(realtime.getTs() + "000"));
         }
         realtime.setName(item.getName());
-        if (high == null || realtime.getHigh().doubleValue() > high) {
+        /*if (high == null || realtime.getHigh().doubleValue() > high) {
             DataCache.getRealtimeHigh().put(symbol, realtime.getHigh().doubleValue());
         }
         if ((low == null || realtime.getLow().doubleValue() < low) && realtime.getLow().doubleValue() > 0) {
             DataCache.getRealtimeLow().put(symbol, realtime.getLow().doubleValue());
+        }*/
+        if (high != null) {
+            realtime.setHigh(BigDecimal.valueOf(high));
         }
+        if (low != null) {
+            realtime.setLow(BigDecimal.valueOf(low));
+        }
+        DataCache.putRealtime(symbol, realtime);
         this.dataDBService.saveAsyn(realtime);
     }
 
@@ -198,6 +218,26 @@
         AdjustmentValueCache.getPreAllocatedAdjustments().remove(symbol);
         AdjustmentValueCache.getCurrentAdjustmentIndex().remove(symbol);
         AdjustmentValueCache.getFrequency().remove(symbol);
+    }
+
+    /**
+     * 等额分步,保证各步相加严格等于 totalValue(适用于管理员小幅调价,如 -0.1)。
+     */
+    private List<BigDecimal> buildEqualAdjustments(BigDecimal totalValue, int count, int decimal) {
+        List<BigDecimal> adjustments = new ArrayList<>(Math.max(1, count));
+        if (count <= 1) {
+            adjustments.add(totalValue.setScale(decimal, RoundingMode.HALF_UP));
+            return adjustments;
+        }
+        BigDecimal per = totalValue.divide(BigDecimal.valueOf(count), decimal + 4, RoundingMode.HALF_UP);
+        BigDecimal sum = BigDecimal.ZERO;
+        for (int i = 0; i < count - 1; i++) {
+            BigDecimal step = per.setScale(decimal, RoundingMode.HALF_UP);
+            adjustments.add(step);
+            sum = sum.add(step);
+        }
+        adjustments.add(totalValue.subtract(sum).setScale(decimal, RoundingMode.HALF_UP));
+        return adjustments;
     }
 
     private List<BigDecimal> generateRandomAdjustments(BigDecimal totalValue, int count, int decimal) {
@@ -309,13 +349,21 @@
     public static void main(String[] args) {
         AbstractGetDataJob abstractGetDataJob = new CryptosGetDataJob();
         List<BigDecimal> list = new ArrayList<>();
-        int frequency = 200;
-        int decimal = 6;
+        int frequency = 334;
+        int decimal = 4;
         //分几段执行
         int nums = Math.max(10, frequency / 10);
+        System.out.println(nums);
         List<BigDecimal> result = RandomNumbersGenerator.generateNumbers(BigDecimal.valueOf(0.02), nums, decimal + 4);
+        System.out.println(result);
         for (int i = 0; i < result.size(); i++) {
-            list.addAll(abstractGetDataJob.generateRandomAdjustments(result.get(i), frequency / 10, decimal));
+            int count = frequency / nums;
+            if (i == result.size() - 1) {
+                count += frequency % nums;
+            }
+            List<BigDecimal> numbers = abstractGetDataJob.generateRandomAdjustments(result.get(i), count, decimal);
+            System.out.println(numbers);
+            list.addAll(numbers);
         }
 
         BigDecimal sum = BigDecimal.ZERO;
@@ -329,7 +377,7 @@
 
             numd = numd.add(list.get(i));
             num++;
-            if (num == 20) {
+            if (num == 33) {
                 System.out.println(dmt+"ddd" + numd);
                 dmt++;
                 num=0;

--
Gitblit v1.9.3