| | |
| | | private final int stopLossCount; |
| | | /** 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2(即隔一格挂一个止盈单) */ |
| | | private final int takeProfitGridSpan; |
| | | /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。默认 true */ |
| | | private final boolean priceDriveEnabled; |
| | | /** 策略运行轮数:达到盈利后重启算一轮,达到上限后不再重启。0=不限轮数 */ |
| | | private final int rounds; |
| | | /** 止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计,默认 "dual" */ |
| | | private final String stopLossCountMode; |
| | | /** 加仓间隔:每隔多少次止损触发一次加仓,默认 3 */ |
| | | private final int addPositionInterval; |
| | | /** 加仓数量:每次加仓追加的张数,默认 1 */ |
| | | private final int addPositionQuantity; |
| | | /** 单边最大仓位量:单向持仓张数上限,超出则按上限挂单,0=不限制 */ |
| | | private final int maxPositionPerSide; |
| | | /** 加仓启动阈值:前N次止损不触发加仓,默认 1(第1次止损不加仓,第2次起按公式计算) */ |
| | | private final int addPositionStartThreshold; |
| | | /** 止盈挂单模式:关闭 */ |
| | | public static final String EXCESS_TP_OFF = "off"; |
| | | /** 止盈挂单模式:集中止盈(挂在对手第一止损位) */ |
| | | public static final String EXCESS_TP_CONCENTRATED = "concentrated"; |
| | | /** 止盈挂单模式:分散止盈(逐格挂到对手盘止损位) */ |
| | | public static final String EXCESS_TP_DISPERSED = "dispersed"; |
| | | |
| | | /** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */ |
| | | private final String placeExcessTakeProfit; |
| | | /** 自定义止损开关:true=启用自定义止损触发价(多空各挂一单),false=使用默认阶梯止损。默认 false */ |
| | | private final boolean dualStopLossEnabled; |
| | | /** 多仓自定义止损触发价(价格跌至该值触发平多),null/0=未设置 */ |
| | | private final BigDecimal longStopLossPrice; |
| | | /** 空仓自定义止损触发价(价格涨至该值触发平空),null/0=未设置 */ |
| | | private final BigDecimal shortStopLossPrice; |
| | | /** 止盈成交触发对向加仓开关:true=启用,false=禁用。默认 false */ |
| | | private final boolean tpTriggerOppositeAddEnabled; |
| | | /** 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数,0=不启用。默认 0 */ |
| | | private final int tpTriggerOppositeAddQuantity; |
| | | /** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */ |
| | | private BigDecimal step; |
| | | /** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */ |
| | |
| | | this.restartGridSpan = builder.restartGridSpan; |
| | | this.stopLossCount = builder.stopLossCount; |
| | | this.takeProfitGridSpan = builder.takeProfitGridSpan; |
| | | this.priceDriveEnabled = builder.priceDriveEnabled; |
| | | this.rounds = builder.rounds; |
| | | this.stopLossCountMode = builder.stopLossCountMode; |
| | | this.addPositionInterval = builder.addPositionInterval; |
| | | this.addPositionQuantity = builder.addPositionQuantity; |
| | | this.maxPositionPerSide = builder.maxPositionPerSide; |
| | | this.addPositionStartThreshold = builder.addPositionStartThreshold; |
| | | this.placeExcessTakeProfit = builder.placeExcessTakeProfit; |
| | | this.dualStopLossEnabled = builder.dualStopLossEnabled; |
| | | this.longStopLossPrice = builder.longStopLossPrice; |
| | | this.shortStopLossPrice = builder.shortStopLossPrice; |
| | | this.tpTriggerOppositeAddEnabled = builder.tpTriggerOppositeAddEnabled; |
| | | this.tpTriggerOppositeAddQuantity = builder.tpTriggerOppositeAddQuantity; |
| | | } |
| | | |
| | | // ==================== REST/WS 地址 ==================== |
| | |
| | | public int getStopLossCount() { return stopLossCount; } |
| | | /** @return 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */ |
| | | public int getTakeProfitGridSpan() { return takeProfitGridSpan; } |
| | | /** @return 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用 */ |
| | | public boolean isPriceDriveEnabled() { return priceDriveEnabled; } |
| | | /** @return 策略运行轮数上限,0=不限 */ |
| | | public int getRounds() { return rounds; } |
| | | /** @return 止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计 */ |
| | | public String getStopLossCountMode() { return stopLossCountMode; } |
| | | /** @return 加仓间隔:每隔多少次止损触发一次加仓 */ |
| | | public int getAddPositionInterval() { return addPositionInterval; } |
| | | /** @return 加仓数量:每次加仓追加的张数 */ |
| | | public int getAddPositionQuantity() { return addPositionQuantity; } |
| | | /** @return 单边最大仓位量:单向持仓张数上限,0=不限制 */ |
| | | public int getMaxPositionPerSide() { return maxPositionPerSide; } |
| | | /** @return 加仓启动阈值:前N次止损不触发加仓 */ |
| | | public int getAddPositionStartThreshold() { return addPositionStartThreshold; } |
| | | /** @return 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈 */ |
| | | public String getPlaceExcessTakeProfit() { return placeExcessTakeProfit; } |
| | | /** @return 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损 */ |
| | | public boolean isDualStopLossEnabled() { return dualStopLossEnabled; } |
| | | /** @return 多仓自定义止损触发价,null/0=未设置 */ |
| | | public BigDecimal getLongStopLossPrice() { return longStopLossPrice; } |
| | | /** @return 空仓自定义止损触发价,null/0=未设置 */ |
| | | public BigDecimal getShortStopLossPrice() { return shortStopLossPrice; } |
| | | /** @return 止盈成交触发对向加仓开关:true=启用,false=禁用 */ |
| | | public boolean isTpTriggerOppositeAddEnabled() { return tpTriggerOppositeAddEnabled; } |
| | | /** @return 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数 */ |
| | | public int getTpTriggerOppositeAddQuantity() { return tpTriggerOppositeAddQuantity; } |
| | | |
| | | // ==================== 运行时参数 ==================== |
| | | |
| | |
| | | private int stopLossCount = 0; |
| | | /** 止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */ |
| | | private int takeProfitGridSpan = 2; |
| | | /** 价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用。默认 true */ |
| | | private boolean priceDriveEnabled = true; |
| | | /** 策略运行轮数上限,0=不限轮数。默认 0 */ |
| | | private int rounds = 0; |
| | | /** 止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计,默认 "dual" */ |
| | | private String stopLossCountMode = "dual"; |
| | | /** 加仓间隔:每隔多少次止损触发一次加仓,默认 3 */ |
| | | private int addPositionInterval = 3; |
| | | /** 加仓数量:每次加仓追加的张数,默认 1 */ |
| | | private int addPositionQuantity = 1; |
| | | /** 单边最大仓位量:单向持仓张数上限,超出则按上限挂单,0=不限制 */ |
| | | private int maxPositionPerSide = 0; |
| | | /** 加仓启动阈值:前N次止损不触发加仓,调整后的 effectiveCount = max(0, count - threshold)。默认 1 */ |
| | | private int addPositionStartThreshold = 1; |
| | | /** 止盈挂单模式:off=关闭 / concentrated=集中止盈 / dispersed=分散止盈,默认 off */ |
| | | private String placeExcessTakeProfit = EXCESS_TP_OFF; |
| | | /** 自定义止损开关:true=启用自定义止损触发价,false=使用默认阶梯止损。默认 false */ |
| | | private boolean dualStopLossEnabled = false; |
| | | /** 多仓自定义止损触发价,null=未设置 */ |
| | | private BigDecimal longStopLossPrice; |
| | | /** 空仓自定义止损触发价,null=未设置 */ |
| | | private BigDecimal shortStopLossPrice; |
| | | /** 止盈成交触发对向加仓开关:true=启用,false=禁用。默认 false */ |
| | | private boolean tpTriggerOppositeAddEnabled = false; |
| | | /** 对向加仓挂单数量:止盈成交后在对向挂出的开仓张数,默认 0 */ |
| | | private int tpTriggerOppositeAddQuantity = 0; |
| | | |
| | | /** 设置 API Key */ |
| | | public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; } |
| | |
| | | public Builder stopLossCount(int stopLossCount) { this.stopLossCount = stopLossCount; return this; } |
| | | /** 设置止盈网格跨度:相邻止盈单跨越的网格数量,默认 2 */ |
| | | public Builder takeProfitGridSpan(int takeProfitGridSpan) { this.takeProfitGridSpan = takeProfitGridSpan; return this; } |
| | | /** 设置价格驱动开关:true=启用K线推送中的价格驱动逻辑,false=禁用 */ |
| | | public Builder priceDriveEnabled(boolean priceDriveEnabled) { this.priceDriveEnabled = priceDriveEnabled; return this; } |
| | | /** 设置策略运行轮数上限:达到盈利后重启计数,达到此值后不再重启。0=不限 */ |
| | | public Builder rounds(int rounds) { this.rounds = rounds; return this; } |
| | | /** 设置止损次数统计方式:"single"=单向分别统计 / "dual"=双向统一统计 */ |
| | | public Builder stopLossCountMode(String stopLossCountMode) { this.stopLossCountMode = stopLossCountMode; return this; } |
| | | /** 设置加仓间隔:每隔多少次止损触发一次加仓 */ |
| | | public Builder addPositionInterval(int addPositionInterval) { this.addPositionInterval = addPositionInterval; return this; } |
| | | /** 设置加仓数量:每次加仓追加的张数 */ |
| | | public Builder addPositionQuantity(int addPositionQuantity) { this.addPositionQuantity = addPositionQuantity; return this; } |
| | | /** 设置单边最大仓位量:单向持仓张数上限,0=不限制 */ |
| | | public Builder maxPositionPerSide(int maxPositionPerSide) { this.maxPositionPerSide = maxPositionPerSide; return this; } |
| | | /** 设置加仓启动阈值:前N次止损不触发加仓,0=立即启动 */ |
| | | public Builder addPositionStartThreshold(int addPositionStartThreshold) { this.addPositionStartThreshold = addPositionStartThreshold; return this; } |
| | | /** 设置止盈挂单模式:off / concentrated / dispersed */ |
| | | public Builder placeExcessTakeProfit(String placeExcessTakeProfit) { this.placeExcessTakeProfit = placeExcessTakeProfit; return this; } |
| | | /** 设置自定义止损开关:true=启用自定义止损触发价 */ |
| | | public Builder dualStopLossEnabled(boolean dualStopLossEnabled) { this.dualStopLossEnabled = dualStopLossEnabled; return this; } |
| | | /** 设置多仓自定义止损触发价 */ |
| | | public Builder longStopLossPrice(BigDecimal longStopLossPrice) { this.longStopLossPrice = longStopLossPrice; return this; } |
| | | /** 设置空仓自定义止损触发价 */ |
| | | public Builder shortStopLossPrice(BigDecimal shortStopLossPrice) { this.shortStopLossPrice = shortStopLossPrice; return this; } |
| | | /** 设置止盈成交触发对向加仓开关:true=启用,false=禁用 */ |
| | | public Builder tpTriggerOppositeAddEnabled(boolean tpTriggerOppositeAddEnabled) { this.tpTriggerOppositeAddEnabled = tpTriggerOppositeAddEnabled; return this; } |
| | | /** 设置对向加仓挂单数量:止盈成交后在对向挂出的开仓张数 */ |
| | | public Builder tpTriggerOppositeAddQuantity(int tpTriggerOppositeAddQuantity) { this.tpTriggerOppositeAddQuantity = tpTriggerOppositeAddQuantity; return this; } |
| | | |
| | | public GateConfig build() { |
| | | return new GateConfig(this); |