From b3a806741d1ace46b9bf8bd3974fc0bab24f4eee Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 06 Aug 2026 16:00:54 +0800
Subject: [PATCH] fix(gateApi): 修复网格交易中订单数量计算逻辑
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
index c7f9bb4..bef35fb 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -665,7 +665,6 @@
}
shortGridElement.setExtendStopLossInProgress(true);
- accumulatedShortLossCount = 0;
lastShortStopLossGridId = Integer.MAX_VALUE;
// [Gate-需求2] 加仓后先撤空仓所有止盈+止损,再查交易所持仓后重挂
cancelAllShortTakeProfitsAndStopLosses();
@@ -677,7 +676,7 @@
log.info("[Gate] 空单成交 gridId:{}, 当前持仓:{}张", filledQty, posSize);
-
+ accumulatedShortLossCount++;
checkShortStopLongProfit(accumulatedShortLossCount, shortGridElement.getId() + 2);
}
@@ -709,7 +708,7 @@
// placeExcessTakeProfit(posSize, true);
log.info("[Gate] 多单成交 gridId:{}, 当前持仓:{}张", filledQty, posSize);
-
+ accumulatedLongLossCount++;
checkLongStopShortProfit(accumulatedLongLossCount, longGridElement.getId() -2);
}
@@ -1158,8 +1157,8 @@
if (newEntryGrid != null) {
- String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_SHORT), shortPositionSize.intValue()) + Integer.parseInt(config.getQuantity()));
-
+// String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_SHORT), shortPositionSize.intValue()) + Integer.parseInt(config.getQuantity()));
+ String quantity = String.valueOf(config.getBaseQuantity());
// 向下检查是否已有多单挂在更低价格网格,有则跳过(防止价格回升后重复挂单)
boolean hasLongOrderBelow = false;
GridElement checkDownCursor = GridElement.findById(newEntryGrid.getDownId());
@@ -1229,8 +1228,8 @@
if (newEntryGrid != null) {
// String quantity = String.valueOf((accumulatedShortLossCount + 1) * Integer.parseInt(config.getQuantity()));
- String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_LONG), longPositionSize.intValue()) + Integer.parseInt(config.getQuantity()));
-
+// String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_LONG), longPositionSize.intValue()) + Integer.parseInt(config.getQuantity()));
+ String quantity = String.valueOf(config.getBaseQuantity());
// 向上检查是否已有空单挂在更高价格网格,有则跳过(防止价格回落后重复挂单)
boolean hasShortOrderAbove = false;
GridElement checkUpCursor = GridElement.findById(newEntryGrid.getUpId());
@@ -1288,7 +1287,6 @@
}
lastLongStopLossGridId = gridId;
- accumulatedLongLossCount++;
log.info("[Gate] 多仓止损触发 gridId:{}, 止损次数:{}{}, 开始追单",
gridId, accumulatedLongLossCount, sameGrid ? "(同网格)" : "");
int newEntryGridId = gridId + 1;
@@ -1331,6 +1329,7 @@
* </ul>
*/
private static final Map<Integer, int[]> STOP_LOSS_RULES = new LinkedHashMap<>();
+ private static final int DEFAULT_STOP_LOSS_PERCENT = 5;
static {
// times {满仓%, 阈值%}
@@ -1407,7 +1406,7 @@
int selfPos = Math.max(queryPositionSize(Position.ModeEnum.DUAL_LONG), longPositionSize.intValue());
int excess = selfPos - thresholdPosNum;
if (excess > 0) {
- int perOrderQty = maxPos * 5 / 100;
+ int perOrderQty = maxPos * DEFAULT_STOP_LOSS_PERCENT / 100;
if (perOrderQty <= 0) {
perOrderQty = 1;
}
@@ -1463,7 +1462,7 @@
int selfPos = Math.max(queryPositionSize(Position.ModeEnum.DUAL_SHORT), shortPositionSize.intValue());
int excess = selfPos - thresholdPosNum;
if (excess > 0) {
- int perOrderQty = maxPos * 5 / 100;
+ int perOrderQty = maxPos * DEFAULT_STOP_LOSS_PERCENT / 100;
if (perOrderQty <= 0) {
perOrderQty = 1;
}
@@ -1497,7 +1496,6 @@
return;
}
lastShortStopLossGridId = gridId;
- accumulatedShortLossCount++;
log.info("[Gate] 空仓止损触发 gridId:{}, 止损次数:{}{}, 开始追单",
gridId, accumulatedShortLossCount, sameGrid ? "(同网格)" : "");
int newEntryGridId = gridId - 1;
--
Gitblit v1.9.1