From bfe3af2d95418b326d707834be6c6ba91f86ecb5 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Fri, 08 May 2026 13:20:58 +0800
Subject: [PATCH] refactor(gateApi): 重构 Gate API 模块代码结构

---
 src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionClosesChannelHandler.java |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionClosesChannelHandler.java b/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionClosesChannelHandler.java
index deefcdb..78f6c14 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionClosesChannelHandler.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionClosesChannelHandler.java
@@ -10,7 +10,16 @@
 
 /**
  * 平仓频道处理器。
- * 私有频道,需认证。解析平仓推送后回调 {@link GateGridTradeService#onPositionClose}。
+ *
+ * <h3>数据用途</h3>
+ * 每笔平仓发生时推送 pnl(盈亏金额),累加到 {@code cumulativePnl} 用于判断策略停止条件:
+ * cumulativePnl ≥ overallTp(达到止盈目标)或 ≤ -maxLoss(超过亏损上限)。
+ *
+ * <h3>推送字段</h3>
+ * contract, side(long / short), pnl(该次平仓的盈亏,如 "+0.2" 或 "-0.1")
+ *
+ * <h3>注意</h3>
+ * 平仓盈亏来自服务器端,不受本地计算误差影响。这是策略停止的唯一盈亏判断来源。
  *
  * @author Administrator
  */
@@ -27,31 +36,21 @@
 
     @Override
     public boolean handleMessage(JSONObject response) {
-        String channel = response.getString("channel");
-        if (!CHANNEL_NAME.equals(channel)) {
-            return false;
-        }
+        if (!CHANNEL_NAME.equals(response.getString("channel"))) return false;
         try {
             JSONArray resultArray = response.getJSONArray("result");
-            if (resultArray == null || resultArray.isEmpty()) {
-                return true;
-            }
+            if (resultArray == null || resultArray.isEmpty()) return true;
             for (int i = 0; i < resultArray.size(); i++) {
                 JSONObject item = resultArray.getJSONObject(i);
-                if (!getContract().equals(item.getString("contract"))) {
-                    continue;
-                }
+                if (!getContract().equals(item.getString("contract"))) continue;
                 BigDecimal pnl = new BigDecimal(item.getString("pnl"));
                 String side = item.getString("side");
-                log.info("[{}] 推送: contract={}, side={}, pnl={}",
-                        CHANNEL_NAME, getContract(), side, pnl);
+                log.info("[{}] side:{}, pnl:{}", CHANNEL_NAME, side, pnl);
                 if (getGridTradeService() != null) {
                     getGridTradeService().onPositionClose(getContract(), side, pnl);
                 }
             }
-        } catch (Exception e) {
-            log.error("[{}] 处理数据失败", CHANNEL_NAME, e);
-        }
+        } catch (Exception e) { log.error("[{}] handle fail", CHANNEL_NAME, e); }
         return true;
     }
 }

--
Gitblit v1.9.1