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/PositionsChannelHandler.java | 32 ++++++++++++++++----------------
1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionsChannelHandler.java b/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionsChannelHandler.java
index 6584fb9..50cf707 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionsChannelHandler.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionsChannelHandler.java
@@ -10,7 +10,17 @@
/**
* 仓位频道处理器。
- * 私有频道,需认证。解析仓位推送后回调 {@link GateGridTradeService#onPositionUpdate}。
+ *
+ * <h3>数据用途</h3>
+ * 监控仓位数量(size)。当 size 从有变为 0 时,表示该方向被止盈条件单平仓,
+ * 触发补仓(reopenLongPosition / reopenShortPosition)。
+ *
+ * <h3>推送字段</h3>
+ * contract, mode(dual_long / dual_short), size(正=持有,0=无仓位), entry_price
+ *
+ * <h3>注意</h3>
+ * 双向持仓模式下空头 size 为负数,使用 {@code size.abs()} 判断是否有仓位。
+ * 累计盈亏不由本频道计算,而是由 {@link PositionClosesChannelHandler} 独立处理。
*
* @author Administrator
*/
@@ -27,32 +37,22 @@
@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 pos = resultArray.getJSONObject(i);
- if (!getContract().equals(pos.getString("contract"))) {
- continue;
- }
+ if (!getContract().equals(pos.getString("contract"))) continue;
String mode = pos.getString("mode");
BigDecimal size = new BigDecimal(pos.getString("size"));
BigDecimal entryPrice = new BigDecimal(pos.getString("entry_price"));
- log.info("[{}] 推送: contract={}, mode={}, size={}, entry_price={}",
- CHANNEL_NAME, getContract(), mode, size, entryPrice);
+ log.info("[{}] mode:{}, size:{}, entry:{}", CHANNEL_NAME, mode, size, entryPrice);
if (getGridTradeService() != null) {
getGridTradeService().onPositionUpdate(getContract(), mode, size, entryPrice);
}
}
- } catch (Exception e) {
- log.error("[{}] 处理数据失败", CHANNEL_NAME, e);
- }
+ } catch (Exception e) { log.error("[{}] handle fail", CHANNEL_NAME, e); }
return true;
}
}
--
Gitblit v1.9.1