Skip to content

Commit

Permalink
πŸš‘ !HOTFIX: SSEκ°€ νŠΉμ • 주식쒅λͺ©μ½”λ“œ μ΄μ™Έμ˜ 정보도 μ „λ‹¬ν•˜λ €λŠ” ν˜„μƒ μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
uuuo3o committed Nov 22, 2024
1 parent 5f62729 commit cbcc38f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';

export class TodayStockTradeHistoryDataDto {
@ApiProperty({ description: '주식 체결 μ‹œκ°„' })
stck_shrn_iscd: string;

@ApiProperty({ description: '주식 체결 μ‹œκ°„' })
stck_cntg_hour: string;

Expand Down
13 changes: 10 additions & 3 deletions BE/src/stock/trade/history/stock-trade-history-socket.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -83,8 +84,14 @@ export class StockTradeHistorySocketService implements OnModuleInit {
};
}

getTradeDataStream(): Observable<SseEvent> {
return this.eventSubject.asObservable();
getTradeDataStream(targetStockCode: string): Observable<SseEvent> {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class StockTradeHistoryController {

return new Observable<SseEvent>((subscriber) => {
const subscription = this.stockTradeHistorySocketService
.getTradeDataStream()
.getTradeDataStream(stockCode)
.subscribe(subscriber);

return () => {
Expand Down

0 comments on commit cbcc38f

Please sign in to comment.