Administrator
1 days ago 5d0e6b7b45630f32100d23ca107a9c74df43db75
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionClosesChannelHandler.java
@@ -14,6 +14,7 @@
 * <h3>数据用途</h3>
 * 每笔平仓发生时推送 pnl(盈亏金额),累加到 {@code cumulativePnl} 用于判断策略停止条件:
 * cumulativePnl ≥ overallTp(达到止盈目标)或 ≤ -maxLoss(超过亏损上限)。
 * 止盈由 Gate 服务端条件单自动触发,平仓后仓位变为 0,盈亏通过本频道推送。
 *
 * <h3>推送字段</h3>
 * contract, side(long / short), pnl(该次平仓的盈亏,如 "+0.2" 或 "-0.1")
@@ -36,21 +37,27 @@
    @Override
    public boolean handleMessage(JSONObject response) {
        if (!CHANNEL_NAME.equals(response.getString("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("[{}] side:{}, pnl:{}", CHANNEL_NAME, side, pnl);
                log.info("[{}] 平仓更新, 方向:{}, 盈亏:{}", CHANNEL_NAME, side, pnl);
                if (getGridTradeService() != null) {
                    getGridTradeService().onPositionClose(getContract(), side, pnl);
                }
            }
        } catch (Exception e) { log.error("[{}] handle fail", CHANNEL_NAME, e); }
        } catch (Exception e) { log.error("[{}] 处理数据失败", CHANNEL_NAME, e); }
        return true;
    }
}