From 50c3b885299e54e998305ec0b5ac73f084e78c55 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 23 Sep 2026 17:59:36 +0800
Subject: [PATCH] fix(gateApi): 修复网格交易中长短仓逻辑错误
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 20 ++++++++------------
1 files changed, 8 insertions(+), 12 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 0d0b369..3a2bb2a 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -529,7 +529,7 @@
config.isPriceDriveEnabled() &&
longActive == false &&
longPositionSize.compareTo(BigDecimal.ZERO) == 0){
- processShortGrid(closePrice);
+ processLongGrid(closePrice);
}
@@ -537,7 +537,7 @@
config.isPriceDriveEnabled() &&
shortActive == false &&
shortPositionSize.compareTo(BigDecimal.ZERO) == 0){
- processLongGrid(closePrice);
+ processShortGrid(closePrice);
}
}
@@ -948,12 +948,6 @@
generateShortQueue();
generateLongQueue();
updateGridElements();
-
- GridElement baseGridElement = GridElement.findById(0);
- baseGridElement.setLongOrderId(baseLongTraderParam.getEntryOrderId());
- baseGridElement.setHasLongOrder(true);
- baseGridElement.setShortOrderId(baseShortTraderParam.getEntryOrderId());
- baseGridElement.setHasShortOrder(true);
// // 空仓止损对应的多仓止盈:多仓止盈挂在ID=3
// int tpGridIdLong = 3;
@@ -1449,7 +1443,8 @@
}
- private void processShortGrid(BigDecimal currentPrice) {
+ /** 多仓仓位归零后,在当前价上方最近网格重新挂多单(遍历 totalLongPriceQueue 升序)。 */
+ private void processLongGrid(BigDecimal currentPrice) {
BigDecimal matched = BigDecimal.ZERO;
synchronized (totalLongPriceQueue) {
for (BigDecimal p : totalLongPriceQueue) {
@@ -1522,7 +1517,8 @@
}
- private void processLongGrid(BigDecimal currentPrice) {
+ /** 空仓仓位归零后,在当前价下方最近网格重新挂空单(遍历 totalShortPriceQueue 降序)。 */
+ private void processShortGrid(BigDecimal currentPrice) {
BigDecimal matched = BigDecimal.ZERO;
synchronized (totalShortPriceQueue) {
for (BigDecimal p : totalShortPriceQueue) {
@@ -1571,7 +1567,7 @@
GridElement finalCancelCursor = cancelCursor;
executor.cancelConditionalOrder(shortOrderId, oid -> {
shortEntryTraderIdParam(finalCancelCursor, shortOrderId, false);
- log.info("[Gate] 空仓仓位归零, 取消gridId:{}的多单{}", finalCancelCursor.getId(), shortOrderId);
+ log.info("[Gate] 空仓仓位归零, 取消gridId:{}的空单{}", finalCancelCursor.getId(), shortOrderId);
});
}
}
@@ -1582,7 +1578,7 @@
if (!newEntryGrid.isHasShortOrder() && !hasShortOrderAbove){
BigDecimal triggerPrice = newEntryGrid.getGridPrice();
String size = quantity;
- log.info("[Gate] 空仓仓位归零 gridId:{}, 挂{}基础张多单",
+ log.info("[Gate] 空仓仓位归零 gridId:{}, 挂{}基础张空单",
newEntryGrid.getId(), size);
newEntryGrid.getShortTraderParam().setQuantity(size);
placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
--
Gitblit v1.9.1