From 900c9b20cca19df60d14b9ea61d336ba640250f0 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 11 May 2026 10:49:57 +0800
Subject: [PATCH] fix(gateApi): 修复网格交易中仓位大小更新逻辑

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 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 b51f95d..a09714d 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -305,17 +305,20 @@
             if (hasPosition) {
                 longActive = true;
                 longEntryPrice = entryPrice;
-                longPositionSize = size;
                 if (!baseLongOpened) {
+                    longPositionSize = size;
                     longBaseEntryPrice = entryPrice;
                     baseLongOpened = true;
                     log.info("[Gate] 基底多成交价: {}", longBaseEntryPrice);
                     tryGenerateQueues();
-                } else {
+                } else if (size.compareTo(longPositionSize) > 0) {
+                    longPositionSize = size;
                     BigDecimal tpPrice = entryPrice.multiply(BigDecimal.ONE.add(config.getGridRate())).setScale(1, RoundingMode.HALF_UP);
                     executor.placeTakeProfit(tpPrice,
                             FuturesPriceTrigger.RuleEnum.NUMBER_1, ORDER_TYPE_CLOSE_LONG, negate(config.getQuantity()));
                     log.info("[Gate] 多单止盈已设, entry:{}, tp:{}, size:{}", entryPrice, tpPrice, negate(config.getQuantity()));
+                } else {
+                    longPositionSize = size;
                 }
             } else {
                 longActive = false;
@@ -325,17 +328,20 @@
             if (hasPosition) {
                 shortActive = true;
                 shortEntryPrice = entryPrice;
-                shortPositionSize = size.abs();
                 if (!baseShortOpened) {
+                    shortPositionSize = size.abs();
                     shortBaseEntryPrice = entryPrice;
                     baseShortOpened = true;
                     log.info("[Gate] 基底空成交价: {}", shortBaseEntryPrice);
                     tryGenerateQueues();
-                } else {
+                } else if (size.abs().compareTo(shortPositionSize) > 0) {
+                    shortPositionSize = size.abs();
                     BigDecimal tpPrice = entryPrice.multiply(BigDecimal.ONE.subtract(config.getGridRate())).setScale(1, RoundingMode.HALF_UP);
                     executor.placeTakeProfit(tpPrice,
                             FuturesPriceTrigger.RuleEnum.NUMBER_2, ORDER_TYPE_CLOSE_SHORT, config.getQuantity());
                     log.info("[Gate] 空单止盈已设, entry:{}, tp:{}, size:{}", entryPrice, tpPrice, config.getQuantity());
+                } else {
+                    shortPositionSize = size.abs();
                 }
             } else {
                 shortActive = false;

--
Gitblit v1.9.1