From 5d0e6b7b45630f32100d23ca107a9c74df43db75 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 11 May 2026 11:58:04 +0800
Subject: [PATCH] refactor(gate): 移除账号标签配置和多账号支持功能

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java |   55 +++++++++++++++++++++++++++----------------------------
 1 files changed, 27 insertions(+), 28 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 fc47591..5710e88 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -166,6 +166,14 @@
                 }
             }
 
+            try {
+                futuresApi.updateDualModePositionLeverageCall(
+                        SETTLE, config.getContract(), config.getLeverage(),
+                        null, null).execute();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
             if (!config.getMarginMode().equals(account.getMarginMode())) {
 
                 UpdateDualCompPositionCrossModeRequest updateDualCompPositionCrossModeRequest = new UpdateDualCompPositionCrossModeRequest();
@@ -178,15 +186,6 @@
                 }
             }
             log.info("[Gate] 持仓模式: {} 余额: {}", config.getPositionMode(), account.getAvailable());
-
-
-            try {
-                futuresApi.updateDualModePositionLeverageCall(
-                        SETTLE, config.getContract(), config.getLeverage(),
-                        config.getMarginMode(), null).execute();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
             log.info("[Gate] 杠杆: {}x {}", config.getLeverage(), config.getMarginMode());
         } catch (GateApiException e) {
             log.error("[Gate] 初始化失败, label:{}, msg:{}", e.getErrorLabel(), e.getMessage());
@@ -306,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;
@@ -326,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;
@@ -454,8 +459,10 @@
             for (int i = 0; i < matched.size(); i++) {
                 min = min.multiply(BigDecimal.ONE.subtract(step)).setScale(1, RoundingMode.HALF_UP);
                 shortPriceQueue.add(min);
+                log.info("[Gate] 空队列增加:{}", min);
             }
-            shortPriceQueue.sort(BigDecimal::compareTo);
+
+            shortPriceQueue.sort((a, b) -> b.compareTo(a));
 
             log.info("[Gate] 现空队列:{}", shortPriceQueue);
         }
@@ -463,21 +470,16 @@
         synchronized (longPriceQueue) {
             BigDecimal first = longPriceQueue.isEmpty() ? matched.get(matched.size() - 1) : longPriceQueue.get(0);
             BigDecimal step = config.getGridRate();
-            int added = 0;
             for (int i = 1; i <= matched.size(); i++) {
                 BigDecimal elem = first.multiply(BigDecimal.ONE.subtract(step.multiply(BigDecimal.valueOf(i)))).setScale(1, RoundingMode.HALF_UP);
-                if (longEntryPrice.compareTo(BigDecimal.ZERO) > 0
-                        && elem.subtract(longEntryPrice).abs().compareTo(longEntryPrice.multiply(step)) < 0) {
-                    continue;
-                }
                 longPriceQueue.add(elem);
-                added++;
+                log.info("[Gate] 多队列增加:{}", elem);
             }
             longPriceQueue.sort(BigDecimal::compareTo);
             while (longPriceQueue.size() > config.getGridQueueSize()) {
                 longPriceQueue.remove(longPriceQueue.size() - 1);
             }
-            log.info("[Gate] 现多队列:{}, 跳过{}个(贴近多仓均价)", longPriceQueue, matched.size() - added);
+            log.info("[Gate] 现多队列:{}", longPriceQueue);
         }
     }
 
@@ -539,6 +541,8 @@
             for (int i = 0; i < matched.size(); i++) {
                 max = max.multiply(BigDecimal.ONE.add(step)).setScale(1, RoundingMode.HALF_UP);
                 longPriceQueue.add(max);
+
+                log.info("[Gate] 多队列增加:{}", max);
             }
             longPriceQueue.sort(BigDecimal::compareTo);
 
@@ -548,21 +552,16 @@
         synchronized (shortPriceQueue) {
             BigDecimal first = shortPriceQueue.isEmpty() ? matched.get(0) : shortPriceQueue.get(0);
             BigDecimal step = config.getGridRate();
-            int added = 0;
             for (int i = 1; i <= matched.size(); i++) {
                 BigDecimal elem = first.multiply(BigDecimal.ONE.add(step.multiply(BigDecimal.valueOf(i)))).setScale(1, RoundingMode.HALF_UP);
-                if (shortEntryPrice.compareTo(BigDecimal.ZERO) > 0
-                        && elem.subtract(shortEntryPrice).abs().compareTo(shortEntryPrice.multiply(step)) < 0) {
-                    continue;
-                }
                 shortPriceQueue.add(elem);
-                added++;
+                log.info("[Gate] 空队列增加:{}", elem);
             }
             shortPriceQueue.sort((a, b) -> b.compareTo(a));
             while (shortPriceQueue.size() > config.getGridQueueSize()) {
                 shortPriceQueue.remove(shortPriceQueue.size() - 1);
             }
-            log.info("[Gate] 现空队列:{}, 跳过{}个(贴近空仓均价)", shortPriceQueue, matched.size() - added);
+            log.info("[Gate] 现空队列:{}", shortPriceQueue);
         }
     }
 

--
Gitblit v1.9.1