| | |
| | | /** 最近触发止损的空头网格ID */ |
| | | private volatile int lastShortStopLossGridId = Integer.MAX_VALUE; |
| | | /** 自定义止损模式激活标记:true=尚未发生第一次止损触发,第一次触发后置 false(触发未触发侧重挂默认) */ |
| | | private final AtomicBoolean customStopLossModeActive = new AtomicBoolean(false); |
| | | private final AtomicBoolean dualStopLossModeActive = new AtomicBoolean(false); |
| | | |
| | | private volatile BigDecimal lastKlinePrice; |
| | | private volatile BigDecimal markPrice = BigDecimal.ZERO; |
| | |
| | | accumulatedShortLossCount = 0; |
| | | lastLongStopLossGridId = Integer.MAX_VALUE; |
| | | lastShortStopLossGridId = Integer.MAX_VALUE; |
| | | customStopLossModeActive.set(false); |
| | | dualStopLossModeActive.set(false); |
| | | shortPriceQueue.clear(); |
| | | longPriceQueue.clear(); |
| | | totalShortPriceQueue.clear(); |
| | |
| | | // ); |
| | | // } |
| | | |
| | | if (config.isCustomStopLossEnabled()) { |
| | | if (config.isDualStopLossEnabled()) { |
| | | placeCustomStopLosses(); |
| | | } else { |
| | | placeDefaultStopLossLadders(); |
| | |
| | | * 多仓止损:NUMBER_2(价格 ≤ 触发价平多),空仓止损:NUMBER_1(价格 ≥ 触发价平空)。 |
| | | */ |
| | | private void placeCustomStopLosses() { |
| | | customStopLossModeActive.set(true); |
| | | dualStopLossModeActive.set(true); |
| | | String baseQty = config.getBaseQuantity(); |
| | | BigDecimal longPrice = config.getLongCustomStopLossPrice(); |
| | | BigDecimal shortPrice = config.getShortCustomStopLossPrice(); |
| | | BigDecimal longPrice = config.getLongStopLossPrice(); |
| | | BigDecimal shortPrice = config.getShortStopLossPrice(); |
| | | |
| | | if (longPrice != null && longPrice.compareTo(BigDecimal.ZERO) > 0) { |
| | | GridElement longElem = findNearestGridElementByPrice(longPrice); |
| | |
| | | } |
| | | |
| | | // 自定义止损模式:第一次止损触发时,取消未触发侧(空仓)自定义止损单并重挂默认阶梯 |
| | | if (config.isCustomStopLossEnabled() && customStopLossModeActive.compareAndSet(true, false)) { |
| | | if (config.isDualStopLossEnabled() && dualStopLossModeActive.compareAndSet(true, false)) { |
| | | cancelAllShortStopLossesOnly(); |
| | | placeDefaultShortStopLossLadder(); |
| | | log.info("[Gate] 自定义止损首次触发(多仓), 已取消空仓自定义止损并重挂默认阶梯"); |
| | |
| | | } |
| | | |
| | | // 自定义止损模式:第一次止损触发时,取消未触发侧(多仓)自定义止损单并重挂默认阶梯 |
| | | if (config.isCustomStopLossEnabled() && customStopLossModeActive.compareAndSet(true, false)) { |
| | | if (config.isDualStopLossEnabled() && dualStopLossModeActive.compareAndSet(true, false)) { |
| | | cancelAllLongStopLossesOnly(); |
| | | placeDefaultLongStopLossLadder(); |
| | | log.info("[Gate] 自定义止损首次触发(空仓), 已取消多仓自定义止损并重挂默认阶梯"); |