| | |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.OrderParamEnums; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxpi.MallUtils; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.WsMapBuild; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.WsParamBuild; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.java_websocket.client.WebSocketClient; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | */ |
| | | @Slf4j |
| | | public class OrderInfoWs { |
| | | |
| | | public static final Map<String,String> ORDERINFOWSMAP = new ConcurrentHashMap<>(); |
| | | |
| | | public static final String ORDERINFOWS_CHANNEL = "orders"; |
| | | |
| | |
| | | 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")); |
| | | } |
| | | |
| | | |
| | |
| | | private static final String STATE_KEY = "state"; |
| | | public static void handleEvent(JSONObject response, RedisUtils redisUtils) { |
| | | |
| | | log.info("开始执行OrderInfoWs......"); |
| | | // log.info("开始执行OrderInfoWs......"); |
| | | try { |
| | | JSONArray dataArray = response.getJSONArray(DATA_KEY); |
| | | if (dataArray == null || dataArray.isEmpty()) { |
| | |
| | | |
| | | 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); |
| | |
| | | String avgPx = detail.getString(AVGPX_KEY); |
| | | String state = detail.getString(STATE_KEY); |
| | | |
| | | log.info( |
| | | "订单详情-币种: {}, 系统编号: {}, 自定义编号: {}, 订单方向: {}, 交易模式: {}," + |
| | | " 累计成交数量: {}, 成交均价: {}, 订单状态: {}", |
| | | instId, ordId, clOrdId, side, tdMode, |
| | | accFillSz, avgPx,state |
| | | ); |
| | | // log.info( |
| | | // "订单详情-币种: {}, 系统编号: {}, 自定义编号: {}, 订单方向: {}, 交易模式: {}," + |
| | | // " 累计成交数量: {}, 成交均价: {}, 订单状态: {}", |
| | | // instId, ordId, clOrdId, side, tdMode, |
| | | // accFillSz, avgPx,state |
| | | // ); |
| | | |
| | | String stateStr = (String) redisUtils.get(TradeOrderWs.ORDERWS_CHANNEL + ":" + CoinEnums.HE_YUE.getCode() + ":state"); |
| | | String clOrdIdStr = TradeOrderWs.TRADEORDERWSMAP.get("clOrdId"); |
| | | String stateStr = TradeOrderWs.TRADEORDERWSMAP.get("state"); |
| | | if ( |
| | | StrUtil.isNotBlank(stateStr) |
| | | StrUtil.isNotBlank(clOrdIdStr) |
| | | && clOrdId.equals(clOrdIdStr) |
| | | && StrUtil.isNotBlank(stateStr) |
| | | && state.equals(stateStr) |
| | | ){ |
| | | redisUtils.set(InstrumentsWs.INSTRUMENTSWS_CHANNEL + ":" + CoinEnums.HE_YUE.getCode() + ":state", OrderParamEnums.STATE_0.getValue(), 0); |
| | | //记录成交均价 |
| | | if (ORDERINFOWSMAP.get("orderPrice") == null){ |
| | | WsMapBuild.saveStringToMap(ORDERINFOWSMAP, "orderPrice",avgPx); |
| | | } |
| | | 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()); |
| | | |
| | | // log.info("订单详情已完成: {}, 自定义编号: {}", CoinEnums.HE_YUE.getCode(), clOrdId); |
| | | } |
| | | } |
| | | } catch (Exception e) { |