From c45bf695a0af9f03f2064f79d502404cf67e416b Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 18 Dec 2025 18:08:01 +0800
Subject: [PATCH] fix(okxWs): 优化订单发送前的就绪状态检查
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/OrderInfoWs.java | 44 +++++++++++++++++++++++++++++---------------
1 files changed, 29 insertions(+), 15 deletions(-)
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 099aa32..92d76f8 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
@@ -5,6 +5,7 @@
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums;
import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.OrderParamEnums;
+import com.xcong.excoin.modules.okxNewPrice.okxWs.wanggeList.WangGeListEnum;
import com.xcong.excoin.modules.okxNewPrice.okxpi.MallUtils;
import com.xcong.excoin.modules.okxNewPrice.utils.WsMapBuild;
import com.xcong.excoin.modules.okxNewPrice.utils.WsParamBuild;
@@ -22,7 +23,13 @@
@Slf4j
public class OrderInfoWs {
- public static final Map<String,String> ORDERINFOWSMAP = new ConcurrentHashMap<>();
+ // 使用双层Map,第一层key为账号名称,第二层key为数据key
+ public static final Map<String, Map<String, String>> ORDERINFOWSMAP = new ConcurrentHashMap<>();
+
+ // 获取指定账号的Map,如果不存在则创建
+ public static Map<String, String> getAccountMap(String accountName) {
+ return ORDERINFOWSMAP.computeIfAbsent(accountName, k -> new ConcurrentHashMap<>());
+ }
public static final String ORDERINFOWS_CHANNEL = "orders";
@@ -38,14 +45,14 @@
String connId = MallUtils.getOrderNum(ORDERINFOWS_CHANNEL);
JSONObject jsonObject = WsParamBuild.buildJsonObject(connId, option, argsArray);
webSocketClient.send(jsonObject.toJSONString());
- log.info("发送订单频道频道:{}", option);
+// log.info("发送订单频道频道:{}", option);
} catch (Exception e) {
log.error("订阅订单频道构建失败", e);
}
}
- public static void initEvent(JSONObject response) {
- log.info("订阅成功: {}", response.getJSONObject("arg"));
+ public static void initEvent(JSONObject response, String accountName) {
+// log.info("订阅成功: {}", response.getJSONObject("arg"));
}
@@ -58,7 +65,7 @@
private static final String ACCFILLSZ_KEY = "accFillSz";
private static final String AVGPX_KEY = "avgPx";
private static final String STATE_KEY = "state";
- public static void handleEvent(JSONObject response, RedisUtils redisUtils) {
+ public static void handleEvent(JSONObject response, RedisUtils redisUtils, String accountName) {
log.info("开始执行OrderInfoWs......");
try {
@@ -85,30 +92,37 @@
String state = detail.getString(STATE_KEY);
log.info(
- "订单详情-币种: {}, 系统编号: {}, 自定义编号: {}, 订单方向: {}, 交易模式: {}," +
+ "{}: 订单详情-币种: {}, 系统编号: {}, 自定义编号: {}, 订单方向: {}, 交易模式: {}," +
" 累计成交数量: {}, 成交均价: {}, 订单状态: {}",
- instId, ordId, clOrdId, side, tdMode,
+ accountName, instId, ordId, clOrdId, side, tdMode,
accFillSz, avgPx,state
);
- String clOrdIdStr = TradeOrderWs.TRADEORDERWSMAP.get("clOrdId");
- String stateStr = TradeOrderWs.TRADEORDERWSMAP.get("state");
+ String clOrdIdStr = TradeOrderWs.getAccountMap(accountName).get("clOrdId");
+ String stateStr = TradeOrderWs.getAccountMap(accountName).get("state");
if (
StrUtil.isNotBlank(clOrdIdStr)
&& clOrdId.equals(clOrdIdStr)
&& StrUtil.isNotBlank(stateStr)
&& state.equals(stateStr)
){
+ Map<String, String> accountMap = getAccountMap(accountName);
//记录成交均价
- if (ORDERINFOWSMAP.get("orderPrice") == null){
- WsMapBuild.saveStringToMap(ORDERINFOWSMAP, "orderPrice",avgPx);
+ if (accountMap.get("orderPrice") == null){
+ log.info("成交均价: {}", avgPx);
+ WsMapBuild.saveStringToMap(accountMap, "orderPrice",avgPx);
}
- WsMapBuild.saveStringToMap(TradeOrderWs.TRADEORDERWSMAP, "state", CoinEnums.ORDER_LIVE.getCode());
+ WsMapBuild.saveStringToMap(TradeOrderWs.getAccountMap(accountName), "state", CoinEnums.ORDER_LIVE.getCode());
- WsMapBuild.saveBigDecimalToMap(PositionsWs.POSITIONSWSMAP, CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_NO.getCode()));
- WsMapBuild.saveStringToMap(AccountWs.ACCOUNTWSMAP, CoinEnums.READY_STATE.name(), CoinEnums.READY_STATE_NO.getCode());
+ // 使用账号特定的Map
+ String positionAccountName = PositionsWs.initAccountName(accountName, side);
+ Map<String, BigDecimal> positionsMap = PositionsWs.getAccountMap(positionAccountName);
+ WsMapBuild.saveBigDecimalToMap(positionsMap, CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_NO.getCode()));
- log.info("订单详情已完成: {}, 自定义编号: {}", CoinEnums.HE_YUE.getCode(), clOrdId);
+ Map<String, String> accountWsMap = AccountWs.getAccountMap(accountName);
+ WsMapBuild.saveStringToMap(accountWsMap, CoinEnums.READY_STATE.name(), CoinEnums.READY_STATE_NO.getCode());
+
+ log.info("{}: 订单详情已完成: {}, 自定义编号: {}", accountName, CoinEnums.HE_YUE.getCode(), clOrdId);
}
}
} catch (Exception e) {
--
Gitblit v1.9.1