-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTradeExecutedNotificationHandler.java
More file actions
46 lines (36 loc) · 1.63 KB
/
TradeExecutedNotificationHandler.java
File metadata and controls
46 lines (36 loc) · 1.63 KB
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
package com.cleanengine.coin.trade.application;
import com.cleanengine.coin.order.domain.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;
import static com.cleanengine.coin.common.CommonValues.BUY_ORDER_BOT_ID;
import static com.cleanengine.coin.common.CommonValues.SELL_ORDER_BOT_ID;
@Slf4j
@Component
public class TradeExecutedNotificationHandler {
private final SimpMessagingTemplate messagingTemplate;
private static final String ASK = "ask"; // 매도
private static final String BID = "bid"; // 매수
public TradeExecutedNotificationHandler(SimpMessagingTemplate messagingTemplate) {
this.messagingTemplate = messagingTemplate;
}
@TransactionalEventListener
public void notifyAfterTradeExecuted(TradeOrderCompletedEvent tradeOrderCompletedEvent) {
// TODO : 평균단가는 별도 계산해야 함
Order order = tradeOrderCompletedEvent.getOrder();
if (order == null) {
log.error("체결 알림 실패! order == null");
return ;
}
Integer userId = order.getUserId();
if (userId == null) {
log.error("체결 알림 실패! userId: {}", userId);
return ;
}
if (userId != SELL_ORDER_BOT_ID && userId != BUY_ORDER_BOT_ID) {
TradeOrderCompletedNotifyDto notifyDto = TradeOrderCompletedNotifyDto.of(order);
messagingTemplate.convertAndSend("/topic/tradeNotification/" + userId, notifyDto);
}
}
}