| | |
| | | log.error("WebSocket登录失败, code: {}, msg: {}", code, response.getString("msg")); |
| | | } |
| | | } else if ("subscribe".equals(event)) { |
| | | log.info("订阅成功: {}", response.getJSONObject("arg")); |
| | | subscribeEvent(response); |
| | | } else if ("error".equals(event)) { |
| | | log.error("订阅错误: code={}, msg={}", |
| | | response.getString("code"), response.getString("msg")); |
| | |
| | | } |
| | | } |
| | | |
| | | private void subscribeEvent(JSONObject response) { |
| | | JSONObject arg = response.getJSONObject("arg"); |
| | | if (arg == null) { |
| | | log.warn("无效的推送数据,缺少 'arg' 字段 :{}",response); |
| | | return; |
| | | } |
| | | |
| | | String channel = arg.getString("channel"); |
| | | if (channel == null) { |
| | | log.warn("无效的推送数据,缺少 'channel' 字段{}",response); |
| | | return; |
| | | } |
| | | if (OrderInfoWs.ORDERINFOWS_CHANNEL.equals(channel)) { |
| | | OrderInfoWs.initEvent(response); |
| | | } |
| | | if (AccountWs.ACCOUNTWS_CHANNEL.equals(channel)) { |
| | | AccountWs.initEvent(response); |
| | | } |
| | | if (PositionsWs.POSITIONSWS_CHANNEL.equals(channel)) { |
| | | PositionsWs.initEvent(response); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 解析并处理价格推送数据。 |
| | | * 将最新的标记价格存入 Redis 并触发后续业务逻辑比较处理。 |
| | |
| | | * @param response 包含价格数据的 JSON 对象 |
| | | */ |
| | | private void processPushData(JSONObject response) { |
| | | String op = response.getString("op"); |
| | | if (op != null){ |
| | | if (TradeOrderWs.ORDERWS_CHANNEL.equals(op)) { |
| | | // 直接使用Object类型接收,避免强制类型转换 |
| | | Object data = response.get("data"); |
| | | log.info("收到下单推送结果: {}", JSON.toJSONString(data)); |
| | | return; |
| | | } |
| | | } |
| | | JSONObject arg = response.getJSONObject("arg"); |
| | | if (arg == null) { |
| | | log.warn("无效的推送数据,缺少 'arg' 字段"); |
| | | log.warn("无效的推送数据,缺少 'arg' 字段 :{}",response); |
| | | return; |
| | | } |
| | | |
| | | String channel = arg.getString("channel"); |
| | | if (channel == null) { |
| | | log.warn("无效的推送数据,缺少 'channel' 字段"); |
| | | log.warn("无效的推送数据,缺少 'channel' 字段{}",response); |
| | | return; |
| | | } |
| | | |
| | |
| | | OrderInfoWs.handleEvent(response, redisUtils); |
| | | }else if (AccountWs.ACCOUNTWS_CHANNEL.equals(channel)) { |
| | | AccountWs.handleEvent(response); |
| | | String side = caoZuoService.caoZuo(); |
| | | TradeOrderWs.orderEvent(webSocketClient, side); |
| | | } else if (PositionsWs.POSITIONSWS_CHANNEL.equals(channel)) { |
| | | PositionsWs.handleEvent(response); |
| | | } else if (BalanceAndPositionWs.CHANNEL_NAME.equals(channel)) { |
| | | BalanceAndPositionWs.handleEvent(response); |
| | | } |
| | | String side = caoZuoService.caoZuo(); |
| | | TradeOrderWs.orderEvent(webSocketClient, side); |
| | | } |
| | | |
| | | /** |