Administrator
2025-12-17 8c199e4521b59034a3347aa20fa6404cdffc46fe
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";
@@ -44,7 +51,7 @@
        }
    }
    public static void initEvent(JSONObject response) {
    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 {
@@ -73,7 +80,7 @@
                String instId = detail.getString(INSTID_KEY);
                if (!CoinEnums.HE_YUE.getCode().equals(instId)){
//                    log.info( "订单详情-币种: {} 没有成交订单", CoinEnums.HE_YUE.getCode() );
                    log.info( "订单详情-币种: {} 没有成交订单", CoinEnums.HE_YUE.getCode() );
                    continue;
                }
                String ordId = detail.getString(ORDID_KEY);
@@ -84,31 +91,45 @@
                String avgPx = detail.getString(AVGPX_KEY);
                String state = detail.getString(STATE_KEY);
//                log.info(
//                        "订单详情-币种: {}, 系统编号: {}, 自定义编号: {}, 订单方向: {}, 交易模式: {}," +
//                                " 累计成交数量: {}, 成交均价: {}, 订单状态: {}",
//                        instId, ordId, clOrdId, side, tdMode,
//                        accFillSz, avgPx,state
//                );
                log.info(
                        "{}: 订单详情-币种: {}, 系统编号: {}, 自定义编号: {}, 订单方向: {}, 交易模式: {}," +
                                " 累计成交数量: {}, 成交均价: {}, 订单状态: {}",
                        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);
                    log.info("成交均价: {}", avgPx);
                    WsMapBuild.saveStringToMap(accountMap, "orderPrice",avgPx);
                    WsMapBuild.saveStringToMap(TradeOrderWs.getAccountMap(accountName), "state", CoinEnums.ORDER_LIVE.getCode());
                    //保存上一个网格信息
                    WangGeListEnum gridByPrice = WangGeListEnum.getGridByPrice(new BigDecimal(avgPx));
                    if (gridByPrice != null){
                        log.info("保存上一个网格: {}", gridByPrice.name());
                        Map<String, String> instrumentsMap = InstrumentsWs.getAccountMap(accountName);
                        WsMapBuild.saveStringToMap(instrumentsMap, CoinEnums.WANG_GE_OLD.name(), gridByPrice.name());
                    }
                    WsMapBuild.saveStringToMap(TradeOrderWs.TRADEORDERWSMAP, "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) {