From f6080a67720f6241564589bb5b074661d8157f0f Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Fri, 30 Oct 2026 17:49:31 +0800
Subject: [PATCH] refactor(gateApi): 优化止损追单逻辑实现
---
src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
index 14733e7..6bc4530 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -121,6 +121,8 @@
private final int maxPositionPerSide;
/** 加仓启动阈值:前N次止损不触发加仓,默认 1(第1次止损不加仓,第2次起按公式计算) */
private final int addPositionStartThreshold;
+ /** 加仓停止阈值:启动加仓后按「加仓执行次数」计数,超过该值后加仓张数恢复为基础张数;0=不限制 */
+ private final int addPositionStopThreshold;
/** 止盈挂单模式:关闭 */
public static final String EXCESS_TP_OFF = "off";
/** 止盈挂单模式:集中止盈(挂在对手第一止损位) */
@@ -140,6 +142,10 @@
private final boolean tpTriggerOppositeAddEnabled;
/** 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数,0=不启用。默认 0 */
private final int tpTriggerOppositeAddQuantity;
+ /** 单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数,支持小数。默认 0 */
+ private final BigDecimal baseTakeProfitPerGrid;
+ /** 止盈网格数量:基础仓位止盈挂单的网格数量。默认 0 */
+ private final int baseTakeProfitGridCount;
/** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */
private BigDecimal step;
/** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */
@@ -180,12 +186,15 @@
this.addPositionQuantity = builder.addPositionQuantity;
this.maxPositionPerSide = builder.maxPositionPerSide;
this.addPositionStartThreshold = builder.addPositionStartThreshold;
+ this.addPositionStopThreshold = builder.addPositionStopThreshold;
this.placeExcessTakeProfit = builder.placeExcessTakeProfit;
this.dualStopLossEnabled = builder.dualStopLossEnabled;
this.longStopLossPrice = builder.longStopLossPrice;
this.shortStopLossPrice = builder.shortStopLossPrice;
this.tpTriggerOppositeAddEnabled = builder.tpTriggerOppositeAddEnabled;
this.tpTriggerOppositeAddQuantity = builder.tpTriggerOppositeAddQuantity;
+ this.baseTakeProfitPerGrid = builder.baseTakeProfitPerGrid;
+ this.baseTakeProfitGridCount = builder.baseTakeProfitGridCount;
}
// ==================== REST/WS 地址 ====================
@@ -291,6 +300,8 @@
public int getMaxPositionPerSide() { return maxPositionPerSide; }
/** @return 加仓启动阈值:前N次止损不触发加仓 */
public int getAddPositionStartThreshold() { return addPositionStartThreshold; }
+ /** @return 加仓停止阈值:启动加仓后加仓执行次数上限,超过后加仓张数恢复基础张数;0=不限制 */
+ public int getAddPositionStopThreshold() { return addPositionStopThreshold; }
/** @return 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈 */
public String getPlaceExcessTakeProfit() { return placeExcessTakeProfit; }
/** @return 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损 */
@@ -303,6 +314,10 @@
public boolean isTpTriggerOppositeAddEnabled() { return tpTriggerOppositeAddEnabled; }
/** @return 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数 */
public int getTpTriggerOppositeAddQuantity() { return tpTriggerOppositeAddQuantity; }
+ /** @return 单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数 */
+ public BigDecimal getBaseTakeProfitPerGrid() { return baseTakeProfitPerGrid; }
+ /** @return 止盈网格数量:基础仓位止盈挂单的网格数量 */
+ public int getBaseTakeProfitGridCount() { return baseTakeProfitGridCount; }
// ==================== 运行时参数 ====================
@@ -413,6 +428,8 @@
private int maxPositionPerSide = 0;
/** 加仓启动阈值:前N次止损不触发加仓,调整后的 effectiveCount = max(0, count - threshold)。默认 1 */
private int addPositionStartThreshold = 1;
+ /** 加仓停止阈值:启动加仓后按加仓执行次数计数,超过该值后加仓张数恢复基础张数,0=不限制。默认 0 */
+ private int addPositionStopThreshold = 0;
/** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */
private String placeExcessTakeProfit = EXCESS_TP_OFF;
/** 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损。默认 false */
@@ -425,6 +442,10 @@
private boolean tpTriggerOppositeAddEnabled = false;
/** 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数,默认 0 */
private int tpTriggerOppositeAddQuantity = 0;
+ /** 单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数,默认 0 */
+ private BigDecimal baseTakeProfitPerGrid = BigDecimal.ZERO;
+ /** 止盈网格数量:基础仓位止盈挂单的网格数量,默认 0 */
+ private int baseTakeProfitGridCount = 0;
/** 设置 API Key */
public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; }
@@ -486,6 +507,8 @@
public Builder maxPositionPerSide(int maxPositionPerSide) { this.maxPositionPerSide = maxPositionPerSide; return this; }
/** 设置加仓启动阈值:前N次止损不触发加仓,0=立即启动 */
public Builder addPositionStartThreshold(int addPositionStartThreshold) { this.addPositionStartThreshold = addPositionStartThreshold; return this; }
+ /** 设置加仓停止阈值:启动加仓后加仓执行次数上限,0=不限制 */
+ public Builder addPositionStopThreshold(int addPositionStopThreshold) { this.addPositionStopThreshold = addPositionStopThreshold; return this; }
/** 设置止盈挂单模式:off / concentrated / dispersed */
public Builder placeExcessTakeProfit(String placeExcessTakeProfit) { this.placeExcessTakeProfit = placeExcessTakeProfit; return this; }
/** 设置自定义止损开关:true=启用自定义止损触发价 */
@@ -498,6 +521,10 @@
public Builder tpTriggerOppositeAddEnabled(boolean tpTriggerOppositeAddEnabled) { this.tpTriggerOppositeAddEnabled = tpTriggerOppositeAddEnabled; return this; }
/** 设置对向加仓挂单数量:止盈成交后在对向挂出的开仓张数 */
public Builder tpTriggerOppositeAddQuantity(int tpTriggerOppositeAddQuantity) { this.tpTriggerOppositeAddQuantity = tpTriggerOppositeAddQuantity; return this; }
+ /** 设置单格止盈张数:基础仓位止盈挂单时每个网格挂的止盈张数 */
+ public Builder baseTakeProfitPerGrid(BigDecimal baseTakeProfitPerGrid) { this.baseTakeProfitPerGrid = baseTakeProfitPerGrid; return this; }
+ /** 设置止盈网格数量:基础仓位止盈挂单的网格数量 */
+ public Builder baseTakeProfitGridCount(int baseTakeProfitGridCount) { this.baseTakeProfitGridCount = baseTakeProfitGridCount; return this; }
public GateConfig build() {
return new GateConfig(this);
--
Gitblit v1.9.1