| | |
| | | log.info("账户通道未就绪,取消发送"); |
| | | return; |
| | | } |
| | | BigDecimal positionsReadyState = PositionsWs.getAccountMap(accountName).get(CoinEnums.READY_STATE.name()) == null |
| | | ? BigDecimal.ZERO : PositionsWs.getAccountMap(accountName).get(CoinEnums.READY_STATE.name()); |
| | | String posSide = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.POSSIDE.name()); |
| | | String positionAccountName = PositionsWs.initAccountName(accountName, posSide); |
| | | BigDecimal positionsReadyState = PositionsWs.getAccountMap(positionAccountName).get(CoinEnums.READY_STATE.name()) == null |
| | | ? BigDecimal.ZERO : PositionsWs.getAccountMap(positionAccountName).get(CoinEnums.READY_STATE.name()); |
| | | if (WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_YES.getCode()).compareTo(positionsReadyState) != 0) { |
| | | log.info("仓位通道未就绪,取消发送"); |
| | | log.info("仓位{}通道未就绪,取消发送",positionAccountName); |
| | | return; |
| | | } |
| | | // 校验必要参数 |
| | |
| | | log.warn("下单参数 side 为空,取消发送"); |
| | | return; |
| | | } |
| | | String buyCnt = ""; |
| | | if (OrderParamEnums.HOLDING.getValue().equals(side)){ |
| | | log.info("当前状态为持仓中,取消发送"); |
| | | return; |
| | | }else if (OrderParamEnums.OUT.getValue().equals(side)){ |
| | | log.info("当前状态为止损"); |
| | | side = OrderParamEnums.SELL.getValue(); |
| | | buyCnt = String.valueOf(PositionsWs.getAccountMap(accountName).get("pos")); |
| | | }else if (OrderParamEnums.INIT.getValue().equals(side)){ |
| | | log.info("当前状态为初始化"); |
| | | side = OrderParamEnums.BUY.getValue(); |
| | | buyCnt = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT.name()); |
| | | }else if (OrderParamEnums.BUY.getValue().equals(side)){ |
| | | log.info("当前状态为加仓"); |
| | | String buyCntTime = getAccountMap(accountName).get("buyCntTime"); |
| | | String buyCntStr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT.name()); |
| | | buyCnt = String.valueOf(new BigDecimal(buyCntTime).multiply(new BigDecimal(buyCntStr))); |
| | | }else if (OrderParamEnums.SELL.getValue().equals(side)){ |
| | | log.info("当前状态为减仓"); |
| | | buyCnt = String.valueOf(PositionsWs.getAccountMap(accountName).get("pos")); |
| | | }else{ |
| | | log.warn("交易状态异常,取消发送"); |
| | | // 校验必要参数 |
| | | if (StrUtil.isBlank(posSide)) { |
| | | log.warn("下单参数 posSide 为空,取消发送"); |
| | | return; |
| | | } |
| | | |
| | | String buyCnt = ""; |
| | | if (CoinEnums.POSSIDE_LONG.getCode().equals(posSide)){ |
| | | if (OrderParamEnums.HOLDING.getValue().equals(side)){ |
| | | log.info("当前状态为持仓中,取消发送"); |
| | | return; |
| | | }else if (OrderParamEnums.OUT.getValue().equals(side)){ |
| | | log.info("当前状态为止损"); |
| | | side = OrderParamEnums.SELL.getValue(); |
| | | buyCnt = String.valueOf(PositionsWs.getAccountMap(positionAccountName).get("pos")); |
| | | }else if (OrderParamEnums.INIT.getValue().equals(side)){ |
| | | log.info("当前状态为初始化"); |
| | | side = OrderParamEnums.BUY.getValue(); |
| | | buyCnt = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT_INIT.name()); |
| | | }else if (OrderParamEnums.BUY.getValue().equals(side)){ |
| | | log.info("当前状态为加仓"); |
| | | String buyCntTime = getAccountMap(accountName).get("buyCntTime"); |
| | | String buyCntStr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT.name()); |
| | | buyCnt = String.valueOf(new BigDecimal(buyCntTime).multiply(new BigDecimal(buyCntStr))); |
| | | }else if (OrderParamEnums.SELL.getValue().equals(side)){ |
| | | log.info("当前状态为减仓"); |
| | | buyCnt = String.valueOf(PositionsWs.getAccountMap(positionAccountName).get("pos")); |
| | | }else{ |
| | | log.warn("交易状态异常,取消发送"); |
| | | return; |
| | | } |
| | | }else if (CoinEnums.POSSIDE_SHORT.getCode().equals(posSide)){ |
| | | if (OrderParamEnums.HOLDING.getValue().equals(side)){ |
| | | log.info("当前状态为持仓中,取消发送"); |
| | | return; |
| | | }else if (OrderParamEnums.OUT.getValue().equals(side)){ |
| | | log.info("当前状态为止损"); |
| | | side = OrderParamEnums.BUY.getValue(); |
| | | buyCnt = String.valueOf(PositionsWs.getAccountMap(positionAccountName).get("pos")); |
| | | }else if (OrderParamEnums.INIT.getValue().equals(side)){ |
| | | log.info("当前状态为初始化"); |
| | | side = OrderParamEnums.SELL.getValue(); |
| | | buyCnt = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT_INIT.name()); |
| | | }else if (OrderParamEnums.BUY.getValue().equals(side)){ |
| | | log.info("当前状态为减仓"); |
| | | buyCnt = String.valueOf(PositionsWs.getAccountMap(positionAccountName).get("pos")); |
| | | }else if (OrderParamEnums.SELL.getValue().equals(side)){ |
| | | log.info("当前状态为加仓"); |
| | | String buyCntTime = getAccountMap(accountName).get("buyCntTime"); |
| | | String buyCntStr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT.name()); |
| | | buyCnt = String.valueOf(new BigDecimal(buyCntTime).multiply(new BigDecimal(buyCntStr))); |
| | | }else{ |
| | | log.warn("交易状态异常,取消发送"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (StrUtil.isBlank(buyCnt)) { |
| | | log.warn("下单数量 buyCnt 为空,取消发送"); |
| | |
| | | args.put("tdMode", CoinEnums.CROSS.getCode()); |
| | | args.put("clOrdId", clOrdId); |
| | | args.put("side", side); |
| | | args.put("posSide", CoinEnums.POSSIDE_LONG.getCode()); |
| | | |
| | | args.put("posSide", posSide); |
| | | args.put("ordType", CoinEnums.ORDTYPE_MARKET.getCode()); |
| | | args.put("sz", buyCnt); |
| | | argsArray.add(args); |
| | |
| | | log.info("发送下单频道:{},数量:{}", side, buyCnt); |
| | | |
| | | WsMapBuild.saveStringToMap(getAccountMap(accountName), "buyCntTime",String.valueOf(BigDecimal.ONE)); |
| | | WsMapBuild.saveStringToMap(getAccountMap(accountName), "clOrdId", clOrdId); |
| | | WsMapBuild.saveStringToMap(getAccountMap(accountName), "state", CoinEnums.ORDER_FILLED.getCode()); |
| | | WsMapBuild.saveStringToMap(getAccountMap(accountName), "clOrdId", clOrdId); |
| | | WsMapBuild.saveStringToMap(getAccountMap(accountName), "state", CoinEnums.ORDER_FILLED.getCode()); |
| | | |
| | | WsMapBuild.saveBigDecimalToMap(PositionsWs.getAccountMap(accountName), CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_NO.getCode())); |
| | | WsMapBuild.saveStringToMap(AccountWs.getAccountMap(accountName), CoinEnums.READY_STATE.name(), CoinEnums.READY_STATE_NO.getCode()); |
| | | WsMapBuild.saveBigDecimalToMap(PositionsWs.getAccountMap(positionAccountName), CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_NO.getCode())); |
| | | WsMapBuild.saveStringToMap(AccountWs.getAccountMap(accountName), CoinEnums.READY_STATE.name(), CoinEnums.READY_STATE_NO.getCode()); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("下单构建失败", e); |