Administrator
2026-05-19 5c7fa04ebbe54d7bf5050c7f02d3dfadd0fbaf7d
src/main/java/com/xcong/excoin/modules/gateApi/GateWebSocketClientManager.java
@@ -1,8 +1,10 @@
package com.xcong.excoin.modules.gateApi;
import com.xcong.excoin.modules.gateApi.wsHandler.handler.CandlestickChannelHandler;
import com.xcong.excoin.modules.gateApi.wsHandler.handler.OrdersChannelHandler;
import com.xcong.excoin.modules.gateApi.wsHandler.handler.PositionClosesChannelHandler;
import com.xcong.excoin.modules.gateApi.wsHandler.handler.PositionsChannelHandler;
import com.xcong.excoin.modules.gateApi.wsHandler.handler.UserTradesChannelHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -56,16 +58,17 @@
                    .leverage("100")
                    .marginMode("CROSS")
                    .positionMode("dual")
                    .gridRate(new BigDecimal("0.005"))
                    .gridRate(new BigDecimal("0.002"))
                    .overallTp(new BigDecimal("5"))
                    .maxLoss(new BigDecimal("15"))
                    .quantity("1")
                    .priceScale(1)
                    .contractMultiplier(new BigDecimal("0.01"))
                    .unrealizedPnlPriceMode(GateConfig.PnLPriceMode.LAST_PRICE)
                    .isProduction(false)
                    .reopenMaxRetries(3)
                    .build();
//            //实盘
            //实盘
//            config = GateConfig.builder()
//                    .apiKey("865371cdaccd5d238aceb06a55f0143a")
//                    .apiSecret("49589c30dfdc3acba007eed445a94990c4b0aa5faac9843e32defdd7371f5a50")
@@ -73,8 +76,8 @@
//                    .leverage("100")
//                    .marginMode("CROSS")
//                    .positionMode("dual")
//                    .gridRate(new BigDecimal("0.0035"))
//                    .overallTp(new BigDecimal("1"))
//                    .gridRate(new BigDecimal("0.005"))
//                    .overallTp(new BigDecimal("5"))
//                    .maxLoss(new BigDecimal("15"))
//                    .quantity("1")
//                    .contractMultiplier(new BigDecimal("0.01"))
@@ -94,8 +97,12 @@
                    config.getApiKey(), config.getApiSecret(), config.getContract(), gridTradeService));
            wsClient.addChannelHandler(new PositionClosesChannelHandler(
                    config.getApiKey(), config.getApiSecret(), config.getContract(), gridTradeService));
            wsClient.addChannelHandler(new OrdersChannelHandler(
                    config.getApiKey(), config.getApiSecret(), config.getContract(), gridTradeService));
            wsClient.addChannelHandler(new UserTradesChannelHandler(
                    config.getApiKey(), config.getApiSecret(), config.getContract(), gridTradeService));
            wsClient.init();
            log.info("[管理器] WS已连接, 已注册 3 个频道处理器");
            log.info("[管理器] WS已连接, 已注册 5 个频道处理器");
            // 3. 激活策略,等待首根 K 线触发基底双开
            gridTradeService.startGrid();
@@ -119,6 +126,12 @@
        log.info("[管理器] 销毁完成");
    }
    /**
     * @return WebSocket 连接管理器实例
     */
    public GateKlineWebSocketClient getKlineWebSocketClient() { return wsClient; }
    /**
     * @return 网格交易策略服务实例
     */
    public GateGridTradeService getGridTradeService() { return gridTradeService; }
}