Skip to content

Commit

Permalink
๐Ÿ”ง fix: service ์—๋Ÿฌ๋ฅผ http ์—๋Ÿฌ๋กœ ๋ณ€๊ฒฝ
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunie committed Nov 8, 2024
1 parent 6549725 commit d65c70b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
15 changes: 10 additions & 5 deletions BE/src/koreaInvestment/korea.investment.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import { UnauthorizedException } from '@nestjs/common';
import { getFullURL } from '../util/getFullURL';

export class KoreaInvestmentService {
Expand All @@ -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;

Expand Down
60 changes: 34 additions & 26 deletions BE/src/stock/index/stock.index.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -34,9 +31,6 @@ export class StockIndexService {
accessToken,
);

if (result.rt_cd !== '0')
throw new Error('๋ฐ์ดํ„ฐ๋ฅผ ์ •์ƒ์ ์œผ๋กœ ์กฐํšŒํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.');

const data = result.output;

return new StockIndexValueElementDto(
Expand All @@ -51,17 +45,25 @@ export class StockIndexService {
code: string,
accessToken: string,
) {
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,
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((err) => {
throw new InternalServerErrorException(
'์ฃผ๊ฐ€ ์ง€์ˆ˜ ์ฐจํŠธ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.',
);
});

return response.data;
}
Expand All @@ -70,16 +72,22 @@ export class StockIndexService {
code: string,
accessToken: string,
) {
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,
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((err) => {
throw new InternalServerErrorException(
'์ฃผ๊ฐ€ ์ง€์ˆ˜ ๊ฐ’ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.',
);
});

return response.data;
}
Expand Down

0 comments on commit d65c70b

Please sign in to comment.