From 7e456badb43245198687381714657b9585eb6c19 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Sat, 09 May 2026 15:03:08 +0800
Subject: [PATCH] fix(gateApi): 修复多队列日志打印错误
---
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionsChannelHandler.java | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 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..e16ac35 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
@@ -4,13 +4,26 @@
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.gateApi.GateGridTradeService;
import com.xcong.excoin.modules.gateApi.wsHandler.AbstractPrivateChannelHandler;
+import io.gate.gateapi.models.Position;
import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
/**
* 仓位频道处理器。
- * 私有频道,需认证。解析仓位推送后回调 {@link GateGridTradeService#onPositionUpdate}。
+ *
+ * <h3>数据用途</h3>
+ * 监控仓位数量(size)和入场价(entry_price)。
+ * 有仓位时(size.abs > 0):标记方向活跃,记录入场价 → 基底首次成交记录基底入场价并等待生成网格队列,
+ * 非基底成交立即设止盈条件单。无仓位时(size=0):标记方向不活跃。
+ *
+ * <h3>推送字段</h3>
+ * contract, mode(dual_long / dual_short), size(正=多头,负=空头),entry_price
+ *
+ * <h3>注意</h3>
+ * 双向持仓模式下空头 size 为负数,使用 {@code size.abs()} 判断是否有仓位。
+ * 累计盈亏不由本频道计算,而是由 {@link PositionClosesChannelHandler} 独立处理。
+ * 止盈条件单由服务端自动触发平仓,本频道不负责开仓操作。
*
* @author Administrator
*/
@@ -27,8 +40,7 @@
@Override
public boolean handleMessage(JSONObject response) {
- String channel = response.getString("channel");
- if (!CHANNEL_NAME.equals(channel)) {
+ if (!CHANNEL_NAME.equals(response.getString("channel"))) {
return false;
}
try {
@@ -41,18 +53,16 @@
if (!getContract().equals(pos.getString("contract"))) {
continue;
}
- String mode = pos.getString("mode");
+ String modeStr = pos.getString("mode");
+ Position.ModeEnum mode = Position.ModeEnum.fromValue(modeStr);
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("[{}] 持仓更新, 模式:{}, 数量:{}, 入场价:{}", CHANNEL_NAME, modeStr, size, entryPrice);
if (getGridTradeService() != null) {
getGridTradeService().onPositionUpdate(getContract(), mode, size, entryPrice);
}
}
- } catch (Exception e) {
- log.error("[{}] 处理数据失败", CHANNEL_NAME, e);
- }
+ } catch (Exception e) { log.error("[{}] 处理数据失败", CHANNEL_NAME, e); }
return true;
}
}
--
Gitblit v1.9.1