Administrator
2026-05-18 e167ed6f9ad83f2caa7aadb0f9dd9ae223cbfcbf
第二个版本
2 files modified
52 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java 19 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GridElement.java 33 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -1,5 +1,6 @@
package com.xcong.excoin.modules.gateApi;
import cn.hutool.core.collection.CollUtil;
import io.gate.gateapi.ApiClient;
import io.gate.gateapi.ApiException;
import io.gate.gateapi.GateApiException;
@@ -432,6 +433,13 @@
                    tryGenerateQueues();
                }else {
                    longPositionSize = size;
                    //取消多仓位线以上的开空仓挂单
                    List<GridElement> allShortOrders = GridElement.findAllShortOrders(longEntryPrice);
                    if (CollUtil.isNotEmpty(allShortOrders)){
                        for (GridElement e : allShortOrders) {
                            executor.cancelOrder(e.getShortOrderId());
                        }
                    }
                }
            } else {
                longActive = false;
@@ -449,6 +457,13 @@
                    tryGenerateQueues();
                }else {
                    shortPositionSize = size.abs();
                    //取消多仓位线以上的开空仓挂单
                    List<GridElement> allLongOrders = GridElement.findAllLongOrders(shortEntryPrice);
                    if (CollUtil.isNotEmpty(allLongOrders)){
                        for (GridElement e : allLongOrders) {
                            executor.cancelOrder(e.getShortOrderId());
                        }
                    }
                }
            } else {
                shortActive = false;
@@ -911,7 +926,7 @@
        List<BigDecimal> matched = new ArrayList<>();
        synchronized (shortPriceQueue) {
            for (BigDecimal p : shortPriceQueue) {
                if (p.compareTo(currentPrice) > 0) {
                if (p.compareTo(currentPrice) >= 0) {
                    matched.add(p);
                } else {
                    break;
@@ -1068,7 +1083,7 @@
        List<BigDecimal> matched = new ArrayList<>();
        synchronized (longPriceQueue) {
            for (BigDecimal p : longPriceQueue) {
                if (p.compareTo(currentPrice) < 0) {
                if (p.compareTo(currentPrice) <= 0) {
                    matched.add(p);
                } else {
                    break;
src/main/java/com/xcong/excoin/modules/gateApi/GridElement.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.modules.gateApi;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -172,6 +173,38 @@
        }
    }
    /**
     * 获取所有已挂多仓条件单的网格元素。
     *      小于空仓仓位线的多单
     *
     * @return 已挂多仓条件单的 GridElement 列表
     */
    public static List<GridElement> findAllLongOrders(BigDecimal currentPrice) {
        List<GridElement> result = new ArrayList<>();
        for (GridElement e : INDEX.values()) {
            if (e.isHasLongOrder() && e.getGridPrice().compareTo(currentPrice) < 0) {
                result.add(e);
            }
        }
        return result;
    }
    /**
     * 获取所有已挂空仓条件单的网格元素。
     *      大于多仓仓位线的空单
     *
     * @return 已挂空仓条件单的 GridElement 列表
     */
    public static List<GridElement> findAllShortOrders(BigDecimal currentPrice) {
        List<GridElement> result = new ArrayList<>();
        for (GridElement e : INDEX.values()) {
            if (e.isHasShortOrder() && e.getGridPrice().compareTo(currentPrice) < 0) {
                result.add(e);
            }
        }
        return result;
    }
    private static void putDynamicIndices(GridElement e) {
        PRICE_INDEX.put(e.getGridPrice(), e);
        if (e.getLongOrderId() != null) {