From bd3a9f2256030b8f41f944568ca7705de7d7fdd8 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sat, 09 May 2026 16:05:33 +0800
Subject: [PATCH] 增加了仓位推动的日志打印
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 31 +++++++++++++++++++++++--------
1 files changed, 23 insertions(+), 8 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 2bccbd2..cd4f0b9 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -58,8 +58,6 @@
WAITING_KLINE, OPENING, ACTIVE, STOPPED
}
- private static final String AUTO_SIZE_LONG = "close_long";
- private static final String AUTO_SIZE_SHORT = "close_short";
private static final String ORDER_TYPE_CLOSE_LONG = "close-long-position";
private static final String ORDER_TYPE_CLOSE_SHORT = "close-short-position";
@@ -123,6 +121,12 @@
FuturesAccount account = futuresApi.listFuturesAccounts(SETTLE);
this.initialPrincipal = new BigDecimal(account.getTotal());
log.info("[Gate] 初始本金: {} USDT", initialPrincipal);
+
+ //设置持仓模式为双向持仓
+ Boolean inDualMode = account.getInDualMode();
+ if (!inDualMode) {
+ futuresApi.setDualModeCall(SETTLE,true,null);
+ }
if (!config.getPositionMode().equals(account.getPositionMode())) {
futuresApi.setPositionMode(SETTLE, config.getPositionMode());
@@ -265,8 +269,8 @@
} else {
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, AUTO_SIZE_LONG);
- log.info("[Gate] 多单止盈已设, entry:{}, tp:{}", entryPrice, tpPrice);
+ FuturesPriceTrigger.RuleEnum.NUMBER_1, ORDER_TYPE_CLOSE_LONG, negate(config.getQuantity()));
+ log.info("[Gate] 多单止盈已设, entry:{}, tp:{}, size:{}", entryPrice, tpPrice, negate(config.getQuantity()));
}
} else {
longActive = false;
@@ -285,8 +289,8 @@
} else {
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, AUTO_SIZE_SHORT);
- log.info("[Gate] 空单止盈已设, entry:{}, tp:{}", entryPrice, tpPrice);
+ FuturesPriceTrigger.RuleEnum.NUMBER_2, ORDER_TYPE_CLOSE_SHORT, config.getQuantity());
+ log.info("[Gate] 空单止盈已设, entry:{}, tp:{}, size:{}", entryPrice, tpPrice, config.getQuantity());
}
} else {
shortActive = false;
@@ -358,10 +362,11 @@
}
}
}
+ log.info("[Gate] 空队列:{}", shortPriceQueue);
if (matched.isEmpty()) {
+ log.info("[Gate] 空仓队列未触发, 当前价:{}", currentPrice);
return;
}
-
log.info("[Gate] 空仓队列触发, 匹配{}个元素, 当前价:{}", matched.size(), currentPrice);
if (!isMarginSafe()) {
log.warn("[Gate] 保证金超限,跳过空单开仓");
@@ -377,7 +382,9 @@
min = min.multiply(BigDecimal.ONE.subtract(step)).setScale(1, RoundingMode.HALF_UP);
shortPriceQueue.add(min);
}
- shortPriceQueue.sort((a, b) -> b.compareTo(a));
+ shortPriceQueue.sort(BigDecimal::compareTo);
+
+ log.info("[Gate] 空队列:{}", shortPriceQueue);
}
synchronized (longPriceQueue) {
@@ -386,6 +393,8 @@
while (longPriceQueue.size() > config.getGridQueueSize()) {
longPriceQueue.remove(longPriceQueue.size() - 1);
}
+
+ log.info("[Gate] 多队列:{}", shortPriceQueue);
}
}
@@ -400,7 +409,9 @@
}
}
}
+ log.info("[Gate] 多队列:{}", longPriceQueue);
if (matched.isEmpty()) {
+ log.info("[Gate] 多仓队列未触发, 当前价:{}", currentPrice);
return;
}
@@ -420,6 +431,8 @@
longPriceQueue.add(max);
}
longPriceQueue.sort(BigDecimal::compareTo);
+
+ log.info("[Gate] 多队列:{}", longPriceQueue);
}
synchronized (shortPriceQueue) {
@@ -428,6 +441,8 @@
while (shortPriceQueue.size() > config.getGridQueueSize()) {
shortPriceQueue.remove(shortPriceQueue.size() - 1);
}
+
+ log.info("[Gate] 空队列:{}", shortPriceQueue);
}
}
--
Gitblit v1.9.1