-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'back/main' of https://github.com/boostcampwm-2024/web16…
…-JuGa into back/main
- Loading branch information
Showing
37 changed files
with
697 additions
and
432 deletions.
There are no files selected for viewing
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
File renamed without changes.
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
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; | ||
} |
2 changes: 1 addition & 1 deletion
2
...oreaInvestment/korea.investment.module.ts → ...oreaInvestment/korea-investment.module.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
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
File renamed without changes.
6 changes: 5 additions & 1 deletion
6
...dto/stock.index.list.chart.element.dto.ts → ...dto/stock-index-list-chart.element.dto.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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
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' }) | ||
time: string; | ||
|
||
@ApiProperty({ description: '주가 지수' }) | ||
value: string; | ||
|
||
@ApiProperty({ description: '전일 대비 주가 지수' }) | ||
diff: string; | ||
} |
14 changes: 14 additions & 0 deletions
14
BE/src/stock/index/dto/stock-index-response-element.dto.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,14 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { StockIndexValueElementDto } from './stock-index-value-element.dto'; | ||
import { StockIndexListChartElementDto } from './stock-index-list-chart.element.dto'; | ||
|
||
export class StockIndexResponseElementDto { | ||
@ApiProperty({ description: '실시간 값', type: StockIndexValueElementDto }) | ||
value: StockIndexValueElementDto; | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { StockIndexResponseElementDto } from './stock-index-response-element.dto'; | ||
|
||
export class StockIndexResponseDto { | ||
@ApiProperty({ | ||
description: '코스피 지수', | ||
type: StockIndexResponseElementDto, | ||
}) | ||
KOSPI: StockIndexResponseElementDto; | ||
|
||
@ApiProperty({ | ||
description: '코스닥 지수', | ||
type: StockIndexResponseElementDto, | ||
}) | ||
KOSDAQ: StockIndexResponseElementDto; | ||
|
||
@ApiProperty({ | ||
description: '코스피200 지수', | ||
type: StockIndexResponseElementDto, | ||
}) | ||
KOSPI200: StockIndexResponseElementDto; | ||
|
||
@ApiProperty({ | ||
description: 'KSQ150 지수', | ||
type: StockIndexResponseElementDto, | ||
}) | ||
KSQ150: StockIndexResponseElementDto; | ||
} |
22 changes: 5 additions & 17 deletions
22
...ndex/dto/stock.index.value.element.dto.ts → ...ndex/dto/stock-index-value-element.dto.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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
.../index/interface/stock.index.interface.ts → .../index/interface/stock-index.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
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,121 @@ | ||
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 { SocketGateway } from '../../websocket/socket.gateway'; | ||
|
||
@Controller('/api/stocks/index') | ||
@ApiTags('주가 지수 API') | ||
export class StockIndexController { | ||
constructor( | ||
private readonly stockIndexService: StockIndexService, | ||
private readonly koreaInvestmentService: KoreaInvestmentService, | ||
private readonly socketGateway: SocketGateway, | ||
) {} | ||
|
||
@Get() | ||
@ApiOperation({ | ||
summary: '주가 지수 차트 정보, 현재 값 조회 API', | ||
description: '주가 지수 차트 정보와 현재 값을 리스트로 반환한다.', | ||
}) | ||
@ApiResponse({ | ||
status: 200, | ||
description: '주가 지수 조회 성공', | ||
type: StockIndexResponseDto, | ||
}) | ||
async getStockIndex() { | ||
const accessToken = await this.koreaInvestmentService.getAccessToken(); | ||
|
||
const [kospiChart, kosdaqChart, kospi200Chart, ksq150Chart] = | ||
await Promise.all([ | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'0001', | ||
accessToken, | ||
), // 코스피 | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'1001', | ||
accessToken, | ||
), // 코스닥 | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'2001', | ||
accessToken, | ||
), // 코스피200 | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'3003', | ||
accessToken, | ||
), // KSQ150 | ||
]); | ||
|
||
const [kospiValue, kosdaqValue, kospi200Value, ksq150Value] = | ||
await Promise.all([ | ||
this.stockIndexService.getDomesticStockIndexValueByCode( | ||
'0001', | ||
accessToken, | ||
), // 코스피 | ||
this.stockIndexService.getDomesticStockIndexValueByCode( | ||
'1001', | ||
accessToken, | ||
), // 코스닥 | ||
this.stockIndexService.getDomesticStockIndexValueByCode( | ||
'2001', | ||
accessToken, | ||
), // 코스피200 | ||
this.stockIndexService.getDomesticStockIndexValueByCode( | ||
'3003', | ||
accessToken, | ||
), // KSQ150 | ||
]); | ||
|
||
const stockIndexResponse = new StockIndexResponseDto(); | ||
stockIndexResponse.KOSPI = { | ||
value: kospiValue, | ||
chart: kospiChart, | ||
}; | ||
stockIndexResponse.KOSDAQ = { | ||
value: kosdaqValue, | ||
chart: kosdaqChart, | ||
}; | ||
stockIndexResponse.KOSPI200 = { | ||
value: kospi200Value, | ||
chart: kospi200Chart, | ||
}; | ||
stockIndexResponse.KSQ150 = { | ||
value: ksq150Value, | ||
chart: ksq150Chart, | ||
}; | ||
return stockIndexResponse; | ||
} | ||
|
||
@Cron('*/5 9-16 * * 1-5') | ||
async cronStockIndexLists() { | ||
const accessToken = await this.koreaInvestmentService.getAccessToken(); | ||
|
||
const stockLists = await Promise.all([ | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'0001', | ||
accessToken, | ||
), // 코스피 | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'1001', | ||
accessToken, | ||
), // 코스닥 | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'2001', | ||
accessToken, | ||
), // 코스피200 | ||
this.stockIndexService.getDomesticStockIndexListByCode( | ||
'3003', | ||
accessToken, | ||
), // KSQ150 | ||
]); | ||
|
||
this.socketGateway.sendStockIndexListToClient({ | ||
KOSPI: stockLists[0], | ||
KOSDAQ: stockLists[1], | ||
KOSPI200: stockLists[2], | ||
KSQ150: stockLists[3], | ||
}); | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
BE/src/stock/index/stock.index.module.ts → BE/src/stock/index/stock-index.module.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
Oops, something went wrong.