From 4802f4b913efa31a97942fde6d07366f2de534ec Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 18 Jun 2026 10:54:29 +0800
Subject: [PATCH] fix(gateApi): 修正网格交易费率配置
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 59 ++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 36 insertions(+), 23 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 e5fca3e..aeb9d38 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -1127,18 +1127,22 @@
return;
}
- BigDecimal triggerPrice = newEntryGrid.getGridPrice();
+ // [Gate-BugFix] 防止与"仓位归零"重复下单:若该网格已有挂单则跳过
+ if (!newEntryGrid.isHasLongOrder()) {
+ BigDecimal triggerPrice = newEntryGrid.getGridPrice();
- // 累计止损张数 + 当前止损量作为追单size,不再依赖positionSize(避免WS竞态)
- accumulatedLongLossCount += Integer.parseInt(config.getQuantity());
- String size = String.valueOf(accumulatedLongLossCount + Integer.parseInt(config.getQuantity()));
- log.info("[Gate] 多仓止损触发 gridId:{}, 在gridId:{}挂{}基础张多单",
- gridId, newEntryGridId, size);
+ // 累计止损张数 + 当前止损量作为追单size,不再依赖positionSize(避免WS竞态)
+ accumulatedLongLossCount += Integer.parseInt(config.getQuantity());
+ String size = String.valueOf(accumulatedLongLossCount + Integer.parseInt(config.getQuantity()));
+ log.info("[Gate] 多仓止损触发 gridId:{}, 在gridId:{}挂{}基础张多单",
+ gridId, newEntryGridId, size);
- newEntryGrid.getLongTraderParam().setQuantity(size);
- placeEntryOrderWithPreFlag(newEntryGrid, true, triggerPrice,
- FuturesPriceTrigger.RuleEnum.NUMBER_1, size);
-
+ newEntryGrid.getLongTraderParam().setQuantity(size);
+ placeEntryOrderWithPreFlag(newEntryGrid, true, triggerPrice,
+ FuturesPriceTrigger.RuleEnum.NUMBER_1, size);
+ }else{
+ log.warn("[Gate] 多仓止损触发 gridId:{}, 目标gridId:{}已有挂单,跳过重复下单", gridId, newEntryGridId);
+ }
int cancelGridId = gridId + 2;
GridElement cancelGrid = GridElement.findById(cancelGridId);
@@ -1182,16 +1186,23 @@
return;
}
- BigDecimal triggerPrice = newEntryGrid.getGridPrice();
+ // [Gate-BugFix] 防止与"仓位归零"重复下单:若该网格已有挂单则跳过
+ if (!newEntryGrid.isHasShortOrder()) {
+ BigDecimal triggerPrice = newEntryGrid.getGridPrice();
- // 累计止损张数 + 当前止损量作为追单size,不再依赖positionSize(避免WS竞态)
- accumulatedShortLossCount += Integer.parseInt(config.getQuantity());
- String size = String.valueOf(accumulatedShortLossCount + Integer.parseInt(config.getQuantity()));
- log.info("[Gate] 空仓止损触发 gridId:{}, 在gridId:{}挂{}基础张空单",
- gridId, newEntryGridId, size);
- newEntryGrid.getShortTraderParam().setQuantity(size);
- placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
- FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size));
+ // 累计止损张数 + 当前止损量作为追单size,不再依赖positionSize(避免WS竞态)
+ accumulatedShortLossCount += Integer.parseInt(config.getQuantity());
+ String size = String.valueOf(accumulatedShortLossCount + Integer.parseInt(config.getQuantity()));
+ log.info("[Gate] 空仓止损触发 gridId:{}, 在gridId:{}挂{}基础张空单",
+ gridId, newEntryGridId, size);
+ newEntryGrid.getShortTraderParam().setQuantity(size);
+ placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
+ FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size));
+ }else{
+ log.warn("[Gate] 空仓止损触发 gridId:{}, 目标gridId:{}已有挂单,跳过重复下单", gridId, newEntryGridId);
+ }
+
+
int cancelGridId = gridId - 2;
@@ -1235,8 +1246,9 @@
furthestSlId = gridId;
interval = 2;
}
- log.info("[Gate] 多仓追挂止损, 当前最远止损gridId:{}, 追加{}张", furthestSlId, filledQty);
- for (int i = 0; i < filledQty; i++) {
+ int stopLossCount = filledQty / Integer.parseInt(config.getQuantity());
+ log.info("[Gate] 多仓追挂止损, 当前最远止损gridId:{}, 成交{}张, 追加{}个止损单", furthestSlId, filledQty, stopLossCount);
+ for (int i = 0; i < stopLossCount; i++) {
int newSlId = furthestSlId - i - interval;
GridElement elem = GridElement.findById(newSlId);
if (elem == null) {
@@ -1271,8 +1283,9 @@
furthestSlId = gridId;
interval = 2;
}
- log.info("[Gate] 空仓追挂止损, 当前最远止损gridId:{}, 追加{}张", furthestSlId, filledQty);
- for (int i = 0; i < filledQty; i++) {
+ int stopLossCount = filledQty / Integer.parseInt(config.getQuantity());
+ log.info("[Gate] 空仓追挂止损, 当前最远止损gridId:{}, 成交{}张, 追加{}个止损单", furthestSlId, filledQty, stopLossCount);
+ for (int i = 0; i < stopLossCount; i++) {
int newSlId = furthestSlId + i + interval;
GridElement elem = GridElement.findById(newSlId);
if (elem == null) {
--
Gitblit v1.9.1