| | |
| | | private volatile int accumulatedLongLossCount = 0; |
| | | /** 空头累计止损次数(始终递增,加仓订单成交后归零) */ |
| | | private volatile int accumulatedShortLossCount = 0; |
| | | /** 多头当前网格重复触发次数(换网格时归零),用于 targetAmount 扣除 */ |
| | | private volatile int longSameGridRepeatCount = 0; |
| | | /** 空头当前网格重复触发次数(换网格时归零),用于 targetAmount 扣除 */ |
| | | private volatile int shortSameGridRepeatCount = 0; |
| | | /** 最近触发止损的多头网格ID */ |
| | | private volatile int lastLongStopLossGridId = Integer.MAX_VALUE; |
| | | /** 最近触发止损的空头网格ID */ |
| | |
| | | shortActive = false; |
| | | accumulatedLongLossCount = 0; |
| | | accumulatedShortLossCount = 0; |
| | | longSameGridRepeatCount = 0; |
| | | shortSameGridRepeatCount = 0; |
| | | lastLongStopLossGridId = Integer.MAX_VALUE; |
| | | lastShortStopLossGridId = Integer.MAX_VALUE; |
| | | shortPriceQueue.clear(); |
| | |
| | | int filledQty = Integer.parseInt(shortGridElement.getShortTraderParam().getQuantity()); |
| | | shortEntryTraderIdParam(shortGridElement, orderId, false); |
| | | accumulatedShortLossCount = 0; |
| | | shortSameGridRepeatCount = 0; |
| | | lastShortStopLossGridId = Integer.MAX_VALUE; |
| | | // [Gate-需求2] 加仓后先撤空仓所有止盈+止损,再查交易所持仓后重挂 |
| | | cancelAllShortTakeProfitsAndStopLosses(); |
| | |
| | | int filledQty = Integer.parseInt(longGridElement.getLongTraderParam().getQuantity()); |
| | | longEntryTraderIdParam(longGridElement, orderId, false); |
| | | accumulatedLongLossCount = 0; |
| | | longSameGridRepeatCount = 0; |
| | | lastLongStopLossGridId = Integer.MAX_VALUE; |
| | | // [Gate-需求2] 加仓后先撤多仓所有止盈+止损,再查交易所持仓后重挂 |
| | | cancelAllLongTakeProfitsAndStopLosses(); |
| | |
| | | gridElement.removeLongStopLossOrderId(orderId); |
| | | |
| | | int gridId = gridElement.getId(); |
| | | boolean sameGrid = (gridId == lastLongStopLossGridId); |
| | | accumulatedLongLossCount++; |
| | | if (gridId == lastLongStopLossGridId) { |
| | | longSameGridRepeatCount++; |
| | | } else { |
| | | longSameGridRepeatCount = 0; |
| | | lastLongStopLossGridId = gridId; |
| | | } |
| | | log.info("[Gate] 多仓止损触发 gridId:{}, 止损次数:{}, 开始追单", gridId, accumulatedLongLossCount); |
| | | lastLongStopLossGridId = gridId; |
| | | log.info("[Gate] 多仓止损触发 gridId:{}, 止损次数:{}{}, 开始追单", |
| | | gridId, accumulatedLongLossCount, sameGrid ? "(同网格)" : ""); |
| | | int newEntryGridId = gridId + 1; |
| | | |
| | | GridElement newEntryGrid = GridElement.findById(newEntryGridId); |
| | |
| | | BigDecimal triggerPrice = newEntryGrid.getGridPrice(); |
| | | int posSize = Math.min(queryPositionSize(Position.ModeEnum.DUAL_LONG), longPositionSize.intValue()); |
| | | int maxPos = config.getMaxPositionSize(); |
| | | int targetAmount = accumulatedLongLossCount - longSameGridRepeatCount + 1; |
| | | int targetAmount = sameGrid ? Integer.parseInt(config.getQuantity()) : accumulatedLongLossCount + 1; |
| | | int addSize; |
| | | if (maxPos > 0) { |
| | | int remainingRoom = maxPos - posSize; |
| | |
| | | gridElement.removeShortStopLossOrderId(orderId); |
| | | |
| | | int gridId = gridElement.getId(); |
| | | boolean sameGrid = (gridId == lastShortStopLossGridId); |
| | | accumulatedShortLossCount++; |
| | | if (gridId == lastShortStopLossGridId) { |
| | | shortSameGridRepeatCount++; |
| | | } else { |
| | | shortSameGridRepeatCount = 0; |
| | | lastShortStopLossGridId = gridId; |
| | | } |
| | | log.info("[Gate] 空仓止损触发 gridId:{}, 止损次数:{}, 开始追单", gridId, accumulatedShortLossCount); |
| | | lastShortStopLossGridId = gridId; |
| | | log.info("[Gate] 空仓止损触发 gridId:{}, 止损次数:{}{}, 开始追单", |
| | | gridId, accumulatedShortLossCount, sameGrid ? "(同网格)" : ""); |
| | | int newEntryGridId = gridId - 1; |
| | | |
| | | GridElement newEntryGrid = GridElement.findById(newEntryGridId); |
| | |
| | | BigDecimal triggerPrice = newEntryGrid.getGridPrice(); |
| | | int posSize = Math.min(queryPositionSize(Position.ModeEnum.DUAL_SHORT), shortPositionSize.intValue()); |
| | | int maxPos = config.getMaxPositionSize(); |
| | | int targetAmount = accumulatedShortLossCount - shortSameGridRepeatCount + 1; |
| | | int targetAmount = sameGrid ? Integer.parseInt(config.getQuantity()) : accumulatedShortLossCount + 1; |
| | | int addSize; |
| | | if (maxPos > 0) { |
| | | int remainingRoom = maxPos - posSize; |