Administrator
2026-05-19 1a85d48f6e70a4091c2a2f8c1b802001918956b8
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;
@@ -153,6 +154,7 @@
            INDEX.put(e.getId(), e);
            putDynamicIndices(e);
        }
        logAll();
    }
    /**
@@ -170,6 +172,67 @@
        for (GridElement e : INDEX.values()) {
            putDynamicIndices(e);
        }
        logAll();
    }
    /**
     * 打印全部网格数据到日志。
     */
    public static void logAll() {
        List<GridElement> sorted = new ArrayList<>(INDEX.values());
        sorted.sort((a, b) -> Integer.compare(a.getId(), b.getId()));
        StringBuilder sb = new StringBuilder("\n========== 网格数据 ==========\n");
        for (GridElement e : sorted) {
            if (e.isHasLongOrder()){
                sb.append(String.format(
                        "  ID=%4d  价格=%s  up=%s  down=%s  多仓=%s(%s)  空仓=%s(%s)  多止盈=%s  空止盈=%s\n",
                        e.getId(),
                        e.getGridPrice(),
                        e.getUpId(),
                        e.getDownId(),
                        e.isHasLongOrder() ? "有" : "无",
                        e.getLongOrderId() != null ? e.getLongOrderId() : "-",
                        e.isHasShortOrder() ? "有" : "无",
                        e.getShortOrderId() != null ? e.getShortOrderId() : "-",
                        e.getLongTakeProfitOrderId() != null ? e.getLongTakeProfitOrderId() : "-",
                        e.getShortTakeProfitOrderId() != null ? e.getShortTakeProfitOrderId() : "-"
                ));
            }
        }
        sb.append("================================\n");
        System.out.println(sb);
    }
    /**
     * 获取所有已挂多仓条件单的网格元素。
     *      小于空仓仓位线的多单
     *
     * @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) {