| | |
| | | package com.xcong.excoin.modules.gateApi; |
| | | |
| | | import com.xcong.excoin.modules.okxNewPrice.celue.CaoZuoService; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.wanggeList.WangGeListService; |
| | | import com.xcong.excoin.modules.gateApi.wsHandler.handler.CandlestickChannelHandler; |
| | | import com.xcong.excoin.modules.gateApi.wsHandler.handler.PositionClosesChannelHandler; |
| | | import com.xcong.excoin.modules.gateApi.wsHandler.handler.PositionsChannelHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class GateWebSocketClientManager { |
| | | @Autowired |
| | | private CaoZuoService caoZuoService; |
| | | @Autowired |
| | | private WangGeListService wangGeListService; |
| | | |
| | | /** K 线 WebSocket 客户端 */ |
| | | private GateKlineWebSocketClient klinePriceClient; |
| | |
| | | private static final String API_KEY = "d90ca272391992b8e74f8f92cedb21ec"; |
| | | /** Gate 测试网 API Secret */ |
| | | private static final String API_SECRET = "1861e4f52de4bb53369ea3208d9ede38ece4777368030f96c77d27934c46c274"; |
| | | /** 合约 */ |
| | | private static final String CONTRACT = "XAUT_USDT"; |
| | | |
| | | /** |
| | | * Spring 容器启动后自动调用。初始化网格交易服务和 WebSocket 客户端。 |
| | |
| | | try { |
| | | gridTradeService = new GateGridTradeService( |
| | | API_KEY, API_SECRET, |
| | | "XAUT_USDT", |
| | | CONTRACT, |
| | | "30", |
| | | "cross", |
| | | "dual", |
| | | new BigDecimal("0.0035"), |
| | | new BigDecimal("0.5"), |
| | | 3, |
| | | new BigDecimal("7.5"), |
| | | "10" |
| | | ); |
| | | gridTradeService.init(); |
| | | |
| | | klinePriceClient = new GateKlineWebSocketClient(caoZuoService, this, wangGeListService, gridTradeService, API_KEY, API_SECRET); |
| | | klinePriceClient = new GateKlineWebSocketClient(); |
| | | klinePriceClient.addChannelHandler(new CandlestickChannelHandler(CONTRACT, gridTradeService)); |
| | | klinePriceClient.addChannelHandler(new PositionsChannelHandler(API_KEY, API_SECRET, CONTRACT, gridTradeService)); |
| | | klinePriceClient.addChannelHandler(new PositionClosesChannelHandler(API_KEY, API_SECRET, CONTRACT, gridTradeService)); |
| | | klinePriceClient.init(); |
| | | log.info("已初始化GateKlineWebSocketClient"); |
| | | log.info("已初始化GateKlineWebSocketClient及3个频道Handler"); |
| | | |
| | | gridTradeService.startGrid(); |
| | | } catch (Exception e) { |