Administrator
4 days ago 4935aac9c7a42215d15ef14f66a3ea228e4303e2
fix(gateApi): 修复网格交易中的止盈逻辑和数量计算问题

- 注释掉多仓和空仓止盈触发的相关代码逻辑
- 修复向上网格遍历时的数量计算公式,使用配置数量而非固定值1
- 修复向下网格遍历时的数量计算公式,使用配置数量而非固定值1
1 files modified
38 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 38 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -620,23 +620,23 @@
            return;
        }
        // [Gate-需求1] 多仓止盈触发:清空止盈状态 + 取消最近多仓止损
        GridElement longTpElem = GridElement.findByLongTakeProfitOrderId(orderId);
        if (longTpElem != null && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
            longTakeProfitTraderIdParam(longTpElem, null, false);
//            log.info("[Gate] 多仓止盈触发 gridId:{}, orderId:{}", longTpElem.getId(), orderId);
//            cancelNearestLongStopLoss();
            return;
        }
        // [Gate-需求1] 空仓止盈触发:清空止盈状态 + 取消最近空仓止损
        GridElement shortTpElem = GridElement.findByShortTakeProfitOrderId(orderId);
        if (shortTpElem != null && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
            shortTakeProfitTraderIdParam(shortTpElem, null, false);
//            log.info("[Gate] 空仓止盈触发 gridId:{}, orderId:{}", shortTpElem.getId(), orderId);
//            cancelNearestShortStopLoss();
//            checkLastTakeProfitAndRestart();
            return;
        }
//        // [Gate-需求1] 多仓止盈触发:清空止盈状态 + 取消最近多仓止损
//        GridElement longTpElem = GridElement.findByLongTakeProfitOrderId(orderId);
//        if (longTpElem != null && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
//            longTakeProfitTraderIdParam(longTpElem, null, false);
////            log.info("[Gate] 多仓止盈触发 gridId:{}, orderId:{}", longTpElem.getId(), orderId);
////            cancelNearestLongStopLoss();
//            return;
//        }
//        // [Gate-需求1] 空仓止盈触发:清空止盈状态 + 取消最近空仓止损
//        GridElement shortTpElem = GridElement.findByShortTakeProfitOrderId(orderId);
//        if (shortTpElem != null && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
//            shortTakeProfitTraderIdParam(shortTpElem, null, false);
////            log.info("[Gate] 空仓止盈触发 gridId:{}, orderId:{}", shortTpElem.getId(), orderId);
////            cancelNearestShortStopLoss();
////            checkLastTakeProfitAndRestart();
//            return;
//        }
        GridElement longStopLossElem = GridElement.findByLongStopLossOrderId(orderId);
//        if (longStopLossElem != null && longPositionSize.compareTo(BigDecimal.ZERO) > 0 && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
@@ -1255,7 +1255,7 @@
                    if (newEntryGrid != null) {
//                        String quantity = String.valueOf((accumulatedLongLossCount + 1) * Integer.parseInt(config.getQuantity()));
                        String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_SHORT), shortPositionSize.intValue()) + 1);
                        String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_SHORT), shortPositionSize.intValue()) + Integer.parseInt(config.getQuantity()));
                        // 向上遍历取消所有遗留多单(跳过基础入场网格0)
                        GridElement cancelCursor = GridElement.findById(newEntryGrid.getUpId());
                        while (cancelCursor != null) {
@@ -1311,7 +1311,7 @@
                    if (newEntryGrid != null) {
//                        String quantity = String.valueOf((accumulatedShortLossCount + 1) * Integer.parseInt(config.getQuantity()));
                        String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_LONG), longPositionSize.intValue()) + 1);
                        String quantity = String.valueOf(Math.max(queryPositionSize(Position.ModeEnum.DUAL_LONG), longPositionSize.intValue()) + Integer.parseInt(config.getQuantity()));
                        // 向下遍历取消所有遗留空单(跳过基础入场网格0)
                        GridElement cancelCursor = GridElement.findById(newEntryGrid.getDownId());
                        while (cancelCursor != null) {