From 9bd318567e2ba1350b47a42dc9b292a1eb0b9757 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 18 May 2026 21:14:18 +0800
Subject: [PATCH] 第二个版本

---
 src/main/java/com/xcong/excoin/modules/gateApi/GridElement.java |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GridElement.java b/src/main/java/com/xcong/excoin/modules/gateApi/GridElement.java
index e34f80c..2c4ed41 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GridElement.java
+++ b/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,65 @@
         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) {
+            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) {

--
Gitblit v1.9.1