Helius
2020-06-04 ccc00fa78758dc848582aa6af685031b471fed1b
modify
4 files modified
120 ■■■■ changed files
src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/parameter/dto/ProfitOrLessDto.java 21 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java 60 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/consumer/OperateOrderPriceConsumer.java 35 ●●●● patch | view | raw | blame | history
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";
    // 开多止盈路由键
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;
}
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));
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);
    }
    }
}