From ef00aeb456a54c7a98b71617fb7e46e56d02aa78 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 29 Dec 2025 10:07:58 +0800
Subject: [PATCH] refactor(okxNewPrice): 重构止损订单处理逻辑
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java | 2 +-
src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java | 15 ++++++++-------
src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxKlineWebSocketClient.java | 6 ------
src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/OrderInfoWs.java | 7 +++++++
src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/TradeOrderWs.java | 2 +-
5 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxKlineWebSocketClient.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxKlineWebSocketClient.java
index cb3a4bb..c089ac6 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxKlineWebSocketClient.java
+++ b/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);
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java
index 22a0a0e..4968898 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxQuantWebSocketClient.java
+++ b/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)) {
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
index 4f23fb8..c00f893 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
+++ b/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());
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/OrderInfoWs.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/OrderInfoWs.java
index f03c6af..8f37385 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/OrderInfoWs.java
+++ b/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;
}
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/TradeOrderWs.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/TradeOrderWs.java
index 93ed017..a96690e 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/TradeOrderWs.java
+++ b/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......");
--
Gitblit v1.9.1