From 6cb72d1fda923f2f4964df8efc56452c0d3d084a Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Thu, 04 Jun 2020 11:36:38 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/chonggaoxiao/new_excoin.git --- src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java | 60 ++++++++++++++++-------------- src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ProfitOrLessDto.java | 21 ++-------- src/main/java/com/xcong/excoin/rabbit/consumer/OperateOrderPriceConsumer.java | 35 ++++++++--------- src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java | 4 +- 4 files changed, 55 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java b/src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java index 633305d..7be7f09 100644 --- a/src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java +++ b/src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java @@ -46,10 +46,10 @@ public static final String QUEUE_COINOUT = "QUEUE_COINOUT_NEW"; //价格操作 - public static final String QUEUE_PRICEOPERATE = "QUEUE_PRICEOPERATE_NEW"; + public static final String QUEUE_PRICEOPERATE = "QUEUE_PRICEOPERATE"; // 平仓队列 - public static final String QUEUE_CLOSETRADE = "QUEUE_CLOSETRADE_NEW"; + public static final String QUEUE_CLOSETRADE = "QUEUE_CLOSETRADE"; // 开多止盈路由键 diff --git a/src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ProfitOrLessDto.java b/src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ProfitOrLessDto.java index 454e628..ea0e60f 100644 --- a/src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ProfitOrLessDto.java +++ b/src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ProfitOrLessDto.java @@ -17,26 +17,13 @@ @ApiModel(value = "ProfitOrLessDto", description = "设置止盈止损接口参数类") public class ProfitOrLessDto { - /** - * 类型 止盈 - */ - public static final int TYPE_PROFIT = 1; - - /** - * 类型 止损 - */ - public static final int TYPE_LESS = 2; - @NotNull @ApiModelProperty(value = "订单ID", example = "1") private Long id; - @NotNull - @ApiModelProperty(value = "类型 1-止盈2-止损", example = "1") - private Integer type; + @ApiModelProperty(value = "止盈价", example = "9000.00") + private BigDecimal stopProfitPrice; - @NotNull - @Min(0) - @ApiModelProperty(value = "目标价格", example = "9000.00") - private BigDecimal price; + @ApiModelProperty(value = "止损价", example = "9000.00") + private BigDecimal stopLessPrice; } diff --git a/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java index 858b2af..f6c8e47 100644 --- a/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java @@ -299,82 +299,86 @@ // 开仓价 BigDecimal openPrice = holdOrderEntity.getOpeningPrice(); // 设置的止盈止损价 - BigDecimal price = profitOrLessDto.getPrice(); + BigDecimal stopProfitPrice = profitOrLessDto.getStopProfitPrice(); + + BigDecimal stopLessPrice = profitOrLessDto.getStopLessPrice(); // 开多 if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { - if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { + if (stopProfitPrice != null) { // 当前价大于开仓价 if (newPrice.compareTo(openPrice) > 0) { // 如果止盈价小于当前价 - if (price.compareTo(newPrice) < 0) { + if (stopProfitPrice.compareTo(newPrice) < 0) { return Result.fail("止盈价必须高于当前价"); } } else { - if (price.compareTo(openPrice) < 0) { + if (stopProfitPrice.compareTo(openPrice) < 0) { return Result.fail("止盈价必须高于开仓价"); } } - } else { + } + + if (stopLessPrice != null) { if (newPrice.compareTo(openPrice) > 0) { - if (price.compareTo(openPrice) > 0) { + if (stopLessPrice.compareTo(openPrice) > 0) { return Result.fail("止损价必须低于开仓价"); } } else { - if (price.compareTo(newPrice) > 0) { + if (stopLessPrice.compareTo(newPrice) > 0) { return Result.fail("止损价必须低于当前价"); } } } // 开空 } else { - if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { + if (stopProfitPrice != null) { if (newPrice.compareTo(openPrice) > 0) { - if (price.compareTo(openPrice) > 0) { + if (stopProfitPrice.compareTo(openPrice) > 0) { return Result.fail("止损价必须低于开仓价"); } } else { - if (price.compareTo(newPrice) > 0) { + if (stopProfitPrice.compareTo(newPrice) > 0) { return Result.fail("止损价必须低于当前价"); } } - } else { + } + if (stopLessPrice != null) { if (newPrice.compareTo(openPrice) > 0) { - if (price.compareTo(newPrice) < 0) { + if (stopLessPrice.compareTo(newPrice) < 0) { return Result.fail("止损价必须高于当前价"); } } else { - if (price.compareTo(openPrice) < 0) { + if (stopLessPrice.compareTo(openPrice) < 0) { return Result.fail("止损价必须高于开仓价"); } } } } - if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { - holdOrderEntity.setStopProfitPrice(price); - } else { - holdOrderEntity.setStopLossPrice(price); - } + holdOrderEntity.setStopProfitPrice(stopProfitPrice); + holdOrderEntity.setStopLossPrice(stopLessPrice); int i = contractHoldOrderDao.updateById(holdOrderEntity); if (i > 0) { OrderModel model = null; if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { // 开多止盈 - if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { - model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); - // 开多止损 - } else { - model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); + if (stopProfitPrice != null) { + model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); + } + // 开多止损 + if (stopLessPrice != null) { + model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); } } else { // 开空止盈 - if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) { - model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); - // 开空止损 - } else { - model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); + if (stopProfitPrice != null) { + model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); + } + // 开空止损 + if (stopLessPrice != null) { + model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); } } producer.sendPriceOperate(JSONObject.toJSONString(model)); diff --git a/src/main/java/com/xcong/excoin/rabbit/consumer/OperateOrderPriceConsumer.java b/src/main/java/com/xcong/excoin/rabbit/consumer/OperateOrderPriceConsumer.java index 2d2ff3d..45ff0f7 100644 --- a/src/main/java/com/xcong/excoin/rabbit/consumer/OperateOrderPriceConsumer.java +++ b/src/main/java/com/xcong/excoin/rabbit/consumer/OperateOrderPriceConsumer.java @@ -14,32 +14,31 @@ /** * 用户修改止损止盈价格、提价限价委托、下单爆仓价等消息 * 后台打包开启 APP 不开启 + * @author helius */ @Component -@ConditionalOnProperty(prefix="app",name="newest-price-update-job",havingValue="true") +@ConditionalOnProperty(prefix = "app", name = "newest-price-update-job", havingValue = "true") public class OperateOrderPriceConsumer { - - /** - * 用户修改止损止盈价格、提价限价委托、下单爆仓价等消息 - * @date 2019年4月19日 - * @param message 消息体 - * @param channel 信道 - */ - @RabbitListener(queues = RabbitMqConfig.QUEUE_PRICEOPERATE) - public void onMessageMorePro(Message message, Channel channel) { + /** + * 用户修改止损止盈价格、提价限价委托、下单爆仓价等消息 + * + * @param message 消息体 + * @param channel 信道 + * @date 2019年4月19日 + */ + @RabbitListener(queues = RabbitMqConfig.QUEUE_PRICEOPERATE) + public void onMessageMorePro(Message message, Channel channel) { String content = new String(message.getBody()); - System.out.println("我收到了用户的订单操作消息:"+content); - // 操作前的map + System.out.println("我收到了用户的订单操作消息:" + content); + // 操作前的map // 转为model - OrderModel orderModel = JSONObject.parseObject(content, OrderModel.class); - // 向优先队列添加 - OrderOperatePriceService.dealWithNewMq(orderModel); + OrderModel orderModel = JSONObject.parseObject(content, OrderModel.class); + // 向优先队列添加 + OrderOperatePriceService.dealWithNewMq(orderModel); - } - - + } } -- Gitblit v1.9.1