Administrator
2026-06-09 37c567c160546a7ab70ce214ee813d6249adf02b
```
feat(gateApi): 添加网格交易价格驱动挂单状态控制

- 新增 shortEntryActive 和 longEntryActive 变量控制价格驱动挂单位置
- 在策略激活条件中增加挂单状态检查
- 在仓位归零时设置对应挂单状态为活跃
- 更新日志信息显示仓位归零和队列触发的关联关系
- 在挂单成交后将对应挂单状态设置为非活跃
```
1 files modified
20 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 20 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -136,6 +136,11 @@
    /** 多头是否活跃(有仓位) */
    private volatile boolean longActive = false;
    /** 价格驱动 空头是否挂单 */
    private volatile boolean shortEntryActive = false;
    /** 价格驱动 多头是否挂单 */
    private volatile boolean longEntryActive = false;
    private volatile BigDecimal lastKlinePrice;
    private volatile BigDecimal markPrice = BigDecimal.ZERO;
    private volatile BigDecimal cumulativePnl = BigDecimal.ZERO;
@@ -413,14 +418,16 @@
        if (state == StrategyState.ACTIVE &&
                longActive == false &&
                        longPositionSize.compareTo(BigDecimal.ZERO) == 0){
                    longPositionSize.compareTo(BigDecimal.ZERO) == 0 &&
                        longEntryActive){
            processShortGrid(closePrice);
        }
        if (state == StrategyState.ACTIVE &&
                shortActive == false &&
                        shortPositionSize.compareTo(BigDecimal.ZERO) == 0){
                        shortPositionSize.compareTo(BigDecimal.ZERO) == 0 &&
                             shortEntryActive){
            processLongGrid(closePrice);
        }
    }
@@ -478,6 +485,7 @@
//                    log.info("[Gate] 多仓持仓归零,重置策略");
//                    handlePositionZeroAndReset("多仓");
                }
                longEntryActive = true;
                longActive = false;
                longPositionSize = BigDecimal.ZERO;
            }
@@ -501,6 +509,7 @@
//                    log.info("[Gate] 空仓持仓归零,重置策略");
//                    handlePositionZeroAndReset("空仓");
                }
                shortEntryActive = true;
                shortActive = false;
                shortPositionSize = BigDecimal.ZERO;
            }
@@ -1199,7 +1208,7 @@
        if (BigDecimal.ZERO.compareTo( matched) == 0) {
            return;
        }
        log.info("[Gate] 空仓队列触发, 匹配:{},当前价:{}", matched, currentPrice);
        log.info("[Gate] 多仓仓位归零 空仓队列触发, 匹配:{},当前价:{}", matched, currentPrice);
        GridElement matchedUpGridElement = GridElement.findByPrice(matched);
@@ -1218,6 +1227,7 @@
                placeEntryOrderWithPreFlag(newEntryGrid, true, triggerPrice,
                        FuturesPriceTrigger.RuleEnum.NUMBER_1, size);
                longEntryActive = false;
                /**
                 * 看是否有多仓挂单,有就取消
@@ -1247,7 +1257,7 @@
            return;
        }
        log.info("[Gate] 多仓队列触发, 匹配:{},当前价:{}", matched, currentPrice);
        log.info("[Gate] 空仓仓位归零 多仓队列触发, 匹配:{},当前价:{}", matched, currentPrice);
        GridElement matchedUpGridElement = GridElement.findByPrice(matched);
@@ -1266,6 +1276,8 @@
                placeEntryOrderWithPreFlag(newEntryGrid, false, triggerPrice,
                        FuturesPriceTrigger.RuleEnum.NUMBER_2, negate(size));
                shortEntryActive = false;
                /**
                 * 看是否有空仓挂单,有就取消
                 */