Administrator
2026-06-10 c0d48978e8dceeb15c5dedc5109b36a9a064d038
refactor(gateApi): 优化网格交易服务中的止损和仓位管理逻辑

- 移除长仓和短仓止损触发条件中的持仓数量判断
- 在仓位归零时增加对订单状态的检查以避免重复下单
- 重构网格元素查找逻辑以提高代码可读性
- 统一订单取消逻辑的处理流程
- 优化日志记录以提供更准确的执行状态信息
1 files modified
10 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 10 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -543,12 +543,14 @@
        }
        GridElement longStopLossElem = GridElement.findByLongStopLossOrderId(orderId);
        if (longStopLossElem != null && longPositionSize.compareTo(BigDecimal.ZERO) > 0 && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
//        if (longStopLossElem != null && longPositionSize.compareTo(BigDecimal.ZERO) > 0 && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
        if (longStopLossElem != null && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
            handleLongStopLossTriggered(longStopLossElem);
            return;
        }
        GridElement shortStopLossElem = GridElement.findByShortStopLossOrderId(orderId);
        if (shortStopLossElem != null && shortPositionSize.compareTo(BigDecimal.ZERO) > 0 && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
//        if (shortStopLossElem != null && shortPositionSize.compareTo(BigDecimal.ZERO) > 0 && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
        if (shortStopLossElem != null && StrUtil.isNotEmpty(tradeId) && !tradeId.equals("0")) {
            handleShortStopLossTriggered(shortStopLossElem);
            return;
        }
@@ -856,6 +858,7 @@
            GridElement matchedUpGridElement = GridElement.findByPrice(matched);
            if (matchedUpGridElement != null){
                if (!matchedUpGridElement.isHasLongOrder()){
                Integer upId = matchedUpGridElement.getUpId();
                GridElement newEntryGrid = GridElement.findById(upId);
@@ -881,6 +884,7 @@
                }
            }
        }
        }
    }
@@ -902,6 +906,7 @@
            GridElement matchedUpGridElement = GridElement.findByPrice(matched);
            if (matchedUpGridElement != null){
                if(!matchedUpGridElement.isHasShortOrder()){
                Integer downId = matchedUpGridElement.getDownId();
                GridElement newEntryGrid = GridElement.findById(downId);
@@ -932,6 +937,7 @@
            }
        }
    }
    }
    private void handleLongStopLossTriggered(GridElement gridElement) {
        gridElement.setLongStopLossOrderId(null);