From 4a12400915bd7ca1404cb68df0a5148a99a431d9 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sat, 06 Jun 2026 11:30:15 +0800
Subject: [PATCH] feat(gateApi): 添加最大持仓限制和止盈机制
---
src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java | 47 +++++++++++++++++++++++++----------------------
1 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
index ef58b29..597ea23 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
@@ -58,24 +58,6 @@
log.info("[管理器] 开始初始化...");
try {
- //测试盘
-// config = GateConfig.builder()
-// .apiKey("d90ca272391992b8e74f8f92cedb21ec")
-// .apiSecret("1861e4f52de4bb53369ea3208d9ede38ece4777368030f96c77d27934c46c274")
-// .contract("ETH_USDT")
-// .leverage("100")
-// .marginMode("CROSS")
-// .positionMode("dual")
-// .gridRate(new BigDecimal("0.002"))
-// .overallTp(new BigDecimal("5"))
-// .maxLoss(new BigDecimal("15"))
-// .quantity("1")
-// .priceScale(1)
-// .contractMultiplier(new BigDecimal("0.01"))
-// .unrealizedPnlPriceMode(GateConfig.PnLPriceMode.LAST_PRICE)
-// .isProduction(false)
-// .reopenMaxRetries(3)
-// .build();
//实盘
config = GateConfig.builder()
.apiKey("a2338398e00b7935104520e16be96918")
@@ -85,21 +67,41 @@
.marginMode("CROSS")
.positionMode("dual")
.gridRate(new BigDecimal("0.005"))
- .overallTp(new BigDecimal("100"))
- .maxLoss(new BigDecimal("15"))
- .quantity("5")
+ .expectedProfit(new BigDecimal("0.5"))
+ .maxLoss(new BigDecimal("1.5"))
+ .baseQuantity("3")
+ .quantity("1")
+ .maxPositionSize(9)
.priceScale(2)
.contractMultiplier(new BigDecimal("0.01"))
.unrealizedPnlPriceMode(GateConfig.PnLPriceMode.LAST_PRICE)
.isProduction(true)
.reopenMaxRetries(3)
.build();
+// //测试盘
+// config = GateConfig.builder()
+// .apiKey("d90ca272391992b8e74f8f92cedb21ec")
+// .apiSecret("1861e4f52de4bb53369ea3208d9ede38ece4777368030f96c77d27934c46c274")
+// .contract("ETH_USDT")
+// .leverage("100")
+// .marginMode("CROSS")
+// .positionMode("dual")
+// .gridRate(new BigDecimal("0.002"))
+// .expectedProfit(new BigDecimal("1"))
+// .maxLoss(new BigDecimal("15"))
+// .quantity("1")
+// .priceScale(1)
+// .contractMultiplier(new BigDecimal("0.01"))
+// .unrealizedPnlPriceMode(GateConfig.PnLPriceMode.LAST_PRICE)
+// .isProduction(false)
+// .reopenMaxRetries(3)
+// .build();
// 1. 初始化交易服务:查用户ID → 切持仓模式 → 清条件单 → 平已有仓位 → 设杠杆
gridTradeService = new GateGridTradeService(config);
gridTradeService.init();
- // 2. 创建 WS 客户端并注册 3 个频道处理器
+ // 2. 创建 WS 客户端并注册频道处理器
wsClient = new GateKlineWebSocketClient(config.getWsUrl());
wsClient.addChannelHandler(new CandlestickChannelHandler(config.getContract(), gridTradeService));
wsClient.addChannelHandler(new PositionsChannelHandler(
@@ -112,6 +114,7 @@
config.getApiKey(), config.getApiSecret(), config.getContract(), gridTradeService));
wsClient.addChannelHandler(new AutoOrdersChannelHandler(
config.getApiKey(), config.getApiSecret(), config.getContract(), gridTradeService));
+ gridTradeService.setWsClient(wsClient);
wsClient.init();
log.info("[管理器] WS已连接, 已注册 6 个频道处理器");
--
Gitblit v1.9.1