Skip to content

Commit

Permalink
✨ feat: 현재 주식가 정보를 전달해주는 실시간 소켓 구현#97
Browse files Browse the repository at this point in the history
  • Loading branch information
uuuo3o committed Nov 20, 2024
1 parent bf64014 commit 20facee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions BE/src/stock/trade/history/dto/stock-detail-socket-data.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';

export class StockDetailSocketDataDto {
@ApiProperty({ description: '주식 현재가' })
stck_prpr: string;

@ApiProperty({ description: '전일 대비 부호' })
prdy_vrss_sign: string;

@ApiProperty({ description: '전일 대비' })
prdy_vrss: string;

@ApiProperty({ description: '전일 대비율' })
prdy_ctrt: string;
}
13 changes: 13 additions & 0 deletions BE/src/stock/trade/history/stock-trade-history-socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SocketConnectTokenInterface } from '../../../common/websocket/interface
import { getFullTestURL } from '../../../util/get-full-URL';
import { TodayStockTradeHistoryDataDto } from './dto/today-stock-trade-history-data.dto';
import { SocketGateway } from '../../../common/websocket/socket.gateway';
import { StockDetailSocketDataDto } from './dto/stock-detail-socket-data.dto';

@Injectable()
export class StockTradeHistorySocketService implements OnModuleInit {
Expand Down Expand Up @@ -53,6 +54,13 @@ export class StockTradeHistorySocketService implements OnModuleInit {
prdy_ctrt: dataList[5],
};

const detailData: StockDetailSocketDataDto = {
stck_prpr: dataList[2],
prdy_vrss_sign: dataList[3],
prdy_vrss: dataList[4],
prdy_ctrt: dataList[5],
};

this.eventSubject.next({
data: JSON.stringify({
tradeData,
Expand All @@ -63,6 +71,11 @@ export class StockTradeHistorySocketService implements OnModuleInit {
`trade-history/${dataList[0]}`,
tradeData,
);

this.socketGateway.sendStockIndexValueToClient(
`detail/${dataList[0]}`,
detailData,
);
};

this.socket.onclose = () => {
Expand Down

0 comments on commit 20facee

Please sign in to comment.