Skip to content
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] 6.02 각 주식 정보 가져오기 API 구현 #75

Merged
merged 17 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
afc77fb
✨ feat: 주식현재가 API 요청에 대한 응답값 interface 구현
uuuo3o Nov 11, 2024
1a48a8b
✨ feat: 주식현재가 API 요청에 필요한 쿼리 파라미터 DTO 구현
uuuo3o Nov 11, 2024
3053dd2
✨ feat: 주식현재가 API 요청 코드 구현
uuuo3o Nov 11, 2024
05200cf
🔧 fix: output에 대한 정보가 잘못된 부분 수정
uuuo3o Nov 11, 2024
35b332d
✨ feat: 주식현재가 API로부터 받아온 데이터 정제 및 반환하는 코드 구현
uuuo3o Nov 11, 2024
08bb77d
✨ feat: 특정 주식의 주식현재가 시세 데이터를 반환하는 controller 구현
uuuo3o Nov 11, 2024
59ecabb
✨ feat: 특정 주식의 주식현재가 시세 데이터 반환 DTO 구현
uuuo3o Nov 11, 2024
c1ff7ee
⚙️ chore: 린트 규칙 추가
uuuo3o Nov 11, 2024
b760a20
🔧 fix: 국내주식기간별시세 API에 사용할 interface로 수정
uuuo3o Nov 11, 2024
1c163ea
✨ feat: 국내주식기간별시세 API에 사용할 DTO로 수정 및 추가
uuuo3o Nov 11, 2024
80dd583
🚚 rename: 파일명을 명확하게 변경
uuuo3o Nov 11, 2024
12abb63
✨ feat: 국내주식기간별시세 API 요구사항에 맞춰 service, controller 수정
uuuo3o Nov 11, 2024
351c474
💡 comment: 주석 추가 및 불필요한 코드 삭제
uuuo3o Nov 11, 2024
ea3d296
Merge branch 'back/main' into feature/api/stockDetail-#54
uuuo3o Nov 11, 2024
3442786
📝 docs: swagger에 잘못 작성된 상태 코드 수정
uuuo3o Nov 11, 2024
115b1db
Merge branch 'back/main' into feature/api/stockDetail-#54
uuuo3o Nov 11, 2024
37e2351
Merge branch 'back/main' into feature/api/stockDetail-#54
uuuo3o Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BE/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ module.exports = {
'class-methods-use-this': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/naming-convention': 'off',
},
};
2 changes: 2 additions & 0 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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';
import { StockDetailModule } from './stock/detail/stock-detail.module';
import { typeOrmConfig } from './configs/typeorm.config';

@Module({
Expand All @@ -21,6 +22,7 @@ import { typeOrmConfig } from './configs/typeorm.config';
StockIndexModule,
StockTopfiveModule,
SocketModule,
StockDetailModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
27 changes: 27 additions & 0 deletions BE/src/stock/detail/dto/stock-detail-output1.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ApiProperty } from '@nestjs/swagger';

export class InquirePriceOutput1Dto {
@ApiProperty({ description: 'HTS 한글 종목명' })
hts_kor_isnm: string;

@ApiProperty({ description: '종목코드' })
stck_shrn_iscd: string;

@ApiProperty({ description: '주식 현재가' })
stck_prpr: string;

@ApiProperty({ description: '전일 대비' })
prdy_vrss: string;

@ApiProperty({ description: '전일 대비 부호' })
prdy_vrss_sign: string;

@ApiProperty({ description: '전일 대비율' })
prdy_ctrt: string;

@ApiProperty({ description: 'HTS 시가총액' })
hts_avls: string;

@ApiProperty({ description: 'PER' })
per: string;
}
42 changes: 42 additions & 0 deletions BE/src/stock/detail/dto/stock-detail-output2.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ApiProperty } from '@nestjs/swagger';

