From 99362cdf5c55fad734d74a05168779e10aa7bd24 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Fri, 8 Nov 2024 10:13:25 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20getFullUrl?= =?UTF-8?q?,=20getHeader=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../korea.investment.service.ts | 14 ++++---- BE/src/stock/index/stock.index.service.ts | 34 +++++++------------ BE/src/websocket/socket.service.ts | 6 ++-- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/BE/src/koreaInvestment/korea.investment.service.ts b/BE/src/koreaInvestment/korea.investment.service.ts index 57458372..73ebe901 100644 --- a/BE/src/koreaInvestment/korea.investment.service.ts +++ b/BE/src/koreaInvestment/korea.investment.service.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import { getFullURL } from '../util/getFullURL'; export class KoreaInvestmentService { private accessToken: string; @@ -9,14 +10,11 @@ export class KoreaInvestmentService { if (this.accessToken && this.tokenExpireTime > new Date()) { return this.accessToken; } - const response = await axios.post( - `${process.env.KOREA_INVESTMENT_BASE_URL}/oauth2/tokenP`, - { - grant_type: 'client_credentials', - appkey: process.env.KOREA_INVESTMENT_APP_KEY, - appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, - }, - ); + const response = await axios.post(getFullURL('/oauth2/tokenP'), { + grant_type: 'client_credentials', + appkey: process.env.KOREA_INVESTMENT_APP_KEY, + appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, + }); const { data } = response; diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock.index.service.ts index 875be12d..42bb056b 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock.index.service.ts @@ -7,6 +7,8 @@ import { StockIndexChartInterface, StockIndexValueInterface, } from './interface/stock.index.interface'; +import { getFullURL } from '../../util/getFullURL'; +import { getHeader } from '../../util/getHeader'; @Injectable() export class StockIndexService { @@ -39,12 +41,14 @@ export class StockIndexService { if (result.rt_cd !== '0') throw new Error('데이터를 정상적으로 조회하지 못했습니다.'); + const data = result.output; + return new StockIndexValueElementDto( code, - result.output.bstp_nmix_prpr, - result.output.bstp_nmix_prdy_vrss, - result.output.bstp_nmix_prdy_ctrt, - result.output.prdy_vrss_sign, + data.bstp_nmix_prpr, + data.bstp_nmix_prdy_vrss, + data.bstp_nmix_prdy_ctrt, + data.prdy_vrss_sign, ); } @@ -53,16 +57,9 @@ export class StockIndexService { accessToken: string, ) { const response = await axios.get( - `${process.env.KOREA_INVESTMENT_BASE_URL}/uapi/domestic-stock/v1/quotations/inquire-index-timeprice`, + getFullURL('/uapi/domestic-stock/v1/quotations/inquire-index-timeprice'), { - headers: { - 'content-type': 'application/json; charset=utf-8', - authorization: `Bearer ${accessToken}`, - appkey: process.env.KOREA_INVESTMENT_APP_KEY, - appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, - tr_id: 'FHPUP02110200', - custtype: 'P', - }, + headers: getHeader(accessToken, 'FHPUP02110200'), params: { fid_input_hour_1: 300, fid_cond_mrkt_div_code: 'U', @@ -79,16 +76,9 @@ export class StockIndexService { accessToken: string, ) { const response = await axios.get( - `${process.env.KOREA_INVESTMENT_BASE_URL}/uapi/domestic-stock/v1/quotations/inquire-index-price`, + getFullURL('/uapi/domestic-stock/v1/quotations/inquire-index-price'), { - headers: { - 'content-type': 'application/json; charset=utf-8', - authorization: `Bearer ${accessToken}`, - appkey: process.env.KOREA_INVESTMENT_APP_KEY, - appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, - tr_id: 'FHPUP02100000', - custtype: 'P', - }, + headers: getHeader(accessToken, 'FHPUP02100000'), params: { fid_cond_mrkt_div_code: 'U', fid_input_iscd: code, diff --git a/BE/src/websocket/socket.service.ts b/BE/src/websocket/socket.service.ts index 0c25bf03..68893600 100644 --- a/BE/src/websocket/socket.service.ts +++ b/BE/src/websocket/socket.service.ts @@ -4,6 +4,7 @@ import axios from 'axios'; import { SocketGateway } from './socket.gateway'; import { StockIndexValueElementDto } from '../stock/index/dto/stock.index.value.element.dto'; import { SocketConnectTokenInterface } from './interface/socket.interface'; +import { getFullURL } from '../util/getFullURL'; @Injectable() export class SocketService implements OnModuleInit { @@ -17,8 +18,7 @@ export class SocketService implements OnModuleInit { async onModuleInit() { const socketConnectionKey = await this.getSocketConnectionKey(); - const url = 'ws://ops.koreainvestment.com:21000'; - this.socket = new WebSocket(url); + this.socket = new WebSocket(process.env.KOREA_INVESTMENT_SOCKET_URL); this.socket.onopen = () => { this.registerStockIndexByCode('0001', socketConnectionKey); // 코스피 @@ -53,7 +53,7 @@ export class SocketService implements OnModuleInit { private async getSocketConnectionKey() { const response = await axios.post( - `${process.env.KOREA_INVESTMENT_BASE_URL}/oauth2/Approval`, + getFullURL('/oauth2/Approval'), { grant_type: 'client_credentials', appkey: process.env.KOREA_INVESTMENT_APP_KEY, From 6549725d9e02ef975f98efc3fd562ea26ba4bf91 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Fri, 8 Nov 2024 10:59:58 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20stock=20in?= =?UTF-8?q?dex=20=EA=B4=80=EB=A0=A8=20=EC=86=8C=EC=BC=93=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8,=20response=20=ED=98=95=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/dto/stock.index.list.element.dto.ts | 17 -------------- .../dto/stock.index.response.element.dto.ts | 14 +++++------- .../dto/stock.index.value.element.dto.ts | 22 +++++-------------- BE/src/stock/index/stock.index.controller.ts | 11 +++++----- BE/src/stock/index/stock.index.service.ts | 17 +++++--------- BE/src/websocket/socket.gateway.ts | 8 +++---- BE/src/websocket/socket.service.ts | 9 +++++++- 7 files changed, 35 insertions(+), 63 deletions(-) delete mode 100644 BE/src/stock/index/dto/stock.index.list.element.dto.ts diff --git a/BE/src/stock/index/dto/stock.index.list.element.dto.ts b/BE/src/stock/index/dto/stock.index.list.element.dto.ts deleted file mode 100644 index 03ec0176..00000000 --- a/BE/src/stock/index/dto/stock.index.list.element.dto.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { StockIndexListChartElementDto } from './stock.index.list.chart.element.dto'; - -export class StockIndexListElementDto { - constructor(code: string, chart: StockIndexListChartElementDto[]) { - this.code = code; - this.chart = chart; - } - - @ApiProperty({ - description: '코스피: 0001, 코스닥: 1001, 코스피200: 2001, KSQ150: 3003', - }) - code: string; - - @ApiProperty({ type: [StockIndexListChartElementDto] }) - chart: StockIndexListChartElementDto[]; -} diff --git a/BE/src/stock/index/dto/stock.index.response.element.dto.ts b/BE/src/stock/index/dto/stock.index.response.element.dto.ts index 7ce0ef1a..09e21102 100644 --- a/BE/src/stock/index/dto/stock.index.response.element.dto.ts +++ b/BE/src/stock/index/dto/stock.index.response.element.dto.ts @@ -1,16 +1,14 @@ import { ApiProperty } from '@nestjs/swagger'; import { StockIndexValueElementDto } from './stock.index.value.element.dto'; -import { StockIndexListElementDto } from './stock.index.list.element.dto'; +import { StockIndexListChartElementDto } from './stock.index.list.chart.element.dto'; export class StockIndexResponseElementDto { - @ApiProperty({ - description: '코스피: 0001, 코스닥: 1001, 코스피200: 2001, KSQ150: 3003', - }) - code: string; - @ApiProperty({ description: '실시간 값', type: StockIndexValueElementDto }) value: StockIndexValueElementDto; - @ApiProperty({ description: '실시간 차트', type: StockIndexListElementDto }) - chart: StockIndexListElementDto; + @ApiProperty({ + description: '실시간 차트', + type: [StockIndexListChartElementDto], + }) + chart: StockIndexListChartElementDto[]; } diff --git a/BE/src/stock/index/dto/stock.index.value.element.dto.ts b/BE/src/stock/index/dto/stock.index.value.element.dto.ts index 88ca4949..1eb73a50 100644 --- a/BE/src/stock/index/dto/stock.index.value.element.dto.ts +++ b/BE/src/stock/index/dto/stock.index.value.element.dto.ts @@ -1,33 +1,21 @@ import { ApiProperty } from '@nestjs/swagger'; export class StockIndexValueElementDto { - constructor( - code: string, - value: string, - diff: string, - diffRate: string, - sign: string, - ) { - this.code = code; - this.value = value; + constructor(value: string, diff: string, diffRate: string, sign: string) { + this.curr_value = value; this.diff = diff; - this.diffRate = diffRate; + this.diff_rate = diffRate; this.sign = sign; } - @ApiProperty({ - description: '코스피: 0001, 코스닥: 1001, 코스피200: 2001, KSQ150: 3003', - }) - code: string; - @ApiProperty({ description: '주가 지수' }) - value: string; + curr_value: string; @ApiProperty({ description: '전일 대비 등락' }) diff: string; @ApiProperty({ description: '전일 대비 등락률' }) - diffRate: string; + diff_rate: string; @ApiProperty({ description: '부호... 인데 추후에 알아봐야 함' }) sign: string; diff --git a/BE/src/stock/index/stock.index.controller.ts b/BE/src/stock/index/stock.index.controller.ts index 949df5a5..7625e044 100644 --- a/BE/src/stock/index/stock.index.controller.ts +++ b/BE/src/stock/index/stock.index.controller.ts @@ -70,22 +70,18 @@ export class StockIndexController { const stockIndexResponse = new StockIndexResponseDto(); stockIndexResponse.KOSPI = { - code: '0001', value: kospiValue, chart: kospiChart, }; stockIndexResponse.KOSDAQ = { - code: '1001', value: kosdaqValue, chart: kosdaqChart, }; stockIndexResponse.KOSPI200 = { - code: '2001', value: kospi200Value, chart: kospi200Chart, }; stockIndexResponse.KSQ150 = { - code: '3003', value: ksq150Value, chart: ksq150Chart, }; @@ -115,6 +111,11 @@ export class StockIndexController { ), // KSQ150 ]); - this.socketGateway.sendStockIndexListToClient(stockLists); + this.socketGateway.sendStockIndexListToClient({ + KOSPI: stockLists[0], + KOSDAQ: stockLists[1], + KOSPI200: stockLists[2], + KSQ150: stockLists[3], + }); } } diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock.index.service.ts index 42bb056b..0d4a97c0 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock.index.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@nestjs/common'; import axios from 'axios'; import { StockIndexListChartElementDto } from './dto/stock.index.list.chart.element.dto'; -import { StockIndexListElementDto } from './dto/stock.index.list.element.dto'; import { StockIndexValueElementDto } from './dto/stock.index.value.element.dto'; import { StockIndexChartInterface, @@ -21,15 +20,12 @@ export class StockIndexService { if (result.rt_cd !== '0') throw new Error('데이터를 정상적으로 조회하지 못했습니다.'); - return new StockIndexListElementDto( - code, - result.output.map((element) => { - return new StockIndexListChartElementDto( - element.bsop_hour, - element.bstp_nmix_prpr, - ); - }), - ); + return result.output.map((element) => { + return new StockIndexListChartElementDto( + element.bsop_hour, + element.bstp_nmix_prpr, + ); + }); } async getDomesticStockIndexValueByCode(code: string, accessToken: string) { @@ -44,7 +40,6 @@ export class StockIndexService { const data = result.output; return new StockIndexValueElementDto( - code, data.bstp_nmix_prpr, data.bstp_nmix_prdy_vrss, data.bstp_nmix_prdy_ctrt, diff --git a/BE/src/websocket/socket.gateway.ts b/BE/src/websocket/socket.gateway.ts index 921d9503..e65eac69 100644 --- a/BE/src/websocket/socket.gateway.ts +++ b/BE/src/websocket/socket.gateway.ts @@ -6,11 +6,11 @@ export class SocketGateway { @WebSocketServer() private server: Server; - sendStockIndexListToClient(stockIndex) { - this.server.emit('index', stockIndex); + sendStockIndexListToClient(stockChart) { + this.server.emit('chart', stockChart); } - sendStockIndexValueToClient(stockIndexValue) { - this.server.emit('indexValue', stockIndexValue); + sendStockIndexValueToClient(event, stockIndexValue) { + this.server.emit(event, stockIndexValue); } } diff --git a/BE/src/websocket/socket.service.ts b/BE/src/websocket/socket.service.ts index 68893600..042cd57a 100644 --- a/BE/src/websocket/socket.service.ts +++ b/BE/src/websocket/socket.service.ts @@ -13,6 +13,13 @@ export class SocketService implements OnModuleInit { H0UPCNT0: this.handleStockIndexValue.bind(this), }; + private STOCK_CODE = { + '0001': 'KOSPI', + '1001': 'KOSDAQ', + '2001': 'KOSPI200', + '3003': 'KSQ150', + }; + constructor(private readonly socketGateway: SocketGateway) {} async onModuleInit() { @@ -41,8 +48,8 @@ export class SocketService implements OnModuleInit { private handleStockIndexValue(responseData: string) { const responseList = responseData.split('^'); this.socketGateway.sendStockIndexValueToClient( + this.STOCK_CODE[responseList[0]], new StockIndexValueElementDto( - responseList[0], responseList[2], responseList[4], responseList[9], From d65c70bfef23fc17362613566ac1a07033f24e2d Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Fri, 8 Nov 2024 11:24:23 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=94=A7=20fix:=20service=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EB=A5=BC=20http=20=EC=97=90=EB=9F=AC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../korea.investment.service.ts | 15 +++-- BE/src/stock/index/stock.index.service.ts | 60 +++++++++++-------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/BE/src/koreaInvestment/korea.investment.service.ts b/BE/src/koreaInvestment/korea.investment.service.ts index 73ebe901..886b68cb 100644 --- a/BE/src/koreaInvestment/korea.investment.service.ts +++ b/BE/src/koreaInvestment/korea.investment.service.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import { UnauthorizedException } from '@nestjs/common'; import { getFullURL } from '../util/getFullURL'; export class KoreaInvestmentService { @@ -10,11 +11,15 @@ export class KoreaInvestmentService { if (this.accessToken && this.tokenExpireTime > new Date()) { return this.accessToken; } - const response = await axios.post(getFullURL('/oauth2/tokenP'), { - grant_type: 'client_credentials', - appkey: process.env.KOREA_INVESTMENT_APP_KEY, - appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, - }); + const response = await axios + .post(getFullURL('/oauth2/tokenP'), { + grant_type: 'client_credentials', + appkey: process.env.KOREA_INVESTMENT_APP_KEY, + appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, + }) + .catch((err) => { + throw new UnauthorizedException('액세스 토큰을 조회하지 못했습니다.'); + }); const { data } = response; diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock.index.service.ts index 0d4a97c0..3a14c7fc 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock.index.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, InternalServerErrorException } from '@nestjs/common'; import axios from 'axios'; import { StockIndexListChartElementDto } from './dto/stock.index.list.chart.element.dto'; import { StockIndexValueElementDto } from './dto/stock.index.value.element.dto'; @@ -17,9 +17,6 @@ export class StockIndexService { accessToken, ); - if (result.rt_cd !== '0') - throw new Error('데이터를 정상적으로 조회하지 못했습니다.'); - return result.output.map((element) => { return new StockIndexListChartElementDto( element.bsop_hour, @@ -34,9 +31,6 @@ export class StockIndexService { accessToken, ); - if (result.rt_cd !== '0') - throw new Error('데이터를 정상적으로 조회하지 못했습니다.'); - const data = result.output; return new StockIndexValueElementDto( @@ -51,17 +45,25 @@ export class StockIndexService { code: string, accessToken: string, ) { - const response = await axios.get( - getFullURL('/uapi/domestic-stock/v1/quotations/inquire-index-timeprice'), - { - headers: getHeader(accessToken, 'FHPUP02110200'), - params: { - fid_input_hour_1: 300, - fid_cond_mrkt_div_code: 'U', - fid_input_iscd: code, + const response = await axios + .get( + getFullURL( + '/uapi/domestic-stock/v1/quotations/inquire-index-timeprice', + ), + { + headers: getHeader(accessToken, 'FHPUP02110200'), + params: { + fid_input_hour_1: 300, + fid_cond_mrkt_div_code: 'U', + fid_input_iscd: code, + }, }, - }, - ); + ) + .catch((err) => { + throw new InternalServerErrorException( + '주가 지수 차트 정보를 조회하지 못했습니다.', + ); + }); return response.data; } @@ -70,16 +72,22 @@ export class StockIndexService { code: string, accessToken: string, ) { - const response = await axios.get( - getFullURL('/uapi/domestic-stock/v1/quotations/inquire-index-price'), - { - headers: getHeader(accessToken, 'FHPUP02100000'), - params: { - fid_cond_mrkt_div_code: 'U', - fid_input_iscd: code, + const response = await axios + .get( + getFullURL('/uapi/domestic-stock/v1/quotations/inquire-index-price'), + { + headers: getHeader(accessToken, 'FHPUP02100000'), + params: { + fid_cond_mrkt_div_code: 'U', + fid_input_iscd: code, + }, }, - }, - ); + ) + .catch((err) => { + throw new InternalServerErrorException( + '주가 지수 값 정보를 조회하지 못했습니다.', + ); + }); return response.data; } From 462c8a189747ec8e15cb25eec87b8e4936543db3 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Fri, 8 Nov 2024 11:42:36 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=94=A7=20fix:=20getAccessToken=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interface/korea.investment.interface.ts | 6 ++++++ BE/src/koreaInvestment/korea.investment.service.ts | 7 ++++--- BE/src/stock/index/stock.index.service.ts | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 BE/src/koreaInvestment/interface/korea.investment.interface.ts diff --git a/BE/src/koreaInvestment/interface/korea.investment.interface.ts b/BE/src/koreaInvestment/interface/korea.investment.interface.ts new file mode 100644 index 00000000..e290a32c --- /dev/null +++ b/BE/src/koreaInvestment/interface/korea.investment.interface.ts @@ -0,0 +1,6 @@ +export interface AccessTokenInterface { + access_token: string; + access_token_token_expired: string; + token_type: string; + expires_in: number; +} diff --git a/BE/src/koreaInvestment/korea.investment.service.ts b/BE/src/koreaInvestment/korea.investment.service.ts index 886b68cb..727c044c 100644 --- a/BE/src/koreaInvestment/korea.investment.service.ts +++ b/BE/src/koreaInvestment/korea.investment.service.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import { UnauthorizedException } from '@nestjs/common'; import { getFullURL } from '../util/getFullURL'; +import { AccessTokenInterface } from './interface/korea.investment.interface'; export class KoreaInvestmentService { private accessToken: string; @@ -12,19 +13,19 @@ export class KoreaInvestmentService { return this.accessToken; } const response = await axios - .post(getFullURL('/oauth2/tokenP'), { + .post(getFullURL('/oauth2/tokenP'), { grant_type: 'client_credentials', appkey: process.env.KOREA_INVESTMENT_APP_KEY, appsecret: process.env.KOREA_INVESTMENT_APP_SECRET, }) - .catch((err) => { + .catch(() => { throw new UnauthorizedException('액세스 토큰을 조회하지 못했습니다.'); }); const { data } = response; this.accessToken = data.access_token; - this.tokenExpireTime = new Date(Date.now() + +data.expires_in); + this.tokenExpireTime = new Date(data.access_token_token_expired); return this.accessToken; } diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock.index.service.ts index 3a14c7fc..587af43d 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock.index.service.ts @@ -59,7 +59,7 @@ export class StockIndexService { }, }, ) - .catch((err) => { + .catch(() => { throw new InternalServerErrorException( '주가 지수 차트 정보를 조회하지 못했습니다.', ); @@ -83,7 +83,7 @@ export class StockIndexService { }, }, ) - .catch((err) => { + .catch(() => { throw new InternalServerErrorException( '주가 지수 값 정보를 조회하지 못했습니다.', ); From f210aa0780a7722ab4b74e8d7ec552810fb61fb1 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Sun, 10 Nov 2024 00:35:32 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9E=95=20add:=20=EC=B0=A8=ED=8A=B8=20res?= =?UTF-8?q?ponse=EC=97=90=20=EC=A0=84=EC=9D=BC=20=EB=8C=80=EB=B9=84=20?= =?UTF-8?q?=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stock/index/dto/stock.index.list.chart.element.dto.ts | 6 +++++- BE/src/stock/index/stock.index.service.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BE/src/stock/index/dto/stock.index.list.chart.element.dto.ts b/BE/src/stock/index/dto/stock.index.list.chart.element.dto.ts index 1f2abdce..ba6ce1f2 100644 --- a/BE/src/stock/index/dto/stock.index.list.chart.element.dto.ts +++ b/BE/src/stock/index/dto/stock.index.list.chart.element.dto.ts @@ -1,9 +1,10 @@ import { ApiProperty } from '@nestjs/swagger'; export class StockIndexListChartElementDto { - constructor(time: string, value: string) { + constructor(time: string, value: string, diff: string) { this.time = time; this.value = value; + this.diff = diff; } @ApiProperty({ description: 'HHMMSS', example: '130500' }) @@ -11,4 +12,7 @@ export class StockIndexListChartElementDto { @ApiProperty({ description: '주가 지수' }) value: string; + + @ApiProperty({ description: '전일 대비 주가 지수' }) + diff: string; } diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock.index.service.ts index 587af43d..f15326f5 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock.index.service.ts @@ -21,6 +21,7 @@ export class StockIndexService { return new StockIndexListChartElementDto( element.bsop_hour, element.bstp_nmix_prpr, + element.bstp_nmix_prdy_vrss, ); }); } From 19fccb72de3a981e3a60a3724245163d04397953 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Mon, 11 Nov 2024 10:57:13 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=EB=B0=B1?= =?UTF-8?q?=EC=97=94=EB=93=9C=20=ED=8C=8C=EC=9D=BC=EB=AA=85=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/app.module.ts | 6 +++--- BE/src/auth/auth.controller.ts | 2 +- BE/src/auth/auth.service.ts | 2 +- ...{authCredentials.dto.ts => auth-credentials.dto.ts} | 0 BE/src/auth/user.repository.ts | 2 +- ...ment.interface.ts => korea-investment.interface.ts} | 0 ...investment.module.ts => korea-investment.module.ts} | 2 +- ...vestment.service.ts => korea-investment.service.ts} | 4 ++-- BE/src/stock/enum/{MarketType.ts => market-type.ts} | 0 ...nt.dto.ts => stock-index-list-chart.element.dto.ts} | 0 ...ment.dto.ts => stock-index-response-element.dto.ts} | 4 ++-- ...dex.response.dto.ts => stock-index-response.dto.ts} | 2 +- ...element.dto.ts => stock-index-value-element.dto.ts} | 0 ...ock.index.interface.ts => stock-index.interface.ts} | 0 ...k.index.controller.ts => stock-index.controller.ts} | 6 +++--- .../{stock.index.module.ts => stock-index.module.ts} | 6 +++--- .../{stock.index.service.ts => stock-index.service.ts} | 10 +++++----- ...topfive.interface.ts => stock-topfive.interface.ts} | 0 ...pfive.controller.ts => stock-topfive.controller.ts} | 4 ++-- ...stock.topfive.module.ts => stock-topfive.module.ts} | 6 +++--- ...ock.topfive.service.ts => stock-topfive.service.ts} | 10 +++++----- BE/src/util/{getFullURL.ts => get-full-URL.ts} | 0 BE/src/util/{getHeader.ts => get-header.ts} | 0 BE/src/websocket/socket.service.ts | 4 ++-- BE/test/stock/index/stock.index.list.e2e-spec.ts | 2 +- BE/test/stock/index/stock.index.value.e2e-spec.ts | 2 +- 26 files changed, 37 insertions(+), 37 deletions(-) rename BE/src/auth/dto/{authCredentials.dto.ts => auth-credentials.dto.ts} (100%) rename BE/src/koreaInvestment/interface/{korea.investment.interface.ts => korea-investment.interface.ts} (100%) rename BE/src/koreaInvestment/{korea.investment.module.ts => korea-investment.module.ts} (76%) rename BE/src/koreaInvestment/{korea.investment.service.ts => korea-investment.service.ts} (89%) rename BE/src/stock/enum/{MarketType.ts => market-type.ts} (100%) rename BE/src/stock/index/dto/{stock.index.list.chart.element.dto.ts => stock-index-list-chart.element.dto.ts} (100%) rename BE/src/stock/index/dto/{stock.index.response.element.dto.ts => stock-index-response-element.dto.ts} (71%) rename BE/src/stock/index/dto/{stock.index.response.dto.ts => stock-index-response.dto.ts} (88%) rename BE/src/stock/index/dto/{stock.index.value.element.dto.ts => stock-index-value-element.dto.ts} (100%) rename BE/src/stock/index/interface/{stock.index.interface.ts => stock-index.interface.ts} (100%) rename BE/src/stock/index/{stock.index.controller.ts => stock-index.controller.ts} (96%) rename BE/src/stock/index/{stock.index.module.ts => stock-index.module.ts} (71%) rename BE/src/stock/index/{stock.index.service.ts => stock-index.service.ts} (87%) rename BE/src/stock/topfive/interface/{stock.topfive.interface.ts => stock-topfive.interface.ts} (100%) rename BE/src/stock/topfive/{stock.topfive.controller.ts => stock-topfive.controller.ts} (88%) rename BE/src/stock/topfive/{stock.topfive.module.ts => stock-topfive.module.ts} (68%) rename BE/src/stock/topfive/{stock.topfive.service.ts => stock-topfive.service.ts} (95%) rename BE/src/util/{getFullURL.ts => get-full-URL.ts} (100%) rename BE/src/util/{getHeader.ts => get-header.ts} (100%) diff --git a/BE/src/app.module.ts b/BE/src/app.module.ts index fbef051f..114ecadf 100644 --- a/BE/src/app.module.ts +++ b/BE/src/app.module.ts @@ -6,9 +6,9 @@ import { AppController } from './app.controller'; import { AppService } from './app.service'; import { AuthModule } from './auth/auth.module'; import { User } from './auth/user.entity'; -import { StockIndexModule } from './stock/index/stock.index.module'; -import { StockTopfiveModule } from './stock/topfive/stock.topfive.module'; -import { KoreaInvestmentModule } from './koreaInvestment/korea.investment.module'; +import { StockIndexModule } from './stock/index/stock-index.module'; +import { StockTopfiveModule } from './stock/topfive/stock-topfive.module'; +import { KoreaInvestmentModule } from './koreaInvestment/korea-investment.module'; import { SocketModule } from './websocket/socket.module'; @Module({ diff --git a/BE/src/auth/auth.controller.ts b/BE/src/auth/auth.controller.ts index 8411eb48..aee104f0 100644 --- a/BE/src/auth/auth.controller.ts +++ b/BE/src/auth/auth.controller.ts @@ -10,7 +10,7 @@ import { import { AuthGuard } from '@nestjs/passport'; import { ApiOperation } from '@nestjs/swagger'; import { AuthService } from './auth.service'; -import { AuthCredentialsDto } from './dto/authCredentials.dto'; +import { AuthCredentialsDto } from './dto/auth-credentials.dto'; @Controller('auth') export class AuthController { diff --git a/BE/src/auth/auth.service.ts b/BE/src/auth/auth.service.ts index cbc4a69f..6f751e1b 100644 --- a/BE/src/auth/auth.service.ts +++ b/BE/src/auth/auth.service.ts @@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { JwtService } from '@nestjs/jwt'; import * as bcrypt from 'bcrypt'; import { UserRepository } from './user.repository'; -import { AuthCredentialsDto } from './dto/authCredentials.dto'; +import { AuthCredentialsDto } from './dto/auth-credentials.dto'; @Injectable() export class AuthService { diff --git a/BE/src/auth/dto/authCredentials.dto.ts b/BE/src/auth/dto/auth-credentials.dto.ts similarity index 100% rename from BE/src/auth/dto/authCredentials.dto.ts rename to BE/src/auth/dto/auth-credentials.dto.ts diff --git a/BE/src/auth/user.repository.ts b/BE/src/auth/user.repository.ts index 0a23f980..429437e7 100644 --- a/BE/src/auth/user.repository.ts +++ b/BE/src/auth/user.repository.ts @@ -3,7 +3,7 @@ import { InjectDataSource } from '@nestjs/typeorm'; import { DataSource, Repository } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { User } from './user.entity'; -import { AuthCredentialsDto } from './dto/authCredentials.dto'; +import { AuthCredentialsDto } from './dto/auth-credentials.dto'; @Injectable() export class UserRepository extends Repository { diff --git a/BE/src/koreaInvestment/interface/korea.investment.interface.ts b/BE/src/koreaInvestment/interface/korea-investment.interface.ts similarity index 100% rename from BE/src/koreaInvestment/interface/korea.investment.interface.ts rename to BE/src/koreaInvestment/interface/korea-investment.interface.ts diff --git a/BE/src/koreaInvestment/korea.investment.module.ts b/BE/src/koreaInvestment/korea-investment.module.ts similarity index 76% rename from BE/src/koreaInvestment/korea.investment.module.ts rename to BE/src/koreaInvestment/korea-investment.module.ts index 69679c6b..8e7dd10a 100644 --- a/BE/src/koreaInvestment/korea.investment.module.ts +++ b/BE/src/koreaInvestment/korea-investment.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import { KoreaInvestmentService } from './korea.investment.service'; +import { KoreaInvestmentService } from './korea-investment.service'; @Module({ imports: [], diff --git a/BE/src/koreaInvestment/korea.investment.service.ts b/BE/src/koreaInvestment/korea-investment.service.ts similarity index 89% rename from BE/src/koreaInvestment/korea.investment.service.ts rename to BE/src/koreaInvestment/korea-investment.service.ts index 727c044c..29dc323c 100644 --- a/BE/src/koreaInvestment/korea.investment.service.ts +++ b/BE/src/koreaInvestment/korea-investment.service.ts @@ -1,7 +1,7 @@ import axios from 'axios'; import { UnauthorizedException } from '@nestjs/common'; -import { getFullURL } from '../util/getFullURL'; -import { AccessTokenInterface } from './interface/korea.investment.interface'; +import { getFullURL } from '../util/get-full-URL'; +import { AccessTokenInterface } from './interface/korea-investment.interface'; export class KoreaInvestmentService { private accessToken: string; diff --git a/BE/src/stock/enum/MarketType.ts b/BE/src/stock/enum/market-type.ts similarity index 100% rename from BE/src/stock/enum/MarketType.ts rename to BE/src/stock/enum/market-type.ts diff --git a/BE/src/stock/index/dto/stock.index.list.chart.element.dto.ts b/BE/src/stock/index/dto/stock-index-list-chart.element.dto.ts similarity index 100% rename from BE/src/stock/index/dto/stock.index.list.chart.element.dto.ts rename to BE/src/stock/index/dto/stock-index-list-chart.element.dto.ts diff --git a/BE/src/stock/index/dto/stock.index.response.element.dto.ts b/BE/src/stock/index/dto/stock-index-response-element.dto.ts similarity index 71% rename from BE/src/stock/index/dto/stock.index.response.element.dto.ts rename to BE/src/stock/index/dto/stock-index-response-element.dto.ts index 09e21102..79cf6af5 100644 --- a/BE/src/stock/index/dto/stock.index.response.element.dto.ts +++ b/BE/src/stock/index/dto/stock-index-response-element.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -import { StockIndexValueElementDto } from './stock.index.value.element.dto'; -import { StockIndexListChartElementDto } from './stock.index.list.chart.element.dto'; +import { StockIndexValueElementDto } from './stock-index-value-element.dto'; +import { StockIndexListChartElementDto } from './stock-index-list-chart.element.dto'; export class StockIndexResponseElementDto { @ApiProperty({ description: '실시간 값', type: StockIndexValueElementDto }) diff --git a/BE/src/stock/index/dto/stock.index.response.dto.ts b/BE/src/stock/index/dto/stock-index-response.dto.ts similarity index 88% rename from BE/src/stock/index/dto/stock.index.response.dto.ts rename to BE/src/stock/index/dto/stock-index-response.dto.ts index 7f26af32..026fecf3 100644 --- a/BE/src/stock/index/dto/stock.index.response.dto.ts +++ b/BE/src/stock/index/dto/stock-index-response.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { StockIndexResponseElementDto } from './stock.index.response.element.dto'; +import { StockIndexResponseElementDto } from './stock-index-response-element.dto'; export class StockIndexResponseDto { @ApiProperty({ diff --git a/BE/src/stock/index/dto/stock.index.value.element.dto.ts b/BE/src/stock/index/dto/stock-index-value-element.dto.ts similarity index 100% rename from BE/src/stock/index/dto/stock.index.value.element.dto.ts rename to BE/src/stock/index/dto/stock-index-value-element.dto.ts diff --git a/BE/src/stock/index/interface/stock.index.interface.ts b/BE/src/stock/index/interface/stock-index.interface.ts similarity index 100% rename from BE/src/stock/index/interface/stock.index.interface.ts rename to BE/src/stock/index/interface/stock-index.interface.ts diff --git a/BE/src/stock/index/stock.index.controller.ts b/BE/src/stock/index/stock-index.controller.ts similarity index 96% rename from BE/src/stock/index/stock.index.controller.ts rename to BE/src/stock/index/stock-index.controller.ts index 7625e044..330685e2 100644 --- a/BE/src/stock/index/stock.index.controller.ts +++ b/BE/src/stock/index/stock-index.controller.ts @@ -1,9 +1,9 @@ import { Controller, Get } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { Cron } from '@nestjs/schedule'; -import { StockIndexService } from './stock.index.service'; -import { StockIndexResponseDto } from './dto/stock.index.response.dto'; -import { KoreaInvestmentService } from '../../koreaInvestment/korea.investment.service'; +import { StockIndexService } from './stock-index.service'; +import { StockIndexResponseDto } from './dto/stock-index-response.dto'; +import { KoreaInvestmentService } from '../../koreaInvestment/korea-investment.service'; import { SocketGateway } from '../../websocket/socket.gateway'; @Controller('/api/stocks/index') diff --git a/BE/src/stock/index/stock.index.module.ts b/BE/src/stock/index/stock-index.module.ts similarity index 71% rename from BE/src/stock/index/stock.index.module.ts rename to BE/src/stock/index/stock-index.module.ts index 1227e4f7..64e0c575 100644 --- a/BE/src/stock/index/stock.index.module.ts +++ b/BE/src/stock/index/stock-index.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; -import { StockIndexController } from './stock.index.controller'; -import { StockIndexService } from './stock.index.service'; -import { KoreaInvestmentModule } from '../../koreaInvestment/korea.investment.module'; +import { StockIndexController } from './stock-index.controller'; +import { StockIndexService } from './stock-index.service'; +import { KoreaInvestmentModule } from '../../koreaInvestment/korea-investment.module'; import { SocketModule } from '../../websocket/socket.module'; @Module({ diff --git a/BE/src/stock/index/stock.index.service.ts b/BE/src/stock/index/stock-index.service.ts similarity index 87% rename from BE/src/stock/index/stock.index.service.ts rename to BE/src/stock/index/stock-index.service.ts index f15326f5..fa05ed4c 100644 --- a/BE/src/stock/index/stock.index.service.ts +++ b/BE/src/stock/index/stock-index.service.ts @@ -1,13 +1,13 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common'; import axios from 'axios'; -import { StockIndexListChartElementDto } from './dto/stock.index.list.chart.element.dto'; -import { StockIndexValueElementDto } from './dto/stock.index.value.element.dto'; +import { StockIndexListChartElementDto } from './dto/stock-index-list-chart.element.dto'; +import { StockIndexValueElementDto } from './dto/stock-index-value-element.dto'; import { StockIndexChartInterface, StockIndexValueInterface, -} from './interface/stock.index.interface'; -import { getFullURL } from '../../util/getFullURL'; -import { getHeader } from '../../util/getHeader'; +} from './interface/stock-index.interface'; +import { getFullURL } from '../../util/get-full-URL'; +import { getHeader } from '../../util/get-header'; @Injectable() export class StockIndexService { diff --git a/BE/src/stock/topfive/interface/stock.topfive.interface.ts b/BE/src/stock/topfive/interface/stock-topfive.interface.ts similarity index 100% rename from BE/src/stock/topfive/interface/stock.topfive.interface.ts rename to BE/src/stock/topfive/interface/stock-topfive.interface.ts diff --git a/BE/src/stock/topfive/stock.topfive.controller.ts b/BE/src/stock/topfive/stock-topfive.controller.ts similarity index 88% rename from BE/src/stock/topfive/stock.topfive.controller.ts rename to BE/src/stock/topfive/stock-topfive.controller.ts index f90d300a..bac275e3 100644 --- a/BE/src/stock/topfive/stock.topfive.controller.ts +++ b/BE/src/stock/topfive/stock-topfive.controller.ts @@ -1,8 +1,8 @@ import { ApiOperation, ApiQuery, ApiResponse } from '@nestjs/swagger'; import { Controller, Get, Query } from '@nestjs/common'; -import { StockTopfiveService } from './stock.topfive.service'; +import { StockTopfiveService } from './stock-topfive.service'; import { StockRankingResponseDto } from './dto/stock-ranking-response.dto'; -import { MarketType } from '../enum/MarketType'; +import { MarketType } from '../enum/market-type'; @Controller('/api/stocks') export class StockTopfiveController { diff --git a/BE/src/stock/topfive/stock.topfive.module.ts b/BE/src/stock/topfive/stock-topfive.module.ts similarity index 68% rename from BE/src/stock/topfive/stock.topfive.module.ts rename to BE/src/stock/topfive/stock-topfive.module.ts index 33a63aae..5be62a4f 100644 --- a/BE/src/stock/topfive/stock.topfive.module.ts +++ b/BE/src/stock/topfive/stock-topfive.module.ts @@ -1,8 +1,8 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; -import { StockTopfiveController } from './stock.topfive.controller'; -import { StockTopfiveService } from './stock.topfive.service'; -import { KoreaInvestmentModule } from '../../koreaInvestment/korea.investment.module'; +import { StockTopfiveController } from './stock-topfive.controller'; +import { StockTopfiveService } from './stock-topfive.service'; +import { KoreaInvestmentModule } from '../../koreaInvestment/korea-investment.module'; @Module({ imports: [ConfigModule, KoreaInvestmentModule], diff --git a/BE/src/stock/topfive/stock.topfive.service.ts b/BE/src/stock/topfive/stock-topfive.service.ts similarity index 95% rename from BE/src/stock/topfive/stock.topfive.service.ts rename to BE/src/stock/topfive/stock-topfive.service.ts index d8da1643..82f659d5 100644 --- a/BE/src/stock/topfive/stock.topfive.service.ts +++ b/BE/src/stock/topfive/stock-topfive.service.ts @@ -3,14 +3,14 @@ import { Injectable, Logger } from '@nestjs/common'; import { StockRankingQueryParameterDto } from './dto/stock-ranking-request.dto'; import { StockRankingResponseDto } from './dto/stock-ranking-response.dto'; import { StockRankingDataDto } from './dto/stock-ranking-data.dto'; -import { MarketType } from '../enum/MarketType'; +import { MarketType } from '../enum/market-type'; import { StockApiOutputData, StockApiResponse, -} from './interface/stock.topfive.interface'; -import { getHeader } from '../../util/getHeader'; -import { getFullURL } from '../../util/getFullURL'; -import { KoreaInvestmentService } from '../../koreaInvestment/korea.investment.service'; +} from './interface/stock-topfive.interface'; +import { getHeader } from '../../util/get-header'; +import { getFullURL } from '../../util/get-full-URL'; +import { KoreaInvestmentService } from '../../koreaInvestment/korea-investment.service'; @Injectable() export class StockTopfiveService { diff --git a/BE/src/util/getFullURL.ts b/BE/src/util/get-full-URL.ts similarity index 100% rename from BE/src/util/getFullURL.ts rename to BE/src/util/get-full-URL.ts diff --git a/BE/src/util/getHeader.ts b/BE/src/util/get-header.ts similarity index 100% rename from BE/src/util/getHeader.ts rename to BE/src/util/get-header.ts diff --git a/BE/src/websocket/socket.service.ts b/BE/src/websocket/socket.service.ts index 042cd57a..0bcb7b64 100644 --- a/BE/src/websocket/socket.service.ts +++ b/BE/src/websocket/socket.service.ts @@ -2,9 +2,9 @@ import { Injectable, OnModuleInit } from '@nestjs/common'; import { WebSocket } from 'ws'; import axios from 'axios'; import { SocketGateway } from './socket.gateway'; -import { StockIndexValueElementDto } from '../stock/index/dto/stock.index.value.element.dto'; +import { StockIndexValueElementDto } from '../stock/index/dto/stock-index-value-element.dto'; import { SocketConnectTokenInterface } from './interface/socket.interface'; -import { getFullURL } from '../util/getFullURL'; +import { getFullURL } from '../util/get-full-URL'; @Injectable() export class SocketService implements OnModuleInit { diff --git a/BE/test/stock/index/stock.index.list.e2e-spec.ts b/BE/test/stock/index/stock.index.list.e2e-spec.ts index 7518b75d..9a844581 100644 --- a/BE/test/stock/index/stock.index.list.e2e-spec.ts +++ b/BE/test/stock/index/stock.index.list.e2e-spec.ts @@ -1,6 +1,6 @@ import { Test } from '@nestjs/testing'; import axios from 'axios'; -import { StockIndexService } from '../../../src/stock/index/stock.index.service'; +import { StockIndexService } from '../../../src/stock/index/stock-index.service'; import { STOCK_INDEX_LIST_MOCK } from './mockdata/stock.index.list.mockdata'; jest.mock('axios'); diff --git a/BE/test/stock/index/stock.index.value.e2e-spec.ts b/BE/test/stock/index/stock.index.value.e2e-spec.ts index 12ff2590..2008f2e4 100644 --- a/BE/test/stock/index/stock.index.value.e2e-spec.ts +++ b/BE/test/stock/index/stock.index.value.e2e-spec.ts @@ -1,6 +1,6 @@ import { Test } from '@nestjs/testing'; import axios from 'axios'; -import { StockIndexService } from '../../../src/stock/index/stock.index.service'; +import { StockIndexService } from '../../../src/stock/index/stock-index.service'; import { STOCK_INDEX_VALUE_MOCK } from './mockdata/stock.index.value.mockdata'; jest.mock('axios');