Helius
2020-06-01 4b844113469b203adc40f1e540de98612321f26e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.xcong.excoin.rabbit.consumer;
 
import com.alibaba.fastjson.JSONArray;
import com.rabbitmq.client.Channel;
import com.xcong.excoin.configurations.RabbitMqConfig;
import com.xcong.excoin.modules.contract.service.RabbitOrderService;
import com.xcong.excoin.modules.contract.service.impl.OrderWebsocketServiceImpl;
import com.xcong.excoin.rabbit.pricequeue.OrderModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
 
/**
 * APP和后台打包都开启
 *
 * @author helius
 */
@Slf4j
@Component
@ConditionalOnProperty(prefix = "app", name = "rabbit-consumer", havingValue = "true")
public class WebsocketPriceConsumer {
 
    @Resource
    OrderWebsocketServiceImpl orderWebsocketService;
 
    @Resource
    RabbitOrderService orderService;
 
 
    /**
     * 开多止盈
     *
     * @param message 消息体
     * @param channel 信道
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_MOREPRO)
    public void onMessageMorePro(Message message, Channel channel) {
        String content = new String(message.getBody());
        System.out.println("我收到消息了开多止盈:" + content);
        List<OrderModel> list = JSONArray.parseArray(content, OrderModel.class);
        // 开始处理  TODO
        //orderWebsocketService.dealOrderFromMq(list,9);
    }
    // 1:买入委托2:开多3:开空4:平多5:平空6:爆仓平多7:爆仓平空8:撤单9:止盈平多10:止盈平空11:止损平多12:止损平空
 
    /**
     * 开空止盈
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_LESSPRO)
    public void onMessageLessPro(Message message, Channel channel) {
        String content = new String(message.getBody());
        System.out.println("我收到消息了开空止盈:" + content);
        // 开始处理
        List<OrderModel> list = JSONArray.parseArray(content, OrderModel.class);
        // 开始处理
        //orderWebsocketService.dealOrderFromMq(list,10);
    }
 
 
    /**
     * 开多止损
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_MORELOSS)
    public void onMessageMoreLoss(Message message, Channel channel) {
        String content = new String(message.getBody());
        System.out.println("我收到消息了开多止损:" + content);
        // 开始处理
        List<OrderModel> list = JSONArray.parseArray(content, OrderModel.class);
        // 开始处理
        //orderWebsocketService.dealOrderFromMq(list,11);
    }
 
    /**
     * 开空止损
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_LESSLOSS)
    public void onMessageLessLoss(Message message, Channel channel) {
        String content = new String(message.getBody());
        System.out.println("我收到消息了开空止损:" + content);
        // 开始处理
        List<OrderModel> list = JSONArray.parseArray(content, OrderModel.class);
        // 开始处理
        //orderWebsocketService.dealOrderFromMq(list,12);
    }
 
    /**
     * 限价委托
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_LIMIT)
    public void onMessageLimit(Message message, Channel channel) {
        String content = new String(message.getBody());
        System.out.println("我收到消息了限价委托:" + content);
        // 开始处理
        List<OrderModel> list = JSONArray.parseArray(content, OrderModel.class);
        // 开始处理
        //orderWebsocketService.dealForLimitMq(list);
    }
 
    /**
     * 爆仓消费者
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_COINOUT)
    public void onMessageCoinout(Message message, Channel channel) {
        String content = new String(message.getBody());
        System.out.println("我收到消息了爆仓:" + content);
        // 开始处理
        List<OrderModel> list = JSONArray.parseArray(content, OrderModel.class);
        // 开始处理
        //orderWebsocketService.dealOrderFromMq(list,6);
    }
 
    /**
     * 平仓
     *
     * @param message
     * @param channel
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_CLOSETRADE)
    public void onMessageCloseTrade(Message message, Channel channel) {
        String content = new String(message.getBody());
        log.info("我收到消息了平仓: {}", content);
        // 订单
        List<Long> ids = JSONArray.parseArray(content, Long.class);
        orderService.cancelHoldOrder(ids);
    }
}