modify entrsut open order when more/less/bomb/entrustClose
 
	
	
	
	
	
	
	
	
	
	
	
	
	
 |  |  | 
 |  |  |      */ | 
 |  |  |     public static final String RABBIT_TYPE = "rabbit_type_"; | 
 |  |  |  | 
 |  |  |     public static final String MEMBER_TYPE = "member_type_"; | 
 |  |  |  | 
 |  |  | } | 
 
 |  |  | 
 |  |  |  | 
 |  |  |             // 发送委托单队列消息 | 
 |  |  |             if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol()); | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |  | 
 |  |  |                 LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买涨", "买涨:" + submitEntrustDto.getSymbol()); | 
 |  |  |             } else { | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol()); | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |  | 
 |  |  |                 LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买跌", "买跌:" + submitEntrustDto.getSymbol()); | 
 |  |  | 
 |  |  |  | 
 |  |  |             // 发送委托单队列消息 | 
 |  |  |             if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol()); | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |  | 
 |  |  |                 LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买涨", "买涨:" + submitEntrustDto.getSymbol()); | 
 |  |  |             } else { | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol()); | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol(), entrustOrderEntity.getMemberId()); | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |  | 
 |  |  |                 LogRecordUtils.insertMemberAccountFlow(memberEntity.getId(), entrustTotalAmount, walletContract.getAvailableBalance().subtract(entrustTotalAmount), submitEntrustDto.getSymbol(), "委托买跌", "买跌:" + submitEntrustDto.getSymbol()); | 
 |  |  | 
 |  |  |         if (i > 0) { | 
 |  |  |             // 发送委托消息 | 
 |  |  |             if (holdOrderEntity.getOpeningType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrder.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_MORE.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrder.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_MORE.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol(), holdOrderEntity.getMemberId()); | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |             } else { | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrder.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_LESS.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                 OrderModel model = new OrderModel(entrustOrder.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_LESS.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol(), holdOrderEntity.getMemberId()); | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |             } | 
 |  |  |         } | 
 
 |  |  | 
 |  |  |             memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId()); | 
 |  |  |  | 
 |  |  |             // 发送爆仓消息 | 
 |  |  |             sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); | 
 |  |  |             sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId()); | 
 |  |  |  | 
 |  |  |             // 计算佣金 | 
 |  |  |             ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); | 
 |  |  | 
 |  |  |         contractHoldOrderDao.updateById(holdOrderEntity); | 
 |  |  |  | 
 |  |  |         // 将待平张数放入缓存 | 
 |  |  |         redisUtils.set(AppContants.CLOSING_ORDER_PREFIX + holdOrderEntity.getId(), wholeCloseOrderDto.getCount()); | 
 |  |  |         redisUtils.set(AppContants.CLOSING_ORDER_PREFIX + holdOrderEntity.getId(), wholeCloseOrderDto.getCount(), 30); | 
 |  |  |  | 
 |  |  |         // 发送平仓消息 | 
 |  |  |         List<Long> ids = new ArrayList<>(); | 
 |  |  | 
 |  |  |             if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { | 
 |  |  |                 // 开多止盈 | 
 |  |  |                 if (stopProfitPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol(), holdOrderEntity.getMemberId()); | 
 |  |  |                     producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                 } | 
 |  |  |                 // 开多止损 | 
 |  |  |                 if (stopLessPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol(), holdOrderEntity.getMemberId()); | 
 |  |  |                     producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 // 开空止盈 | 
 |  |  |                 if (stopProfitPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol(), holdOrderEntity.getMemberId()); | 
 |  |  |                     producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                 } | 
 |  |  |                 // 开空止损 | 
 |  |  |                 if (stopLessPrice != null) { | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); | 
 |  |  |                     model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol(), holdOrderEntity.getMemberId()); | 
 |  |  |                     producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  | 
 |  |  |  | 
 |  |  |         if (i > 0) { | 
 |  |  |             // 发送爆仓消息 | 
 |  |  |             sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); | 
 |  |  |             sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId()); | 
 |  |  |             return Result.ok("调整成功"); | 
 |  |  |         } | 
 |  |  |         return Result.fail("调整失败"); | 
 |  |  | 
 |  |  |                     contractHoldOrderDao.updateById(holdOrderEntity); | 
 |  |  |  | 
 |  |  |                     // 发送爆仓消息 | 
 |  |  |                     sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), newForcePrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); | 
 |  |  |                     sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), newForcePrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId()); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo) { | 
 |  |  |     public void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo, Long memberId) { | 
 |  |  |         OrderModel model = null; | 
 |  |  |         // 开多 | 
 |  |  |         if (ContractHoldOrderEntity.OPENING_TYPE_MORE == type) { | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo); | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo, memberId); | 
 |  |  |             // 开空 | 
 |  |  |         } else { | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo); | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo, memberId); | 
 |  |  |         } | 
 |  |  |         producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |     } | 
 
 |  |  | 
 |  |  |                 // 市价 | 
 |  |  |                 if (coinsCoinsOrder.getEntrustType() == 1) { | 
 |  |  |                     // 开多 | 
 |  |  |                     OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 6, contractHoldOrderEntity.getForceClosingPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), coinsCoinsOrder.getSymbol(), 1); | 
 |  |  |                     OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 6, contractHoldOrderEntity.getForceClosingPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), coinsCoinsOrder.getSymbol(), 1, coinsCoinsOrder.getMemberId()); | 
 |  |  |                     producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                 } else { | 
 |  |  |                     // 开空 | 
 |  |  |                     OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 7, contractHoldOrderEntity.getForceClosingPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), coinsCoinsOrder.getSymbol(), 1); | 
 |  |  |                     OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 7, contractHoldOrderEntity.getForceClosingPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), coinsCoinsOrder.getSymbol(), 1, coinsCoinsOrder.getMemberId()); | 
 |  |  |                     producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                 } | 
 |  |  |                 // 扣除手续费 | 
 |  |  | 
 |  |  |  | 
 |  |  |     private void wholeEntrustOrder(ContractEntrustOrderEntity entrustOrder) { | 
 |  |  |         log.info("全仓委托逻辑处理:{}", entrustOrder.getOrderNo()); | 
 |  |  |  | 
 |  |  |         List<Object> types = redisUtils.lGet(AppContants.MEMBER_TYPE + entrustOrder.getMemberId(), 0, -1); | 
 |  |  |         int i = 1; | 
 |  |  |         while (true) { | 
 |  |  |             if (CollUtil.isEmpty(types)) { | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |             log.info("存在止盈/止损/爆仓/委托平仓,等待 -- {}", i); | 
 |  |  |             try { | 
 |  |  |                 Thread.sleep(1000); | 
 |  |  |             } catch (InterruptedException e) { | 
 |  |  |                 e.printStackTrace(); | 
 |  |  |             } | 
 |  |  |             i++; | 
 |  |  |         } | 
 |  |  |         MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(entrustOrder.getMemberId(), CoinTypeConvert.convertContractTypeToCoin(entrustOrder.getSymbol())); | 
 |  |  |  | 
 |  |  |         PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); | 
 
 |  |  | 
 |  |  |                     followFollowerOrderRelationDao.insert(relationEntity); | 
 |  |  |  | 
 |  |  |                     // 发送爆仓消息 | 
 |  |  |                     sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo()); | 
 |  |  |                     sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId()); | 
 |  |  |  | 
 |  |  |                     // 计算佣金 | 
 |  |  |                     ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo) { | 
 |  |  |     public void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo, Long memberId) { | 
 |  |  |         OrderModel model = null; | 
 |  |  |         // 开多 | 
 |  |  |         if (ContractHoldOrderEntity.OPENING_TYPE_MORE == type) { | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo); | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo, memberId); | 
 |  |  |             // 开空 | 
 |  |  |         } else { | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo); | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo, memberId); | 
 |  |  |         } | 
 |  |  |         producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |     } | 
 
 |  |  | 
 |  |  |                         if (forceSetPrice != null) { | 
 |  |  |                             if (forceSetPrice.compareTo(BigDecimal.ZERO) >= 0) { | 
 |  |  |                                 OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceSetPrice.toPlainString(), | 
 |  |  |                                         order.getSymbol(), order.getOperateNo()); | 
 |  |  |                                         order.getSymbol(), order.getOperateNo(), order.getMemberId()); | 
 |  |  |                                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  | 
 |  |  |                     if (stopLossPrice != null && stopLossPrice.compareTo(BigDecimal.ZERO) > 0) { | 
 |  |  |                         OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), | 
 |  |  |                                 stopLossPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                                 order.getSymbol()); | 
 |  |  |                                 order.getSymbol(), order.getMemberId()); | 
 |  |  |                         producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                     } | 
 |  |  |                     // 止盈 | 
 |  |  | 
 |  |  |                     if (stopProfitPrice != null && stopProfitPrice.compareTo(BigDecimal.ZERO) > 0) { | 
 |  |  |                         OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), | 
 |  |  |                                 stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                                 order.getSymbol()); | 
 |  |  |                                 order.getSymbol(), order.getMemberId()); | 
 |  |  |                         producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                         if (forceSetPrice != null) { | 
 |  |  |                             if (forceSetPrice.compareTo(BigDecimal.ZERO) >= 0) { | 
 |  |  |                                 OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceSetPrice.toPlainString(), | 
 |  |  |                                         order.getSymbol(), order.getOperateNo()); | 
 |  |  |                                         order.getSymbol(), order.getOperateNo(), order.getMemberId()); | 
 |  |  |                                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  | 
 |  |  |                     if (stopLossPrice != null && stopLossPrice.compareTo(BigDecimal.ZERO) > 0) { | 
 |  |  |                         OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), | 
 |  |  |                                 stopLossPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                                 order.getSymbol()); | 
 |  |  |                                 order.getSymbol(), order.getMemberId()); | 
 |  |  |                         producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                     } | 
 |  |  |                     // 止盈 | 
 |  |  | 
 |  |  |                     if (stopProfitPrice != null && stopProfitPrice.compareTo(BigDecimal.ZERO) > 0) { | 
 |  |  |                         OrderModel model = new OrderModel(order.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), | 
 |  |  |                                 stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                                 order.getSymbol()); | 
 |  |  |                                 order.getSymbol(), order.getMemberId()); | 
 |  |  |                         producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                     // 开多委托 | 
 |  |  |                     model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), | 
 |  |  |                             entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                             order.getSymbol()); | 
 |  |  |                             order.getSymbol(), order.getMemberId()); | 
 |  |  |  | 
 |  |  |                 } else if (ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_LESS == entrustType){ | 
 |  |  |                     model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), | 
 |  |  |                             entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                             order.getSymbol()); | 
 |  |  |                             order.getSymbol(), order.getMemberId()); | 
 |  |  |                 } else if (ContractEntrustOrderEntity.ENTRUST_TYPE_CLOSE_MORE == entrustType) { | 
 |  |  |                     model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_MORE.getValue(), | 
 |  |  |                             entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                             order.getSymbol()); | 
 |  |  |                             order.getSymbol(), order.getMemberId()); | 
 |  |  |                 } else { | 
 |  |  |                     model = new OrderModel(order.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_LESS.getValue(), | 
 |  |  |                             entrustPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), | 
 |  |  |                             order.getSymbol()); | 
 |  |  |                             order.getSymbol(), order.getMemberId()); | 
 |  |  |                 } | 
 |  |  |                 producer.sendPriceOperate(JSONObject.toJSONString(model)); | 
 |  |  |             } | 
 
 |  |  | 
 |  |  |      */ | 
 |  |  |     private Integer operateNo; | 
 |  |  |  | 
 |  |  |     private Long memberId; | 
 |  |  |  | 
 |  |  |     public OrderModel(Long orderId, Integer type, String price, String symbol){ | 
 |  |  |  | 
 |  |  |     public OrderModel(Long orderId, Integer type, String price, String symbol, Long memberId){ | 
 |  |  |         this.orderId= orderId; | 
 |  |  |         this.type= type; | 
 |  |  |         this.price= price; | 
 |  |  |         this.symbol= symbol; | 
 |  |  |         this.memberId = memberId; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public OrderModel(Long orderId,Integer type,String price, String symbol,Integer operateNo){ | 
 |  |  |     public OrderModel(Long orderId,Integer type,String price, String symbol,Integer operateNo, Long memberId){ | 
 |  |  |         this.orderId= orderId; | 
 |  |  |         this.type= type; | 
 |  |  |         this.price= price; | 
 |  |  |         this.symbol= symbol; | 
 |  |  |         this.operateNo= operateNo; | 
 |  |  |         this.memberId = memberId; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Integer getOperateNo() { | 
 |  |  | 
 |  |  |     public void setSymbol(String symbol) { | 
 |  |  |         this.symbol = symbol; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Long getMemberId() { | 
 |  |  |         return memberId; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void setMemberId(Long memberId) { | 
 |  |  |         this.memberId = memberId; | 
 |  |  |     } | 
 |  |  | } | 
 
 |  |  | 
 |  |  |             // 判断这个单的这个类型是否有 | 
 |  |  | //            if (CollectionUtils.isNotEmpty(list)) { | 
 |  |  |                 // 新增 | 
 |  |  |                 OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo()); | 
 |  |  |                 OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo(), order.getMemberId()); | 
 |  |  |                 list.add(orderModel); | 
 |  |  | //            } | 
 |  |  |         } else { | 
 |  |  |             List<OrderModel> list = new ArrayList<OrderModel>(); | 
 |  |  |             OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo()); | 
 |  |  |             OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo(), order.getMemberId()); | 
 |  |  |             list.add(orderModel); | 
 |  |  |             orderMap.put(price, list); | 
 |  |  |         } | 
 |  |  | 
 |  |  |             // 判断这个单的这个类型是否有 | 
 |  |  | //            if (CollectionUtils.isNotEmpty(list)) { | 
 |  |  |                 // 新增 | 
 |  |  |                 OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo()); | 
 |  |  |                 OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo(), order.getMemberId()); | 
 |  |  |                 list.add(orderModel); | 
 |  |  | //            } | 
 |  |  |         } else { | 
 |  |  |             List<OrderModel> list = new ArrayList<OrderModel>(); | 
 |  |  |             OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo()); | 
 |  |  |             OrderModel orderModel = new OrderModel(orderId, type, price, null,order.getOperateNo(), order.getMemberId()); | 
 |  |  |             list.add(orderModel); | 
 |  |  |             orderMap.put(price, list); | 
 |  |  |         } | 
 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         redisUtils.lSet(AppContants.RABBIT_TYPE + model.getOrderId(), orderTypes, 10); | 
 |  |  |         redisUtils.lSet(AppContants.MEMBER_TYPE + model.getMemberId(), orderTypes, 5); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 处理消息 正序的 包括 | 
 |  |  | 
 |  |  |             // 2:开多6:爆仓平多 | 
 |  |  |             // 10:止盈平空11:止损平多 | 
 |  |  |             for (OrderModel model : orderModelList) { | 
 |  |  |                 /* | 
 |  |  |                    问题: 1、逐仓: 当行情大时,若设置的止损点与爆仓过于接近,则可能会出现直接爆仓,而不止损的情况 | 
 |  |  |                         2、全仓: 止盈价/止损价 设置的与委托平仓价相同,需优先处理止盈/止损 | 
 |  |  |                    解决: 将订单ID作为Key, 该订单执行的队列类型集合作为value, 用于在执行爆仓、委托平仓时,是否存在止盈/止损,若存在则不执行该爆仓和委托平仓 | 
 |  |  |                  */ | 
 |  |  |                 addExecType(model); | 
 |  |  |  | 
 |  |  |                 // 开空止盈 | 
 |  |  |                 List<OrderModel> kkzyList = new ArrayList<OrderModel>(); | 
 |  |  |                 // 开多止损 | 
 
 |  |  | 
 |  |  | 
 | 
 |  |  |             if (forceSetPrice.compareTo(BigDecimal.ZERO) > 0) {
 | 
 |  |  |                 log.info("id:{}, type:{}, forceSetPrice:{}, symbol:{}, operateNo:{}", id, type, forceSetPrice, symbol, operateNo);
 | 
 |  |  |                 sendOrderBombMsg(id, type, forceSetPrice, symbol, operateNo);
 | 
 |  |  |                 sendOrderBombMsg(id, type, forceSetPrice, symbol, operateNo, memberEntity.getId());
 | 
 |  |  |             }
 | 
 |  |  |         }
 | 
 |  |  |     }
 | 
 |  |  | 
 |  |  | 
 | 
 |  |  |      */
 | 
 |  |  | 
 | 
 |  |  |     private static void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo) {
 | 
 |  |  |     private static void sendOrderBombMsg(Long id, int type, BigDecimal forceClosingPrice, String symbol, int operateNo, Long memberId) {
 | 
 |  |  |         OrderModel model = null;
 | 
 |  |  |         // 开多
 | 
 |  |  |         if (ContractHoldOrderEntity.OPENING_TYPE_MORE == type) {
 | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo);
 | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_MORE_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo, memberId);
 | 
 |  |  |             // 开空
 | 
 |  |  |         } else {
 | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo);
 | 
 |  |  |             model = new OrderModel(id, RabbitPriceTypeEnum.CLOSE_LESS_BOMB.getValue(), forceClosingPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), symbol, operateNo, memberId);
 | 
 |  |  |         }
 | 
 |  |  |         SpringContextHolder.getBean(OrderProducer.class).sendPriceOperate(JSONObject.toJSONString(model));
 | 
 |  |  |     }
 | 
 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private OrderProducer orderProducer; | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void sendMsg() { | 
 |  |  |         List<OrderModel> list = new ArrayList<>(); | 
 |  |  |         OrderModel orderModel = new OrderModel(1L, RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), "111", "BTC"); | 
 |  |  |         list.add(orderModel); | 
 |  |  |         orderProducer.sendLimitClose(JSONObject.toJSONString(list)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     // 面值*(多单张数*多单开仓价-空单张数*空单开仓价)-余额-已实现盈亏 / 面值*(多单张数-空单张数)-(维持保证金率+TAKER手续费)*面值*(开多张数+开空张数) | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Test | 
 |  |  |     public void redisTest() { | 
 |  |  |         for (int i = 827; i < 999; i++) { | 
 |  |  |             redisUtils.del(AppContants.CLOSING_ORDER_PREFIX + i); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |