Administrator
4 days ago 01da1f754426a1285fc20b9cf1b80672b16d8814
src/main/java/com/xcong/excoin/modules/gateApi/wsHandler/handler/PositionsChannelHandler.java
@@ -4,6 +4,7 @@
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;
@@ -37,22 +38,29 @@
    @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 pos = resultArray.getJSONObject(i);
                if (!getContract().equals(pos.getString("contract"))) continue;
                String mode = pos.getString("mode");
                if (!getContract().equals(pos.getString("contract"))) {
                    continue;
                }
                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("[{}] mode:{}, size:{}, entry:{}", CHANNEL_NAME, mode, size, entryPrice);
                log.info("[{}] 持仓更新, 模式:{}, 数量:{}, 入场价:{}", CHANNEL_NAME, modeStr, size, entryPrice);
                if (getGridTradeService() != null) {
                    getGridTradeService().onPositionUpdate(getContract(), mode, size, entryPrice);
                }
            }
        } catch (Exception e) { log.error("[{}] handle fail", CHANNEL_NAME, e); }
        } catch (Exception e) { log.error("[{}] 处理数据失败", CHANNEL_NAME, e); }
        return true;
    }
}