From cbcc38f91665aedf45ae7537793f8e8cd3bf294a Mon Sep 17 00:00:00 2001 From: JIN Date: Fri, 22 Nov 2024 12:54:15 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20!HOTFIX:=20SSE=EA=B0=80=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EC=A3=BC=EC=8B=9D=EC=A2=85=EB=AA=A9?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9D=B4=EC=99=B8=EC=9D=98=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=8F=84=20=EC=A0=84=EB=8B=AC=ED=95=98=EB=A0=A4?= =?UTF-8?q?=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/today-stock-trade-history-data.dto.ts | 3 +++ .../history/stock-trade-history-socket.service.ts | 13 ++++++++++--- .../trade/history/stock-trade-history.controller.ts | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/BE/src/stock/trade/history/dto/today-stock-trade-history-data.dto.ts b/BE/src/stock/trade/history/dto/today-stock-trade-history-data.dto.ts index 7842a29b..d73f4ba0 100644 --- a/BE/src/stock/trade/history/dto/today-stock-trade-history-data.dto.ts +++ b/BE/src/stock/trade/history/dto/today-stock-trade-history-data.dto.ts @@ -1,6 +1,9 @@ import { ApiProperty } from '@nestjs/swagger'; export class TodayStockTradeHistoryDataDto { + @ApiProperty({ description: '주식 체결 시간' }) + stck_shrn_iscd: string; + @ApiProperty({ description: '주식 체결 시간' }) stck_cntg_hour: string; diff --git a/BE/src/stock/trade/history/stock-trade-history-socket.service.ts b/BE/src/stock/trade/history/stock-trade-history-socket.service.ts index 9b055a3c..b32f9601 100644 --- a/BE/src/stock/trade/history/stock-trade-history-socket.service.ts +++ b/BE/src/stock/trade/history/stock-trade-history-socket.service.ts @@ -1,6 +1,6 @@ import { WebSocket } from 'ws'; import axios from 'axios'; -import { Observable, Subject } from 'rxjs'; +import { filter, map, Observable, Subject } from 'rxjs'; import { Injectable, Logger, OnModuleInit } from '@nestjs/common'; import { SseEvent } from './interface/sse-event'; import { SocketConnectTokenInterface } from '../../../common/websocket/interface/socket.interface'; @@ -47,6 +47,7 @@ export class StockTradeHistorySocketService implements OnModuleInit { const dataList = data[3].split('^'); const tradeData: TodayStockTradeHistoryDataDto = { + stck_shrn_iscd: dataList[0], stck_cntg_hour: dataList[1], stck_prpr: dataList[2], prdy_vrss_sign: dataList[3], @@ -83,8 +84,14 @@ export class StockTradeHistorySocketService implements OnModuleInit { }; } - getTradeDataStream(): Observable { - return this.eventSubject.asObservable(); + getTradeDataStream(targetStockCode: string): Observable { + return this.eventSubject.pipe( + filter((event: SseEvent) => { + const parsed = JSON.parse(event.data); + return parsed.tradeData.stck_shrn_iscd === targetStockCode; + }), + map((event: SseEvent) => event), + ); } subscribeByCode(stockCode: string) { diff --git a/BE/src/stock/trade/history/stock-trade-history.controller.ts b/BE/src/stock/trade/history/stock-trade-history.controller.ts index 74f21c44..b225642d 100644 --- a/BE/src/stock/trade/history/stock-trade-history.controller.ts +++ b/BE/src/stock/trade/history/stock-trade-history.controller.ts @@ -76,7 +76,7 @@ export class StockTradeHistoryController { return new Observable((subscriber) => { const subscription = this.stockTradeHistorySocketService - .getTradeDataStream() + .getTradeDataStream(stockCode) .subscribe(subscriber); return () => {