Skip to content

Commit

Permalink
✨ feat: 체결가 웹소켓과 주문 체결 연동 #53
Browse files Browse the repository at this point in the history
sieunie committed Nov 12, 2024
1 parent 3ca62ea commit 4ae4780
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions BE/src/websocket/stock/price/stock-price-socket.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { BaseSocketService } from '../../base-socket.service';
import { SocketGateway } from '../../socket.gateway';
import { StockItemService } from '../../../stock/item/stock-item.service';
import { StockOrderService } from '../../../stock/order/stock-order.service';

@Injectable()
export class StockPriceSocketService {
private TR_ID = 'H0STCNT0';

constructor(
private readonly socketGateway: SocketGateway,
private readonly baseSocketService: BaseSocketService,
private readonly stockItemService: StockItemService,
private readonly stockOrderService: StockOrderService,
) {
baseSocketService.registerSocketOpenHandler(async () => {
const stockList = await this.stockItemService.getAllStockItems();
stockList.forEach((stock) => {
this.baseSocketService.registerCode(this.TR_ID, stock.code);
});
});

baseSocketService.registerSocketDataHandler(
this.TR_ID,
(data: string[]) => {
stockOrderService
.checkExecutableOrder(
data[0], // 주식 코드
data[2], // 주식 체결가
)
.catch(() => {
throw new InternalServerErrorException();
});
},
);
}
}

0 comments on commit 4ae4780

Please sign in to comment.