src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxKlineWebSocketClient.java
@@ -375,12 +375,6 @@ sz = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT_INIT.name()); tradeRequestParam.setSz(sz); TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParam); BigDecimal pos = PositionsWs.getAccountMap(PositionsWs.initAccountName(accountName, CoinEnums.POSSIDE_SHORT.getCode())).get("pos"); if (BigDecimal.ZERO.compareTo( pos) >= 0) { TradeRequestParam tradeRequestParamOld = caoZuoService.caoZuoZhiSunEvent(accountName, String.valueOf(closePx), CoinEnums.POSSIDE_SHORT.getCode()); TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParamOld); } }else if (posSide == CoinEnums.POSSIDE_SHORT.getCode() && side == CoinEnums.SIDE_SELL.getCode()){ sz = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT_INIT.name()); tradeRequestParam.setSz(sz); src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java
@@ -4,20 +4,18 @@ import com.alibaba.fastjson.JSONObject; import com.xcong.excoin.modules.okxNewPrice.celue.CaoZuoService; import com.xcong.excoin.modules.okxNewPrice.okxWs.*; import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums; import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.ExchangeInfoEnum; import com.xcong.excoin.modules.okxNewPrice.okxWs.param.TradeRequestParam; import com.xcong.excoin.modules.okxNewPrice.utils.SSLConfig; import com.xcong.excoin.modules.okxNewPrice.wangge.WangGeService; import com.xcong.excoin.utils.RedisUtils; import lombok.extern.slf4j.Slf4j; import org.java_websocket.client.WebSocketClient; import org.java_websocket.handshake.ServerHandshake; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.math.BigDecimal; import java.net.URI; import java.net.URISyntaxException; import java.util.concurrent.*; @@ -34,6 +32,7 @@ public class OkxQuantWebSocketClient { private final RedisUtils redisUtils; private final ExchangeInfoEnum account; private final CaoZuoService caoZuoService; private WebSocketClient webSocketClient; private ScheduledExecutorService heartbeatExecutor; @@ -61,8 +60,10 @@ } public OkxQuantWebSocketClient(ExchangeInfoEnum account, CaoZuoService caoZuoService, RedisUtils redisUtils) { this.account = account; this.caoZuoService = caoZuoService; this.redisUtils = redisUtils; } @@ -382,9 +383,9 @@ // 注意:当前实现中,OrderInfoWs等类使用静态Map存储数据 // 这会导致多账号之间的数据冲突。需要进一步修改这些类的设计,让数据存储与特定账号关联 if (OrderInfoWs.ORDERINFOWS_CHANNEL.equals(channel)) { OrderInfoWs.handleEvent(response, redisUtils, account.name()); // TradeRequestParam tradeRequestParam = OrderInfoWs.handleEvent(response, redisUtils, account.name()); // TradeOrderWs.orderZhiYingEvent(webSocketClient, tradeRequestParam); TradeRequestParam tradeRequestParam = OrderInfoWs.handleEvent(response, redisUtils, account.name()); tradeRequestParam = caoZuoService.caoZuoZhiSunEvent(account.name(), tradeRequestParam.getMarkPx(), tradeRequestParam.getPosSide()); TradeOrderWs.orderZhiYingZhiSunEventNoState(webSocketClient, tradeRequestParam); }else if (AccountWs.ACCOUNTWS_CHANNEL.equals(channel)) { AccountWs.handleEvent(response, account.name()); } else if (PositionsWs.POSITIONSWS_CHANNEL.equals(channel)) { src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
@@ -58,7 +58,7 @@ // 为每个账号创建一个WebSocket客户端实例 for (ExchangeInfoEnum account : accounts) { try { OkxQuantWebSocketClient client = new OkxQuantWebSocketClient(account, redisUtils); OkxQuantWebSocketClient client = new OkxQuantWebSocketClient(account, caoZuoService, redisUtils); quantClientMap.put(account.name(), client); client.init(); log.info("已初始化账号 {} 的WebSocket客户端", account.name()); src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/OrderInfoWs.java
@@ -116,6 +116,13 @@ log.info("{}: 订单详情已完成: {}, 自定义编号: {}", accountName, CoinEnums.HE_YUE.getCode(), clOrdId); TradeRequestParam tradeRequestParam = new TradeRequestParam(); tradeRequestParam.setAccountName(accountName); tradeRequestParam.setMarkPx(String.valueOf(avgPx)); String fanfangxiangPosside = CoinEnums.POSSIDE_LONG.getCode().equals(posSide) ? CoinEnums.POSSIDE_SHORT.getCode() : CoinEnums.POSSIDE_LONG.getCode(); tradeRequestParam.setPosSide(fanfangxiangPosside); return tradeRequestParam; } return null; } src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/TradeOrderWs.java
@@ -126,7 +126,7 @@ } } public static void orderZhiYingEvent(WebSocketClient webSocketClient, TradeRequestParam tradeRequestParam) { public static void orderZhiYingZhiSunEventNoState(WebSocketClient webSocketClient, TradeRequestParam tradeRequestParam) { log.info("开始执行TradeOrderWs......");