| | |
| | | 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()) { |
| | |
| | | accFillSz, avgPx,state |
| | | ); |
| | | |
| | | String clOrdIdStr = (String) redisUtils.get(TradeOrderWs.ORDERWS_CHANNEL + ":" + CoinEnums.HE_YUE.getCode() + ":clOrdId"); |
| | | 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(clOrdIdStr) |
| | | && clOrdId.equals(clOrdIdStr) |
| | | && StrUtil.isNotBlank(stateStr) |
| | | && state.equals(stateStr) |
| | | ){ |
| | | boolean setResult = false; |
| | | String outStr = (String) redisUtils.get(InstrumentsWs.INSTRUMENTSWS_CHANNEL + ":" + CoinEnums.HE_YUE.getCode() + ":out"); |
| | | if (OrderParamEnums.OUT_YES.getValue().equals(outStr)){ |
| | | setResult = redisUtils.set(InstrumentsWs.INSTRUMENTSWS_CHANNEL + ":" + CoinEnums.HE_YUE.getCode() + ":state", OrderParamEnums.STATE_3.getValue(), 0); |
| | | }else{ |
| | | setResult = 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); |
| | | } |
| | | if (setResult){ |
| | | log.info("订单详情-币种: {}, 自定义编号: {}, 订单状态: {}", CoinEnums.HE_YUE.getCode(), clOrdId, OrderParamEnums.STATE_0.getValue()); |
| | | } |
| | | 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) { |