From ef4d46d6d2c89353163e779499f38b11d03a2fa1 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 27 May 2026 14:48:48 +0800
Subject: [PATCH] config(gateApi): 更新Gate API配置参数
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 48 ++++++++++++++++++++++++++++++++----------------
1 files changed, 32 insertions(+), 16 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 04a4108..485bbae 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -1,6 +1,8 @@
package com.xcong.excoin.modules.gateApi;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xcong.excoin.utils.dingtalk.DingTalkUtils;
import io.gate.gateapi.ApiClient;
import io.gate.gateapi.ApiException;
import io.gate.gateapi.GateApiException;
@@ -426,14 +428,19 @@
tryGenerateQueues();
}else {
longPositionSize = size;
- //取消多仓位线以上的开空仓挂单
- List<GridElement> allShortOrders = GridElement.findAllShortOrders(longEntryPrice);
+ List<GridElement> allShortOrders = GridElement.findAllLongOrders(longEntryPrice);
if (CollUtil.isNotEmpty(allShortOrders)){
+ GridElement keep = allShortOrders.stream()
+ .max((a, b) -> a.getGridPrice().compareTo(b.getGridPrice()))
+ .orElse(null);
for (GridElement e : allShortOrders) {
+ if (e == keep) {
+ continue;
+ }
executor.cancelConditionalOrder(
- e.getShortOrderId(),
+ e.getLongOrderId(),
orderId -> {
- shortEntryTraderIdParam(
+ longEntryTraderIdParam(
e,
null,
false
@@ -441,11 +448,11 @@
}
);
- if (e.getShortTakeProfitOrderId() != null){
+ if (e.getLongTakeProfitOrderId() != null){
executor.cancelConditionalOrder(
- e.getShortTakeProfitOrderId(),
+ e.getLongTakeProfitOrderId(),
orderId -> {
- shortTakeProfitTraderIdParam(
+ longTakeProfitTraderIdParam(
e,
null,
false
@@ -472,25 +479,30 @@
tryGenerateQueues();
}else {
shortPositionSize = size.abs();
- //取消空仓仓位线以下的开多仓挂单
- List<GridElement> allLongOrders = GridElement.findAllLongOrders(shortEntryPrice);
+ List<GridElement> allLongOrders = GridElement.findAllShortOrders(shortEntryPrice);
if (CollUtil.isNotEmpty(allLongOrders)){
+ GridElement keep = allLongOrders.stream()
+ .min((a, b) -> a.getGridPrice().compareTo(b.getGridPrice()))
+ .orElse(null);
for (GridElement e : allLongOrders) {
+ if (e == keep) {
+ continue;
+ }
executor.cancelConditionalOrder(
- e.getLongOrderId(),
+ e.getShortOrderId(),
orderId -> {
- longEntryTraderIdParam(
+ shortEntryTraderIdParam(
e,
null,
false
);
}
);
- if (e.getLongTakeProfitOrderId() != null){
+ if (e.getShortTakeProfitOrderId() != null){
executor.cancelConditionalOrder(
- e.getLongTakeProfitOrderId(),
+ e.getShortTakeProfitOrderId(),
orderId -> {
- longTakeProfitTraderIdParam(
+ shortTakeProfitTraderIdParam(
e,
null,
false
@@ -536,9 +548,13 @@
totalPnl, cumulativePnl, unrealizedPnl);
state = StrategyState.STOPPED;
} else if (totalPnl.compareTo(config.getMaxLoss().negate()) <= 0) {
- log.info("[Gate] 已达亏损上限(合计{})→已停止, 已实现:{}, 未实现:{}",
+ String logMessage = StrUtil.format("[Gate] 已达亏损风险值(合计{}), 已实现:{}, 未实现:{}",
totalPnl, cumulativePnl, unrealizedPnl);
- state = StrategyState.STOPPED;
+ log.info(logMessage);
+
+
+ DingTalkUtils.getDefault().sendActionCard("风险提醒", logMessage, config.getApiKey(), "");
+// state = StrategyState.STOPPED;
}
}
--
Gitblit v1.9.1