| | |
| | | */ |
| | | ENTRUST_OPEN_MORE(2) |
| | | , ENTRUST_OPEN_LESS(3) |
| | | , ENTRUST_CLOSE_MORE(4) |
| | | , ENTRUST_CLOSE_LESS(5) |
| | | , CLOSE_MORE_BOMB(6) |
| | | , CLOSE_LESS_BOMB(7) |
| | | , CLOSE_MORE_STOP_PROFIT(9) |
| | |
| | | // 限价委托 |
| | | public static final String QUEUE_LIMIT = "QUEUE_LIMIT_NEW"; |
| | | |
| | | // 委托平仓 |
| | | public static final String QUEUE_LIMIT_CLOSE = "QUEUE_LIMIT_CLOSE_NEW"; |
| | | |
| | | // 爆仓队列 |
| | | public static final String QUEUE_COINOUT = "QUEUE_COINOUT_NEW"; |
| | | |
| | |
| | | public static final String ROUTINGKEY_PRICEOPERATE = "ROUTINGKEY_PRICEOPERATE"; |
| | | // 平仓路由 |
| | | public static final String ROUTINGKEY_CLOSETRADE = "ROUTINGKEY_CLOSETRADE"; |
| | | |
| | | // 委托平仓 |
| | | public static final String ROUTINGKEY_LIMIT_CLOSE = "ROUTINGKEY_LIMIT_CLOSE"; |
| | | |
| | | @Resource |
| | | private ConnectionFactory connectionFactory; |
| | |
| | | return new Queue(QUEUE_LIMIT, true); |
| | | } |
| | | |
| | | /** |
| | | * 委托平仓 |
| | | * |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public Queue queueLimitClose() { |
| | | return new Queue(QUEUE_LIMIT_CLOSE, true); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 爆仓 |
| | |
| | | return BindingBuilder.bind(queueLimit()).to(orderExchange()).with(RabbitMqConfig.ROUTINGKEY_LIMIT); |
| | | } |
| | | |
| | | /** |
| | | * 委托平仓 |
| | | * |
| | | * @return |
| | | */ |
| | | public Binding bindingLimitClose() { |
| | | return BindingBuilder.bind(queueLimitClose()).to(orderExchange()).with(RabbitMqConfig.QUEUE_LIMIT_CLOSE); |
| | | } |
| | | |
| | | /** |
| | | * 爆仓 |
| | |
| | | if (i > 0) { |
| | | // 发送委托消息 |
| | | if (holdOrderEntity.getOpeningType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { |
| | | OrderModel model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | OrderModel model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_MORE.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } else { |
| | | OrderModel model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | OrderModel model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_CLOSE_LESS.getValue(), submitCloseEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol()); |
| | | producer.sendPriceOperate(JSONObject.toJSONString(model)); |
| | | } |
| | | } |
| | |
| | | List<Long> ids = JSONArray.parseArray(content, Long.class); |
| | | orderService.cancelHoldOrder(ids); |
| | | } |
| | | |
| | | /** |
| | | * 委托平仓 |
| | | * |
| | | * @param message |
| | | * @param channel |
| | | */ |
| | | public void onMessageLimitClose(Message message, Channel channel) { |
| | | String content = new String(message.getBody()); |
| | | log.info("==message-price-consumer==我收到消息了委托平仓: {}", content); |
| | | } |
| | | } |
| | |
| | | // 【1:买入委托2:开多3:开空4:平多5:平空6:爆仓平多7:爆仓平空8:撤单9:止盈平多10:止盈平空11:止损平多12:止损平空】 |
| | | int type = orderModel.getType(); |
| | | Map<String, List<OrderModel>> orderMap = PricePriorityQueue.getOrderMap(orderModel.getSymbol(), type); |
| | | if (type == 12 || type == 9 || type == 7 || type == 3) { |
| | | if (type == 12 || type == 9 || type == 7 || type == 3 || type == 4) { |
| | | // 需要价格涨的 |
| | | PriorityBlockingQueue<AscBigDecimal> queue = PricePriorityQueue.getQueueAsc(orderModel.getSymbol()); |
| | | dealPriceAsc(orderModel, orderMap, queue); |
| | |
| | | List<OrderModel> bcList = new ArrayList<OrderModel>(); |
| | | // 开空 |
| | | List<OrderModel> wtkkList = new ArrayList<OrderModel>(); |
| | | // 委托平多 |
| | | List<OrderModel> wtpdList = new ArrayList<>(); |
| | | switch (model.getType()) { |
| | | case 3: |
| | | wtkkList.add(model); |
| | | break; |
| | | case 4: |
| | | wtpdList.add(model); |
| | | break; |
| | | case 7: |
| | | bcList.add(model); |
| | |
| | | } |
| | | if (CollectionUtils.isNotEmpty(wtkkList)) { |
| | | orderProducer.sendLimit(JSONObject.toJSONString(wtkkList)); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(wtpdList)) { |
| | | orderProducer.sendLimitClose(JSONObject.toJSONString(wtpdList)); |
| | | } |
| | | } |
| | | } |
| | |
| | | List<OrderModel> bcList = new ArrayList<OrderModel>(); |
| | | // 开多委托 |
| | | List<OrderModel> wtkdList = new ArrayList<OrderModel>(); |
| | | // 委托平空 |
| | | List<OrderModel> wtpkList = new ArrayList<>(); |
| | | switch (model.getType()) { |
| | | case 2: |
| | | wtkdList.add(model); |
| | | break; |
| | | case 5: |
| | | wtpkList.add(model); |
| | | break; |
| | | case 6: |
| | | bcList.add(model); |
| | |
| | | } |
| | | if (CollectionUtils.isNotEmpty(wtkdList)) { |
| | | orderProducer.sendLimit(JSONObject.toJSONString(wtkdList)); |
| | | |
| | | } |
| | | if (CollectionUtils.isNotEmpty(wtpkList)) { |
| | | orderProducer.sendLimitClose(JSONObject.toJSONString(wtpkList)); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送委托平仓 |
| | | * |
| | | * @param content |
| | | */ |
| | | public void sendLimitClose(String content) { |
| | | CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); |
| | | log.info("发送委托平仓消息:{} == pid:{}", content, correlationData.getId()); |
| | | |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LIMIT_CLOSE, content, correlationData); |
| | | } |
| | | |
| | | } |