-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 3.02 주식차트 정보 기능 구현 수정 #6 #47
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99362cd
♻️ refactor: getFullUrl, getHeader 적용
sieunie 6549725
♻️ refactor: stock index 관련 소켓 이벤트, response 형식 변경
sieunie d65c70b
🔧 fix: service 에러를 http 에러로 변경
sieunie 462c8a1
🔧 fix: getAccessToken 로직 오류 수정
sieunie f210aa0
➕ add: 차트 response에 전일 대비 값 추가
sieunie 19fccb7
♻️ refactor: 백엔드 파일명 통일
sieunie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
BE/src/koreaInvestment/interface/korea.investment.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface AccessTokenInterface { | ||
access_token: string; | ||
access_token_token_expired: string; | ||
token_type: string; | ||
expires_in: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
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 { StockIndexListElementDto } from './dto/stock.index.list.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'; | ||
|
||
@Injectable() | ||
export class StockIndexService { | ||
|
@@ -16,18 +17,12 @@ export class StockIndexService { | |
accessToken, | ||
); | ||
|
||
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) { | ||
|
@@ -36,40 +31,39 @@ export class StockIndexService { | |
accessToken, | ||
); | ||
|
||
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, | ||
); | ||
} | ||
|
||
private async requestDomesticStockIndexListApi( | ||
code: string, | ||
accessToken: string, | ||
) { | ||
const response = await axios.get<StockIndexChartInterface>( | ||
`${process.env.KOREA_INVESTMENT_BASE_URL}/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', | ||
}, | ||
params: { | ||
fid_input_hour_1: 300, | ||
fid_cond_mrkt_div_code: 'U', | ||
fid_input_iscd: code, | ||
const response = await axios | ||
.get<StockIndexChartInterface>( | ||
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(() => { | ||
throw new InternalServerErrorException( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 저도 에러 처리를 그냥 log만 찍어놓듯이 작성해놨는데 이렇게 수정해봐야겠어요! |
||
'주가 지수 차트 정보를 조회하지 못했습니다.', | ||
); | ||
}); | ||
|
||
return response.data; | ||
} | ||
|
@@ -78,23 +72,22 @@ export class StockIndexService { | |
code: string, | ||
accessToken: string, | ||
) { | ||
const response = await axios.get<StockIndexValueInterface>( | ||
`${process.env.KOREA_INVESTMENT_BASE_URL}/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', | ||
}, | ||
params: { | ||
fid_cond_mrkt_div_code: 'U', | ||
fid_input_iscd: code, | ||
const response = await axios | ||
.get<StockIndexValueInterface>( | ||
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(() => { | ||
throw new InternalServerErrorException( | ||
'주가 지수 값 정보를 조회하지 못했습니다.', | ||
); | ||
}); | ||
|
||
return response.data; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 여기가 어제 그룹 리뷰 때 말한 잘못 만들었다고 수정하신다고 하신 부분인가요?! 어떤 식으로 변경됐는지 나중에 한번 설명 기대하겠습니다ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네넵 이 부분이랑 소켓 이벤트 발생시키고 response 전달하는 부분도 수정했습니다!