From 7aa5b5509eaa80e0361f261093f9d4ddabbadc0e Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Wed, 28 Jan 2026 18:47:27 +0800
Subject: [PATCH] adj优化
---
trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/AbstractGetDataJob.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 50 insertions(+), 6 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 27a1238..d10d3e9 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
@@ -6,6 +6,7 @@
import com.yami.trading.common.util.Arith;
import com.yami.trading.huobi.data.AdjustmentValueCache;
import com.yami.trading.huobi.data.DataCache;
+import com.yami.trading.huobi.data.RandomNumbersGenerator;
import com.yami.trading.huobi.data.internal.DataDBService;
import com.yami.trading.huobi.data.model.AdjustmentValue;
import com.yami.trading.huobi.hobi.HobiDataService;
@@ -23,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);
/**
* 数据接口调用间隔时长(毫秒)
*/
@@ -65,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) {
@@ -87,7 +96,19 @@
// 首次执行:生成含正负值的调整序列
if (adjustments == null || currentIndex == null) {
- adjustments = generateRandomAdjustments(delayValue.getValue(), frequency, decimal);
+ //分几段执行
+ 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<>();
+ }
+ int count = frequency / nums;
+ if (i == result.size() - 1) {
+ count += frequency % nums;
+ }
+ adjustments.addAll(generateRandomAdjustments(result.get(i), count, decimal));
+ }
currentIndex = 0;
AdjustmentValueCache.getPreAllocatedAdjustments().put(symbol, adjustments);
AdjustmentValueCache.getCurrentAdjustmentIndex().put(symbol, currentIndex);
@@ -175,11 +196,17 @@
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));
}
this.dataDBService.saveAsyn(realtime);
}
@@ -299,7 +326,24 @@
public static void main(String[] args) {
AbstractGetDataJob abstractGetDataJob = new CryptosGetDataJob();
- List<BigDecimal> list = abstractGetDataJob.generateRandomAdjustments(new BigDecimal(0.002), 300, 8);
+ List<BigDecimal> list = new ArrayList<>();
+ 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++) {
+ 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;
int num = 0;
int dmt = 1;
@@ -311,7 +355,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