From e7ae190050948b421279c63148babb736ed134c4 Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:25:05 +0900 Subject: [PATCH 1/9] =?UTF-8?q?=E2=9C=A8=20feat:=20API=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=B4=20chart=20=EC=A0=84?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ....dto.ts => stock-detail-chart-data.dto.ts} | 2 +- .../dto/stock-detail-chart-response.dto.ts | 5 + .../detail/dto/stock-detail-response.dto.ts | 14 --- .../stock/detail/stock-detail.controller.ts | 6 +- BE/src/stock/detail/stock-detail.service.ts | 98 +++++++------------ 5 files changed, 42 insertions(+), 83 deletions(-) rename BE/src/stock/detail/dto/{stock-detail-output2.dto.ts => stock-detail-chart-data.dto.ts} (96%) create mode 100644 BE/src/stock/detail/dto/stock-detail-chart-response.dto.ts delete mode 100644 BE/src/stock/detail/dto/stock-detail-response.dto.ts diff --git a/BE/src/stock/detail/dto/stock-detail-output2.dto.ts b/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts similarity index 96% rename from BE/src/stock/detail/dto/stock-detail-output2.dto.ts rename to BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts index c6df900f..fd108090 100644 --- a/BE/src/stock/detail/dto/stock-detail-output2.dto.ts +++ b/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -export class InquirePriceOutput2Dto { +export class InquirePriceChartDataDto { @ApiProperty({ description: '주식 영업 일자' }) stck_bsop_date: string; diff --git a/BE/src/stock/detail/dto/stock-detail-chart-response.dto.ts b/BE/src/stock/detail/dto/stock-detail-chart-response.dto.ts new file mode 100644 index 00000000..3c580851 --- /dev/null +++ b/BE/src/stock/detail/dto/stock-detail-chart-response.dto.ts @@ -0,0 +1,5 @@ +import { InquirePriceChartDataDto } from './stock-detail-chart-data.dto'; + +export class InquirePriceChartResponseDto { + output: InquirePriceChartDataDto[]; +} diff --git a/BE/src/stock/detail/dto/stock-detail-response.dto.ts b/BE/src/stock/detail/dto/stock-detail-response.dto.ts deleted file mode 100644 index a86f9e04..00000000 --- a/BE/src/stock/detail/dto/stock-detail-response.dto.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { InquirePriceOutput1Dto } from './stock-detail-output1.dto'; -import { InquirePriceOutput2Dto } from './stock-detail-output2.dto'; - -/** - * 국내주식기간별시세(일/주/월/년) API 응답값 정제 후 FE에 보낼 DTO - */ -export class InquirePriceResponseDto { - @ApiProperty({ type: InquirePriceOutput1Dto, description: '상승률 순위' }) - output1: InquirePriceOutput1Dto; - - @ApiProperty({ type: [InquirePriceOutput2Dto], description: '하락률 순위' }) - output2: InquirePriceOutput2Dto[]; -} diff --git a/BE/src/stock/detail/stock-detail.controller.ts b/BE/src/stock/detail/stock-detail.controller.ts index 5c4cfa85..64509746 100644 --- a/BE/src/stock/detail/stock-detail.controller.ts +++ b/BE/src/stock/detail/stock-detail.controller.ts @@ -2,7 +2,7 @@ import { Body, Controller, Param, Post } from '@nestjs/common'; import { ApiBody, ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger'; import { StockDetailService } from './stock-detail.service'; import { StockDetailRequestDto } from './dto/stock-detail-request.dto'; -import { InquirePriceResponseDto } from './dto/stock-detail-response.dto'; +import { InquirePriceChartResponseDto } from './dto/stock-detail-chart-response.dto'; @Controller('/api/stocks') export class StockDetailController { @@ -28,14 +28,14 @@ export class StockDetailController { @ApiResponse({ status: 201, description: '단일 주식 종목 기본값 조회 성공', - type: InquirePriceResponseDto, + type: InquirePriceChartResponseDto, }) getStockDetail( @Param('stockCode') stockCode: string, @Body() body: StockDetailRequestDto, ) { const { fid_input_date_1, fid_input_date_2, fid_period_div_code } = body; - return this.stockDetailService.getInquirePrice( + return this.stockDetailService.getInquirePriceChart( stockCode, fid_input_date_1, fid_input_date_2, diff --git a/BE/src/stock/detail/stock-detail.service.ts b/BE/src/stock/detail/stock-detail.service.ts index c0629406..a454beec 100644 --- a/BE/src/stock/detail/stock-detail.service.ts +++ b/BE/src/stock/detail/stock-detail.service.ts @@ -4,8 +4,7 @@ import { KoreaInvestmentService } from '../../koreaInvestment/korea-investment.s import { getHeader } from '../../util/get-header'; import { getFullURL } from '../../util/get-full-URL'; import { InquirePriceApiResponse } from './interface/stock-detail.interface'; -import { StockDetailQueryParameterDto } from './dto/stock-detail-query-parameter.dto'; -import { InquirePriceResponseDto } from './dto/stock-detail-response.dto'; +import { InquirePriceChartResponseDto } from './dto/stock-detail-chart-response.dto'; @Injectable() export class StockDetailService { @@ -23,23 +22,29 @@ export class StockDetailService { * * @author uuuo3o */ - async getInquirePrice( + async getInquirePriceChart( stockCode: string, date1: string, date2: string, periodDivCode: string, ) { try { - const queryParams = new StockDetailQueryParameterDto(); - queryParams.fid_cond_mrkt_div_code = 'J'; - queryParams.fid_input_iscd = stockCode; - queryParams.fid_input_date_1 = date1; - queryParams.fid_input_date_2 = date2; - queryParams.fid_period_div_code = periodDivCode; + const queryParams = { + fid_cond_mrkt_div_code: 'J', + fid_input_iscd: stockCode, + fid_input_date_1: date1, + fid_input_date_2: date2, + fid_period_div_code: periodDivCode, + fid_org_adj_prc: '0', + }; - const response = await this.requestApi(queryParams); + const response = await this.requestApi( + 'FHKST03010100', + '/uapi/domestic-stock/v1/quotations/inquire-daily-itemchartprice', + queryParams, + ); - return this.formatStockData(response); + return this.formatStockInquirePriceData(response); } catch (error) { this.logger.error('API Error Details:', { status: error.response?.status, @@ -53,22 +58,25 @@ export class StockDetailService { } /** - * @private 한국투자 Open API - [국내주식] 기본시세 - 국내주식기간별시세(일/주/월/년) 호출 함수 - * @param {StockDetailQueryParameterDto} queryParams - API 요청 시 필요한 쿼리 파라미터 DTO - * @returns - 국내주식기간별시세(일/주/월/년) 데이터 + * @private 한국투자 Open API - API 호출용 공통 함수 + * @param {string} trId - API 호출에 사용할 tr_id + * @param {string} apiURL - API 호출에 사용할 URL + * @param {Record} params - API 요청 시 필요한 쿼리 파라미터 DTO + * @returns - API 호출에 대한 응답 데이터 * * @author uuuo3o */ - private async requestApi(queryParams: StockDetailQueryParameterDto) { + private async requestApi( + trId: string, + apiURL: string, + params: Record, + ): Promise { try { const accessToken = await this.koreaInvetmentService.getAccessToken(); - const headers = getHeader(accessToken, 'FHKST03010100'); - const url = getFullURL( - '/uapi/domestic-stock/v1/quotations/inquire-daily-itemchartprice', - ); - const params = this.getInquirePriceParams(queryParams); + const headers = getHeader(accessToken, trId); + const url = getFullURL(apiURL); - const response = await axios.get(url, { + const response = await axios.get(url, { headers, params, }); @@ -93,52 +101,12 @@ export class StockDetailService { * * @author uuuo3o */ - private formatStockData(response: InquirePriceApiResponse) { - const stockData = new InquirePriceResponseDto(); - const { output1, output2 } = response; - - const { - hts_kor_isnm, - stck_shrn_iscd, - stck_prpr, - prdy_vrss, - prdy_vrss_sign, - prdy_ctrt, - hts_avls, - per, - } = output1; - - stockData.output1 = { - hts_kor_isnm, - stck_shrn_iscd, - stck_prpr, - prdy_vrss, - prdy_vrss_sign, - prdy_ctrt, - hts_avls, - per, - }; + private formatStockInquirePriceData(response: InquirePriceApiResponse) { + const stockData = new InquirePriceChartResponseDto(); + const { output2 } = response; - stockData.output2 = output2; + stockData.output = output2; return stockData; } - - /** - * @private 국내주식기간별시세(일/주/월/년) 요청을 위한 쿼리 파라미터 객체 생성 함수 - * @param {StockDetailQueryParameterDto} params - API 요청에 필요한 쿼리 파라미터 DTO - * @returns - API 요청에 필요한 쿼리 파라미터 객체 - * - * @author uuuo3o - */ - private getInquirePriceParams(params: StockDetailQueryParameterDto) { - return { - fid_cond_mrkt_div_code: params.fid_cond_mrkt_div_code, - fid_input_iscd: params.fid_input_iscd, - fid_input_date_1: params.fid_input_date_1, - fid_input_date_2: params.fid_input_date_2, - fid_period_div_code: params.fid_period_div_code, - fid_org_adj_prc: 0, - }; - } } From 5989e081812c065013a154854bd0f07def6f5a2e Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:34:13 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=E2=9C=A8=20feat:=20=ED=94=84=EB=A1=A0?= =?UTF-8?q?=ED=8A=B8=EC=97=90=EC=84=9C=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EA=B0=92=EB=A7=8C=20=EB=B0=98=ED=99=98=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20DTO=20=EC=88=98=EC=A0=95#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/dto/stock-detail-chart-data.dto.ts | 21 ---------------- BE/src/stock/detail/stock-detail.service.ts | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts b/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts index fd108090..4574d3a7 100644 --- a/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts +++ b/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts @@ -18,25 +18,4 @@ export class InquirePriceChartDataDto { @ApiProperty({ description: '누적 거래량' }) acml_vol: string; - - @ApiProperty({ description: '누적 거래 대금' }) - acml_tr_pbmn: string; - - @ApiProperty({ description: '락 구분 코드' }) - flng_cls_code: string; - - @ApiProperty({ description: '분할 비율' }) - prtt_rate: string; - - @ApiProperty({ description: '분할변경여부' }) - mod_yn: string; - - @ApiProperty({ description: '전일 대비 부호' }) - prdy_vrss_sign: string; - - @ApiProperty({ description: '전일 대비' }) - prdy_vrss: string; - - @ApiProperty({ description: '재평가사유코드' }) - revl_issu_reas: string; } diff --git a/BE/src/stock/detail/stock-detail.service.ts b/BE/src/stock/detail/stock-detail.service.ts index a454beec..b47a6606 100644 --- a/BE/src/stock/detail/stock-detail.service.ts +++ b/BE/src/stock/detail/stock-detail.service.ts @@ -4,7 +4,7 @@ import { KoreaInvestmentService } from '../../koreaInvestment/korea-investment.s import { getHeader } from '../../util/get-header'; import { getFullURL } from '../../util/get-full-URL'; import { InquirePriceApiResponse } from './interface/stock-detail.interface'; -import { InquirePriceChartResponseDto } from './dto/stock-detail-chart-response.dto'; +import { InquirePriceChartDataDto } from './dto/stock-detail-chart-data.dto'; @Injectable() export class StockDetailService { @@ -102,11 +102,27 @@ export class StockDetailService { * @author uuuo3o */ private formatStockInquirePriceData(response: InquirePriceApiResponse) { - const stockData = new InquirePriceChartResponseDto(); const { output2 } = response; - stockData.output = output2; + return output2.map((info) => { + const stockData = new InquirePriceChartDataDto(); + const { + stck_bsop_date, + stck_clpr, + stck_oprc, + stck_hgpr, + stck_lwpr, + acml_vol, + } = info; - return stockData; + stockData.stck_bsop_date = stck_bsop_date; + stockData.stck_clpr = stck_clpr; + stockData.stck_oprc = stck_oprc; + stockData.stck_hgpr = stck_hgpr; + stockData.stck_lwpr = stck_lwpr; + stockData.acml_vol = acml_vol; + + return stockData; + }); } } From b0b6d8d115308fd7bdf0b8273346f9793bffd142 Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:36:22 +0900 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=8E=A8=20style:=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/stock/detail/stock-detail.service.ts | 64 ++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/BE/src/stock/detail/stock-detail.service.ts b/BE/src/stock/detail/stock-detail.service.ts index b47a6606..ef463dc7 100644 --- a/BE/src/stock/detail/stock-detail.service.ts +++ b/BE/src/stock/detail/stock-detail.service.ts @@ -57,6 +57,38 @@ export class StockDetailService { } } + /** + * @private API에서 받은 국내주식기간별시세(일/주/월/년) 데이터를 필요한 정보로 정제하는 함수 + * @param {InquirePriceApiResponse} response - API 응답에서 받은 원시 데이터 + * @returns - 필요한 정보만 추출한 데이터 배열 + * + * @author uuuo3o + */ + private formatStockInquirePriceData(response: InquirePriceApiResponse) { + const { output2 } = response; + + return output2.map((info) => { + const stockData = new InquirePriceChartDataDto(); + const { + stck_bsop_date, + stck_clpr, + stck_oprc, + stck_hgpr, + stck_lwpr, + acml_vol, + } = info; + + stockData.stck_bsop_date = stck_bsop_date; + stockData.stck_clpr = stck_clpr; + stockData.stck_oprc = stck_oprc; + stockData.stck_hgpr = stck_hgpr; + stockData.stck_lwpr = stck_lwpr; + stockData.acml_vol = acml_vol; + + return stockData; + }); + } + /** * @private 한국투자 Open API - API 호출용 공통 함수 * @param {string} trId - API 호출에 사용할 tr_id @@ -93,36 +125,4 @@ export class StockDetailService { throw error; } } - - /** - * @private API에서 받은 국내주식기간별시세(일/주/월/년) 데이터를 필요한 정보로 정제하는 함수 - * @param {InquirePriceApiResponse} response - API 응답에서 받은 원시 데이터 - * @returns - 필요한 정보만 추출한 데이터 배열 - * - * @author uuuo3o - */ - private formatStockInquirePriceData(response: InquirePriceApiResponse) { - const { output2 } = response; - - return output2.map((info) => { - const stockData = new InquirePriceChartDataDto(); - const { - stck_bsop_date, - stck_clpr, - stck_oprc, - stck_hgpr, - stck_lwpr, - acml_vol, - } = info; - - stockData.stck_bsop_date = stck_bsop_date; - stockData.stck_clpr = stck_clpr; - stockData.stck_oprc = stck_oprc; - stockData.stck_hgpr = stck_hgpr; - stockData.stck_lwpr = stck_lwpr; - stockData.acml_vol = acml_vol; - - return stockData; - }); - } } From 153e023e3b45696baf3d63d6a142704a20967e58 Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:36:33 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=94=A5=20remove:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/stock-detail-query-parameter.dto.ts | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 BE/src/stock/detail/dto/stock-detail-query-parameter.dto.ts diff --git a/BE/src/stock/detail/dto/stock-detail-query-parameter.dto.ts b/BE/src/stock/detail/dto/stock-detail-query-parameter.dto.ts deleted file mode 100644 index feb9ca0f..00000000 --- a/BE/src/stock/detail/dto/stock-detail-query-parameter.dto.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 주식 현재가 시세 API를 사용할 때 쿼리 파라미터로 사용할 요청값 DTO - */ -export class StockDetailQueryParameterDto { - /** - * 조건 시장 분류 코드 - * 'J' 주식 - */ - fid_cond_mrkt_div_code: string; - - /** - * 주식 종목 코드 - * (ex) 005930 - */ - fid_input_iscd: string; - - /** - * 조회 시작일자 - * (ex) 20220501 - */ - fid_input_date_1: string; - - /** - * 조회 종료일자 - * (ex) 20220530 - */ - fid_input_date_2: string; - - /** - * 기간 분류 코드 - * D:일봉, W:주봉, M:월봉, Y:년봉 - */ - fid_period_div_code: string; -} From c7561727ed5fdffd302fad16733eab9fec970c66 Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:41:07 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=93=9D=20docs:=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20swagger=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=20=EC=88=98=EC=A0=95#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...equest.dto.ts => stock-detail-chart-request.dto.ts} | 2 +- BE/src/stock/detail/stock-detail.controller.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename BE/src/stock/detail/dto/{stock-detail-request.dto.ts => stock-detail-chart-request.dto.ts} (92%) diff --git a/BE/src/stock/detail/dto/stock-detail-request.dto.ts b/BE/src/stock/detail/dto/stock-detail-chart-request.dto.ts similarity index 92% rename from BE/src/stock/detail/dto/stock-detail-request.dto.ts rename to BE/src/stock/detail/dto/stock-detail-chart-request.dto.ts index 7bd1b1d8..4a21bbc3 100644 --- a/BE/src/stock/detail/dto/stock-detail-request.dto.ts +++ b/BE/src/stock/detail/dto/stock-detail-chart-request.dto.ts @@ -3,7 +3,7 @@ import { ApiProperty } from '@nestjs/swagger'; /** * 국내주식기간별시세(일/주/월/년) API를 이용할 때 필요한 요청 데이터를 담고 있는 DTO */ -export class StockDetailRequestDto { +export class StockDetailChartRequestDto { @ApiProperty({ description: '조회 시작일자 (ex) 20220501' }) fid_input_date_1: string; diff --git a/BE/src/stock/detail/stock-detail.controller.ts b/BE/src/stock/detail/stock-detail.controller.ts index 64509746..86149af2 100644 --- a/BE/src/stock/detail/stock-detail.controller.ts +++ b/BE/src/stock/detail/stock-detail.controller.ts @@ -1,7 +1,7 @@ import { Body, Controller, Param, Post } from '@nestjs/common'; import { ApiBody, ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger'; import { StockDetailService } from './stock-detail.service'; -import { StockDetailRequestDto } from './dto/stock-detail-request.dto'; +import { StockDetailChartRequestDto } from './dto/stock-detail-chart-request.dto'; import { InquirePriceChartResponseDto } from './dto/stock-detail-chart-response.dto'; @Controller('/api/stocks') @@ -9,7 +9,7 @@ export class StockDetailController { constructor(private readonly stockDetailService: StockDetailService) {} @Post(':stockCode') - @ApiOperation({ summary: '단일 주식 종목 detail 페이지 상단부 조회 API' }) + @ApiOperation({ summary: '국내주식기간별시세(일/주/월/년) 조회 API' }) @ApiParam({ name: 'stockCode', required: true, @@ -23,16 +23,16 @@ export class StockDetailController { 'fid_input_date_1: 조회 시작일자 (ex) 20240505\n\n' + 'fid_input_date_2: 조회 종료일자 (ex) 20241111\n\n' + 'fid_period_div_code: 기간 분류 코드 (ex) D(일봉), W(주봉), M(월봉), Y(년봉)', - type: StockDetailRequestDto, + type: StockDetailChartRequestDto, }) @ApiResponse({ status: 201, - description: '단일 주식 종목 기본값 조회 성공', + description: '국내주식기간별시세(일/주/월/년) 조회 성공', type: InquirePriceChartResponseDto, }) getStockDetail( @Param('stockCode') stockCode: string, - @Body() body: StockDetailRequestDto, + @Body() body: StockDetailChartRequestDto, ) { const { fid_input_date_1, fid_input_date_2, fid_period_div_code } = body; return this.stockDetailService.getInquirePriceChart( From a6eeef40be6484c5f8479a4bd4295022cf7b6bcc Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:46:25 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=E2=9E=95=20add:=20=EC=B0=A8=ED=8A=B8=20?= =?UTF-8?q?=EA=B7=B8=EB=A6=AC=EA=B8=B0=EC=97=90=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B0=92=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts | 3 +++ ...ck-detail.interface.ts => stock-detail-chart.interface.ts} | 0 BE/src/stock/detail/stock-detail.service.ts | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) rename BE/src/stock/detail/interface/{stock-detail.interface.ts => stock-detail-chart.interface.ts} (100%) diff --git a/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts b/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts index 4574d3a7..de68279f 100644 --- a/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts +++ b/BE/src/stock/detail/dto/stock-detail-chart-data.dto.ts @@ -18,4 +18,7 @@ export class InquirePriceChartDataDto { @ApiProperty({ description: '누적 거래량' }) acml_vol: string; + + @ApiProperty({ description: '전일 대비 부호' }) + prdy_vrss_sign: string; } diff --git a/BE/src/stock/detail/interface/stock-detail.interface.ts b/BE/src/stock/detail/interface/stock-detail-chart.interface.ts similarity index 100% rename from BE/src/stock/detail/interface/stock-detail.interface.ts rename to BE/src/stock/detail/interface/stock-detail-chart.interface.ts diff --git a/BE/src/stock/detail/stock-detail.service.ts b/BE/src/stock/detail/stock-detail.service.ts index ef463dc7..e66b0736 100644 --- a/BE/src/stock/detail/stock-detail.service.ts +++ b/BE/src/stock/detail/stock-detail.service.ts @@ -3,7 +3,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { KoreaInvestmentService } from '../../koreaInvestment/korea-investment.service'; import { getHeader } from '../../util/get-header'; import { getFullURL } from '../../util/get-full-URL'; -import { InquirePriceApiResponse } from './interface/stock-detail.interface'; +import { InquirePriceApiResponse } from './interface/stock-detail-chart.interface'; import { InquirePriceChartDataDto } from './dto/stock-detail-chart-data.dto'; @Injectable() @@ -76,6 +76,7 @@ export class StockDetailService { stck_hgpr, stck_lwpr, acml_vol, + prdy_vrss_sign, } = info; stockData.stck_bsop_date = stck_bsop_date; @@ -84,6 +85,7 @@ export class StockDetailService { stockData.stck_hgpr = stck_hgpr; stockData.stck_lwpr = stck_lwpr; stockData.acml_vol = acml_vol; + stockData.prdy_vrss_sign = prdy_vrss_sign; return stockData; }); From 99a94fac8e13b6191e4c7ff740eafa11ca792ed9 Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 17:59:50 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=9A=9A=20rename:=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/stock/detail/interface/stock-detail-chart.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BE/src/stock/detail/interface/stock-detail-chart.interface.ts b/BE/src/stock/detail/interface/stock-detail-chart.interface.ts index 1169eb90..e49746e9 100644 --- a/BE/src/stock/detail/interface/stock-detail-chart.interface.ts +++ b/BE/src/stock/detail/interface/stock-detail-chart.interface.ts @@ -47,7 +47,7 @@ export interface InquirePriceOutput2Data { revl_issu_reas: string; } -export interface InquirePriceApiResponse { +export interface InquirePriceChartApiResponse { output1: InquirePriceOutput1Data; output2: InquirePriceOutput2Data[]; rt_cd: string; From fc9a9170ced449e3a18e8883a210fff71f63fb76 Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 18:01:38 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A3=BC=EC=8B=9D=20?= =?UTF-8?q?=ED=98=84=EC=9E=AC=EA=B0=80=20API=EC=97=90=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20interface,=20dto=20=EA=B5=AC=ED=98=84#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t1.dto.ts => stock-detail-response.dto.ts} | 2 +- .../interface/stock-detail.interface.ts | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) rename BE/src/stock/detail/dto/{stock-detail-output1.dto.ts => stock-detail-response.dto.ts} (94%) create mode 100644 BE/src/stock/detail/interface/stock-detail.interface.ts diff --git a/BE/src/stock/detail/dto/stock-detail-output1.dto.ts b/BE/src/stock/detail/dto/stock-detail-response.dto.ts similarity index 94% rename from BE/src/stock/detail/dto/stock-detail-output1.dto.ts rename to BE/src/stock/detail/dto/stock-detail-response.dto.ts index aa911bd1..96e4ba52 100644 --- a/BE/src/stock/detail/dto/stock-detail-output1.dto.ts +++ b/BE/src/stock/detail/dto/stock-detail-response.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -export class InquirePriceOutput1Dto { +export class InquirePriceResponseDto { @ApiProperty({ description: 'HTS 한글 종목명' }) hts_kor_isnm: string; diff --git a/BE/src/stock/detail/interface/stock-detail.interface.ts b/BE/src/stock/detail/interface/stock-detail.interface.ts new file mode 100644 index 00000000..1cef7848 --- /dev/null +++ b/BE/src/stock/detail/interface/stock-detail.interface.ts @@ -0,0 +1,84 @@ +export interface InquirePriceOutputData { + iscd_stat_cls_code: string; + marg_rate: string; + rprs_mrkt_kor_name: string; + new_hgpr_lwpr_cls_code: string; + btsp_kor_isnm: string; + temp_stop_yn: string; + oprc_rang_cont_yn: string; + clpr_rang_cont_yn: string; + crdt_able_yn: string; + grmn_rate_cls_code: string; + elw_pblc_yn: string; + stck_prpr: string; + prdy_vrss: string; + prdy_vrss_sign: string; + prdy_ctrt: string; + acml_tr_pbmn: string; + acml_vol: string; + prdy_vrss_vol_rate: string; + stck_oprc: string; + stck_hgpr: string; + stck_lwpr: string; + stck_mxpr: string; + stck_llam: string; + stck_sdpr: string; + wghn_avrg_stck_prc: string; + hts_frgn_ehrt: string; + frgn_ntby_qty: string; + pgtr_ntby_qty: string; + dmrs_val: string; + dmsp_val: string; + cpfn: string; + rstc_wdth_prc: string; + stck_fcam: string; + stck_sspr: string; + aspr_unit: string; + hts_deal_qty_unit_val: string; + lstn_stcn: string; + hts_avls: string; + per: string; + pbr: string; + stac_month: string; + vol_tnrt: string; + eps: string; + bps: string; + d250_hgpr: string; + d250_hgpr_date: string; + d250_hgpr_vrss_prpr_rate: string; + d250_lwpr: string; + d250_lwpr_date: string; + d250_lwpr_vrss_prpr_rate: string; + stck_dryy_hgpr: string; + dryy_hgpr_vrss_prpr_rate: string; + dryy_hgpr_date: string; + stck_dryy_lwpr: string; + dryy_lwpr_vrss_prpr_rate: string; + dryy_lwpr_date: string; + w52_hgpr: string; + w52_hgpr_vrss_prpr_ctrt: string; + w52_hgpr_date: string; + w52_lwpr: string; + w52_lwpr_vrss_prpr_ctrt: string; + w52_lwpr_date: string; + whol_loan_rmnd_rate: string; + ssts_yn: string; + stck_shrn_iscd: string; + fcam_cnnm: string; + cpfn_cnnm: string; + apprch_rate: string; + frgn_hldn_qty: string; + vi_cls_code: string; + ovtm_vi_cls_code: string; + last_ssts_cntg_qty: string; + invt_caful_yn: string; + mrkt_warn_cls_code: string; + short_over_yn: string; + sltr_yn: string; +} +export interface InquirePriceApiResponse { + output: InquirePriceOutputData; + rt_cd: string; + msg_cd: string; + msg1: string; +} From 5f7d33c2842bdabe1027b9d84ac69c8c703852af Mon Sep 17 00:00:00 2001 From: JIN Date: Wed, 13 Nov 2024 18:01:53 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=E2=9C=A8=20feat:=20=EC=A3=BC=EC=8B=9D=20?= =?UTF-8?q?=ED=98=84=EC=9E=AC=EA=B0=80=20API=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stock/detail/stock-detail.controller.ts | 23 ++++++- BE/src/stock/detail/stock-detail.service.ts | 63 ++++++++++++++++++- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/BE/src/stock/detail/stock-detail.controller.ts b/BE/src/stock/detail/stock-detail.controller.ts index 86149af2..533b67ca 100644 --- a/BE/src/stock/detail/stock-detail.controller.ts +++ b/BE/src/stock/detail/stock-detail.controller.ts @@ -1,6 +1,7 @@ -import { Body, Controller, Param, Post } from '@nestjs/common'; +import { Body, Controller, Get, Param, Post } from '@nestjs/common'; import { ApiBody, ApiOperation, ApiParam, ApiResponse } from '@nestjs/swagger'; import { StockDetailService } from './stock-detail.service'; +import { InquirePriceResponseDto } from './dto/stock-detail-response.dto'; import { StockDetailChartRequestDto } from './dto/stock-detail-chart-request.dto'; import { InquirePriceChartResponseDto } from './dto/stock-detail-chart-response.dto'; @@ -8,6 +9,24 @@ import { InquirePriceChartResponseDto } from './dto/stock-detail-chart-response. export class StockDetailController { constructor(private readonly stockDetailService: StockDetailService) {} + @Get(':stockCode') + @ApiOperation({ summary: '단일 주식 종목 detail 페이지 상단부 조회 API' }) + @ApiParam({ + name: 'stockCode', + required: true, + description: + '종목 코드\n' + + '(ex) 005930 삼성전자 / 005380 현대차 / 001500 현대차증권', + }) + @ApiResponse({ + status: 200, + description: '단일 주식 종목 기본값 조회 성공', + type: InquirePriceResponseDto, + }) + getStockDetail(@Param('stockCode') stockCode: string) { + return this.stockDetailService.getInquirePrice(stockCode); + } + @Post(':stockCode') @ApiOperation({ summary: '국내주식기간별시세(일/주/월/년) 조회 API' }) @ApiParam({ @@ -30,7 +49,7 @@ export class StockDetailController { description: '국내주식기간별시세(일/주/월/년) 조회 성공', type: InquirePriceChartResponseDto, }) - getStockDetail( + getStockDetailChart( @Param('stockCode') stockCode: string, @Body() body: StockDetailChartRequestDto, ) { diff --git a/BE/src/stock/detail/stock-detail.service.ts b/BE/src/stock/detail/stock-detail.service.ts index e66b0736..8031c4d6 100644 --- a/BE/src/stock/detail/stock-detail.service.ts +++ b/BE/src/stock/detail/stock-detail.service.ts @@ -3,8 +3,13 @@ import { Injectable, Logger } from '@nestjs/common'; import { KoreaInvestmentService } from '../../koreaInvestment/korea-investment.service'; import { getHeader } from '../../util/get-header'; import { getFullURL } from '../../util/get-full-URL'; -import { InquirePriceApiResponse } from './interface/stock-detail-chart.interface'; +import { InquirePriceChartApiResponse } from './interface/stock-detail-chart.interface'; import { InquirePriceChartDataDto } from './dto/stock-detail-chart-data.dto'; +import { + InquirePriceApiResponse, + InquirePriceOutputData, +} from './interface/stock-detail.interface'; +import { InquirePriceResponseDto } from './dto/stock-detail-response.dto'; @Injectable() export class StockDetailService { @@ -12,6 +17,58 @@ export class StockDetailService { constructor(private readonly koreaInvetmentService: KoreaInvestmentService) {} + /** + * 주식현재가 시세 데이터를 반환하는 함수 + * @param {string} stockCode - 종목코드 + * @returns - 주식현재가 시세 데이터 객체 반환 + * + * @author uuuo3o + */ + async getInquirePrice(stockCode: string) { + try { + const queryParams = { + fid_cond_mrkt_div_code: 'J', + fid_input_iscd: stockCode, + }; + + const response = await this.requestApi( + 'FHKST01010100', + '/uapi/domestic-stock/v1/quotations/inquire-price', + queryParams, + ); + + return this.formatStockData(response.output); + } catch (error) { + this.logger.error('API Error Details:', { + status: error.response?.status, + statusText: error.response?.statusText, + data: error.response?.data, + headers: error.response?.config?.headers, // 실제 요청 헤더 + message: error.message, + }); + throw error; + } + } + + /** + * @private API에서 받은 주식현재가 시세 데이터를 필요한 정보로 정제하는 함수 + * @param {InquirePriceOutputData} stock - API 응답에서 받은 원시 데이터 + * @returns - 필요한 정보만 추출한 데이터 배열 + * + * @author uuuo3o + */ + private formatStockData(stock: InquirePriceOutputData) { + const stockData = new InquirePriceResponseDto(); + stockData.stck_shrn_iscd = stock.stck_shrn_iscd; + stockData.stck_prpr = stock.stck_prpr; + stockData.prdy_vrss = stock.prdy_vrss; + stockData.prdy_vrss_sign = stock.prdy_vrss_sign; + stockData.prdy_ctrt = stock.prdy_ctrt; + stockData.hts_avls = stock.hts_avls; + stockData.per = stock.per; + return stockData; + } + /** * 특정 주식의 기간별시세 데이터를 반환하는 함수 * @param {string} stockCode - 종목코드 @@ -38,7 +95,7 @@ export class StockDetailService { fid_org_adj_prc: '0', }; - const response = await this.requestApi( + const response = await this.requestApi( 'FHKST03010100', '/uapi/domestic-stock/v1/quotations/inquire-daily-itemchartprice', queryParams, @@ -64,7 +121,7 @@ export class StockDetailService { * * @author uuuo3o */ - private formatStockInquirePriceData(response: InquirePriceApiResponse) { + private formatStockInquirePriceData(response: InquirePriceChartApiResponse) { const { output2 } = response; return output2.map((info) => {