Administrator
2026-05-22 67939acc2d20ea34618013898154d9ff3fe37a74
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -342,6 +342,16 @@
        lastKlinePrice = closePrice;
        updateUnrealizedPnl();
        if (state == StrategyState.STOPPED) {
            try {
                futuresApi.cancelPriceTriggeredOrderList(SETTLE, config.getContract());
            } catch (ApiException e) {
                e.printStackTrace();
            }
            closeExistingPositions();
            BigDecimal totalPnl = cumulativePnl.add(unrealizedPnl);
            log.info("[Gate] 已实现:{}, 未实现:{}, 合计:{}",
                    cumulativePnl, unrealizedPnl, totalPnl);
            return;
        }
@@ -517,13 +527,17 @@
            return;
        }
        cumulativePnl = cumulativePnl.add(pnl);
        log.info("[Gate] 盈亏累加:{}, 方向:{}, 累计:{}", pnl, side, cumulativePnl);
        BigDecimal totalPnl = cumulativePnl.add(unrealizedPnl);
        log.info("[Gate] 已实现:{}, 未实现:{}, 合计:{}",
                cumulativePnl, unrealizedPnl, totalPnl);
        if (cumulativePnl.compareTo(config.getOverallTp()) >= 0) {
            log.info("[Gate] 已达止盈目标 {}→已停止", cumulativePnl);
        if (totalPnl.compareTo(config.getOverallTp()) >= 0) {
            log.info("[Gate] 已达止盈目标(合计{})→已停止, 已实现:{}, 未实现:{}",
                    totalPnl, cumulativePnl, unrealizedPnl);
            state = StrategyState.STOPPED;
        } else if (cumulativePnl.compareTo(config.getMaxLoss().negate()) <= 0) {
            log.info("[Gate] 已达亏损上限 {}→已停止", cumulativePnl);
        } else if (totalPnl.compareTo(config.getMaxLoss().negate()) <= 0) {
            log.info("[Gate] 已达亏损上限(合计{})→已停止, 已实现:{}, 未实现:{}",
                    totalPnl, cumulativePnl, unrealizedPnl);
            state = StrategyState.STOPPED;
        }
    }
@@ -557,11 +571,11 @@
                    null,
                    false
            );
            longEntryTraderIdParam(
                    byLongTakeProfitOrderId,
                    null,
                    false
            );
//            longEntryTraderIdParam(
//                    byLongTakeProfitOrderId,
//                    null,
//                    false
//            );
        }
        GridElement byShortTakeProfitOrderId = GridElement.findByShortTakeProfitOrderId(orderId);
        if (byShortTakeProfitOrderId != null){
@@ -570,11 +584,11 @@
                    null,
                    false
            );
            shortEntryTraderIdParam(
                    byShortTakeProfitOrderId,
                    null,
                    false
            );
//            shortEntryTraderIdParam(
//                    byShortTakeProfitOrderId,
//                    null,
//                    false
//            );
        }
        /**
@@ -583,6 +597,11 @@
        GridElement longGridElement = GridElement.findByLongOrderId(orderId);
        if (longGridElement != null) {
            if (longGridElement.isHasLongOrder()){
                longEntryTraderIdParam(
                        longGridElement,
                        null,
                        false
                );
                if (longGridElement.getLongTakeProfitOrderId() == null){
                    BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice();
                    if (longTp != null) {
@@ -606,6 +625,11 @@
        GridElement shortGridElement = GridElement.findByShortOrderId(orderId);
        if (shortGridElement != null) {
            if (shortGridElement.isHasShortOrder()){
                shortEntryTraderIdParam(
                        shortGridElement,
                        null,
                        false
                );
                if (shortGridElement.getShortTakeProfitOrderId() == null){
                    BigDecimal shortTp = shortGridElement.getShortTraderParam().getTakeProfitPrice();
                    if (shortTp != null) {
@@ -1104,7 +1128,7 @@
            // 判断网格是否能开空仓,如果不能则跳过
            if (UpGridElement != null) {
                if (!UpGridElement.isHasShortOrder()) {
                if (!UpGridElement.isHasShortOrder() && shortEntryPrice.compareTo(newLongFirst) > 0) {
                    //挂空仓条件单
                    TraderParam upShortTraderParam = UpGridElement.getShortTraderParam();
@@ -1241,7 +1265,7 @@
            // 判断网格是否能开多仓,如果不能则跳过
            if (UpGridElement != null) {
                if (!UpGridElement.isHasLongOrder()) {
                if (!UpGridElement.isHasLongOrder() && longEntryPrice.compareTo(newLongFirst) < 0) {
                    //挂多仓条件单
                    TraderParam upLongTraderParam = UpGridElement.getLongTraderParam();
                    executor.placeConditionalEntryOrder(