export class InquirePriceOutput2Dto {
@ApiProperty({ description: '주식 영업 일자' })
stck_bsop_date: string;

@ApiProperty({ description: '주식 종가' })
stck_clpr: string;

@ApiProperty({ description: '주식 시가' })
stck_oprc: string;

@ApiProperty({ description: '주식 최고가' })
stck_hgpr: string;

@ApiProperty({ description: '주식 최저가' })
stck_lwpr: string;

@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;
}
34 changes: 34 additions & 0 deletions BE/src/stock/detail/dto/stock-detail-query-parameter.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 주식 현재가 시세 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;
}
17 changes: 17 additions & 0 deletions BE/src/stock/detail/dto/stock-detail-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';

/**
* 국내주식기간별시세(일/주/월/년) API를 이용할 때 필요한 요청 데이터를 담고 있는 DTO
*/
export class StockDetailRequestDto {
@ApiProperty({ description: '조회 시작일자 (ex) 20220501' })
fid_input_date_1: string;

@ApiProperty({ description: '조회 종료일자 (ex) 20220530' })
fid_input_date_2: string;

@ApiProperty({
description: '기간 분류 코드 (ex) D(일봉) W(주봉) M(월봉) Y(년봉)',
})
fid_period_div_code: string;
}
14 changes: 14 additions & 0 deletions BE/src/stock/detail/dto/stock-detail-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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[];
}
56 changes: 56 additions & 0 deletions BE/src/stock/detail/interface/stock-detail.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export interface InquirePriceOutput1Data {
prdy_vrss: string;
prdy_vrss_sign: string;
prdy_ctrt: string;
stck_prdy_clpr: string;
acml_vol: string;
acml_tr_pbmn: string;
hts_kor_isnm: string;
stck_prpr: string;
stck_shrn_iscd: string;
prdy_vol: string;
stck_mxpr: string;
stck_llam: string;
stck_oprc: string;
stck_hgpr: string;
stck_lwpr: string;
stck_prdy_oprc: string;
stck_prdy_hgpr: string;
stck_prdy_lwpr: string;
askp: string;
bidp: string;
prdy_vrss_vol: string;
vol_tnrt: string;
stck_fcam: string;
lstn_stcn: string;
cpfn: string;
hts_avls: string;
per: string;
eps: string;
pbr: string;
itewhol_loan_rmnd_ratem_name: string;
}

export interface InquirePriceOutput2Data {
stck_bsop_date: string;
stck_clpr: string;
stck_oprc: string;
stck_hgpr: string;
stck_lwpr: string;
acml_vol: string;
acml_tr_pbmn: string;
flng_cls_code: string;
prtt_rate: string;
mod_yn: string;
prdy_vrss_sign: string;
prdy_vrss: string;
revl_issu_reas: string;
}

export interface InquirePriceApiResponse {
output1: InquirePriceOutput1Data;
output2: InquirePriceOutput2Data[];
rt_cd: string;
msg_cd: string;
msg1: string;
}
45 changes: 45 additions & 0 deletions BE/src/stock/detail/stock-detail.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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';

@Controller('/api/stocks')
export class StockDetailController {
constructor(private readonly stockDetailService: StockDetailService) {}

@Post(':stockCode')
@ApiOperation({ summary: '단일 주식 종목 detail 페이지 상단부 조회 API' })
@ApiParam({
name: 'stockCode',
required: true,
description:
'종목 코드\n\n' +
'(ex) 005930 삼성전자 / 005380 현대차 / 001500 현대차증권',
})
@ApiBody({
description:
'주식 상세 조회에 필요한 데이터\n\n' +
'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,
})
@ApiResponse({
status: 201,
description: '단일 주식 종목 기본값 조회 성공',
type: InquirePriceResponseDto,
})
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(
stockCode,
fid_input_date_1,
fid_input_date_2,
fid_period_div_code,
);
}
}
11 changes: 11 additions & 0 deletions BE/src/stock/detail/stock-detail.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { KoreaInvestmentModule } from '../../koreaInvestment/korea-investment.module';
import { StockDetailController } from './stock-detail.controller';
import { StockDetailService } from './stock-detail.service';

@Module({
imports: [KoreaInvestmentModule],
controllers: [StockDetailController],
providers: [StockDetailService],
})
export class StockDetailModule {}
Loading
Loading