From 9fba722deb846ef1d006131a6e0d4b12802a71dd Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 17 Jun 2024 17:00:58 +0900 Subject: [PATCH 1/4] =?UTF-8?q?#42=20[refactor]=20:=20=EC=B0=A8=ED=8A=B8?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=EC=9D=BC=20=EC=A7=80=EC=A0=95=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/controller/ChartController.java | 2 +- .../service/BackTestingServiceImpl.java | 6 ++--- .../backend/service/CandleInfoUpdater.java | 23 ++++++++++--------- .../org/dgu/backend/service/ChartService.java | 3 ++- .../dgu/backend/service/ChartServiceImpl.java | 16 +++++++------ 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/org/dgu/backend/controller/ChartController.java b/backend/src/main/java/org/dgu/backend/controller/ChartController.java index dabaf70..5d08245 100644 --- a/backend/src/main/java/org/dgu/backend/controller/ChartController.java +++ b/backend/src/main/java/org/dgu/backend/controller/ChartController.java @@ -22,7 +22,7 @@ public ResponseEntity>> getOHLCVCharts( @RequestParam("coin_name") String koreanName, @RequestParam("candle_name") String candleName) { - List ohlcvResponses = chartService.getOHLCVCharts(koreanName, candleName); + List ohlcvResponses = chartService.getOHLCVCharts(koreanName, candleName, null); return ApiResponse.onSuccess(SuccessStatus.SUCCESS_GET_OHLCV_CHART, ohlcvResponses); } diff --git a/backend/src/main/java/org/dgu/backend/service/BackTestingServiceImpl.java b/backend/src/main/java/org/dgu/backend/service/BackTestingServiceImpl.java index d49ac45..67bc232 100644 --- a/backend/src/main/java/org/dgu/backend/service/BackTestingServiceImpl.java +++ b/backend/src/main/java/org/dgu/backend/service/BackTestingServiceImpl.java @@ -34,15 +34,15 @@ public class BackTestingServiceImpl implements BackTestingService { // 백테스팅 결과를 생성하는 메서드 @Override public BackTestingDto.BackTestingResponse createBackTestingResult(String authorizationHeader, BackTestingDto.StepInfo stepInfo) { - updateCandleInfo("비트코인", stepInfo.getCandleName()); + updateCandleInfo("비트코인", stepInfo.getCandleName(), null); return fetchBackTestingResult(authorizationHeader, stepInfo); } // 캔들 정보 최신화 메서드 @Transactional - protected void updateCandleInfo(String koreanName, String candleName) { - candleInfoUpdater.ensureCandleInfoUpToDate(koreanName, candleName); + protected void updateCandleInfo(String koreanName, String candleName, LocalDateTime startDate) { + candleInfoUpdater.ensureCandleInfoUpToDate(koreanName, candleName, startDate); } // 최신화된 캔들 정보를 사용해 백테스팅 결과를 생성하는 메서드 diff --git a/backend/src/main/java/org/dgu/backend/service/CandleInfoUpdater.java b/backend/src/main/java/org/dgu/backend/service/CandleInfoUpdater.java index 82f1430..e384dd6 100644 --- a/backend/src/main/java/org/dgu/backend/service/CandleInfoUpdater.java +++ b/backend/src/main/java/org/dgu/backend/service/CandleInfoUpdater.java @@ -30,7 +30,7 @@ public class CandleInfoUpdater { private final DateUtil dateUtil; // 현재 시각을 기준으로 캔들 정보를 최신화하는 메서드 - public void ensureCandleInfoUpToDate(String koreanName, String candleName) { + public void ensureCandleInfoUpToDate(String koreanName, String candleName, LocalDateTime startDate) { Market market = marketRepository.findByKoreanName(koreanName); if (Objects.isNull(market)) { throw new MarketException(MarketErrorResult.NOT_FOUND_MARKET); @@ -40,16 +40,17 @@ public void ensureCandleInfoUpToDate(String koreanName, String candleName) { throw new CandleException(CandleErrorResult.NOT_FOUND_CANDLE); } - // 가장 최근 캔들 차트 - CandleInfo latestCandleInfo = candleInfoRepository.findTopByMarketAndCandleOrderByTimestampDesc(market, candle); - int candleInterval = candleUtil.calculateCandleInterval(candleName); - LocalDateTime startDate; - if (Objects.isNull(latestCandleInfo)) { - startDate = dateUtil.convertToLocalDateTime("2018-01-01T00:00:00"); - } else { - startDate = latestCandleInfo.getDateTime(); - if (startDate.plusMinutes(candleInterval).isAfter(LocalDateTime.now())) { - return; + if (Objects.isNull(startDate)) { + // 가장 최근 캔들 차트 + CandleInfo latestCandleInfo = candleInfoRepository.findTopByMarketAndCandleOrderByTimestampDesc(market, candle); + int candleInterval = candleUtil.calculateCandleInterval(candleName); + if (Objects.isNull(latestCandleInfo)) { + startDate = dateUtil.convertToLocalDateTime("2018-01-01T00:00:00"); + } else { + startDate = latestCandleInfo.getDateTime(); + if (startDate.plusMinutes(candleInterval).isAfter(LocalDateTime.now())) { + return; + } } } diff --git a/backend/src/main/java/org/dgu/backend/service/ChartService.java b/backend/src/main/java/org/dgu/backend/service/ChartService.java index 3a71c68..284ac1c 100644 --- a/backend/src/main/java/org/dgu/backend/service/ChartService.java +++ b/backend/src/main/java/org/dgu/backend/service/ChartService.java @@ -2,9 +2,10 @@ import org.dgu.backend.dto.ChartDto; +import java.time.LocalDateTime; import java.util.List; public interface ChartService { - List getOHLCVCharts(String koreanName, String candleType); + List getOHLCVCharts(String koreanName, String candleType, LocalDateTime startDate); List getAllChartOptions(); } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/service/ChartServiceImpl.java b/backend/src/main/java/org/dgu/backend/service/ChartServiceImpl.java index 972b802..e106ab2 100644 --- a/backend/src/main/java/org/dgu/backend/service/ChartServiceImpl.java +++ b/backend/src/main/java/org/dgu/backend/service/ChartServiceImpl.java @@ -29,10 +29,10 @@ public class ChartServiceImpl implements ChartService { // OHLCV 차트를 반환하는 메서드 @Override - public List getOHLCVCharts(String koreanName, String candleName) { - updateCandleInfo(koreanName, candleName); + public List getOHLCVCharts(String koreanName, String candleName, LocalDateTime startDate) { + updateCandleInfo(koreanName, candleName, startDate); - return fetchUpdatedCandleInfo(koreanName, candleName); + return fetchUpdatedCandleInfo(koreanName, candleName, startDate); } // 차트 선택 지표 목록을 반환하는 메서드 @@ -55,13 +55,13 @@ public List getAllChartOptions() { // 캔들 정보 최신화 메서드 @Transactional - protected void updateCandleInfo(String koreanName, String candleName) { - candleInfoUpdater.ensureCandleInfoUpToDate(koreanName, candleName); + protected void updateCandleInfo(String koreanName, String candleName, LocalDateTime startDate) { + candleInfoUpdater.ensureCandleInfoUpToDate(koreanName, candleName, startDate); } // 최신화된 캔들 정보를 반환하는 메서드 @Transactional - protected List fetchUpdatedCandleInfo(String koreanName, String candleName) { + protected List fetchUpdatedCandleInfo(String koreanName, String candleName, LocalDateTime startDate) { Market market = marketRepository.findByKoreanName(koreanName); if (Objects.isNull(market)) { throw new MarketException(MarketErrorResult.NOT_FOUND_MARKET); @@ -70,7 +70,9 @@ protected List fetchUpdatedCandleInfo(String koreanName, if (Objects.isNull(candle)) { throw new CandleException(CandleErrorResult.NOT_FOUND_CANDLE); } - LocalDateTime startDate = candleUtil.getStartDateByCandleName(candleName); + if (Objects.isNull(startDate)) { + startDate = candleUtil.getStartDateByCandleName(candleName); + } List candleInfos = candleInfoRepository.findByMarketAndCandleAndDateTimeAfter(market, candle, startDate); if (candleInfos.isEmpty()) { From e873cecb6ee6ab53f1f5a4d36201016c0bc98b80 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 17 Jun 2024 17:01:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?#42=20[feat]=20:=20=EC=98=A4=EC=A0=84=209?= =?UTF-8?q?=EC=8B=9C=EB=A5=BC=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=EC=9D=BC=EC=9D=84=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/dgu/backend/util/DateUtil.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/src/main/java/org/dgu/backend/util/DateUtil.java b/backend/src/main/java/org/dgu/backend/util/DateUtil.java index b8d7234..6708bb5 100644 --- a/backend/src/main/java/org/dgu/backend/util/DateUtil.java +++ b/backend/src/main/java/org/dgu/backend/util/DateUtil.java @@ -3,6 +3,7 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; @Component @@ -12,4 +13,18 @@ public class DateUtil { public LocalDateTime convertToLocalDateTime(String date) { return LocalDateTime.parse(date, FORMATTER); } + + public LocalDateTime calculateDailyStartDate() { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime startDate; + + // 현재 시간이 오전 9시 이전이면 전날 오전 9시부터 필터링 + if (now.toLocalTime().isBefore(LocalTime.of(9, 0))) { + startDate = now.minusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0); + } else { + startDate = now.withHour(0).withMinute(0).withSecond(0).withNano(0); + } + + return startDate; + } } \ No newline at end of file From 95932a9ddbe97fdff72ff4fc52e72b84621d9522 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 17 Jun 2024 17:01:46 +0900 Subject: [PATCH 3/4] =?UTF-8?q?#42=20[feat]=20:=20=EB=B9=84=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EC=9D=B8=201=EB=B6=84=EB=B4=89=20=EC=B0=A8=ED=8A=B8?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20Enum=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/dgu/backend/common/constant/SuccessStatus.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java b/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java index 037ff40..5bac814 100644 --- a/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java +++ b/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java @@ -37,6 +37,7 @@ public enum SuccessStatus implements BaseCode { SUCCESS_GET_USER_COINS(HttpStatus.OK, "200", "유저 보유 코인 조회에 성공했습니다"), SUCCESS_GET_REPRESENTATIVE_COINS(HttpStatus.OK, "200", "대표 코인 조회에 성공했습니다"), SUCCESS_GET_BITCOIN_DAY_CHARTS(HttpStatus.OK, "200", "비트코인 일봉 차트 조회에 성공했습니다"), + SUCCESS_GET_BITCOIN_ONE_MINUTE_CHARTS(HttpStatus.OK, "200", "비트코인 1분봉 차트 조회에 성공했습니다"), // Upbit-Key SUCCESS_ADD_UPBIT_KEYS(HttpStatus.CREATED, "201", "업비트 키 등록에 성공했습니다"), // Chart From 4d589b38dd372d59291610735ab4e871c561b8b0 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 17 Jun 2024 17:01:57 +0900 Subject: [PATCH 4/4] =?UTF-8?q?#42=20[feat]=20:=20=EB=B9=84=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EC=9D=B8=201=EB=B6=84=EB=B4=89=20=EC=B0=A8=ED=8A=B8?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84=20(GET)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/controller/DashBoardController.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/org/dgu/backend/controller/DashBoardController.java b/backend/src/main/java/org/dgu/backend/controller/DashBoardController.java index 90d629b..0b16f70 100644 --- a/backend/src/main/java/org/dgu/backend/controller/DashBoardController.java +++ b/backend/src/main/java/org/dgu/backend/controller/DashBoardController.java @@ -7,9 +7,11 @@ import org.dgu.backend.dto.DashBoardDto; import org.dgu.backend.service.ChartService; import org.dgu.backend.service.DashBoardService; +import org.dgu.backend.util.DateUtil; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; import java.util.List; @RestController @@ -18,6 +20,7 @@ public class DashBoardController { private final DashBoardService dashBoardService; private final ChartService chartService; + private final DateUtil dateUtil; // 유저 업비트 잔고 조회 API @GetMapping("/accounts") @@ -46,10 +49,19 @@ public ResponseEntity> } // 비트코인 차트 (일봉) 조회 API - @GetMapping("/bit-charts") + @GetMapping("/bit-charts/days") public ResponseEntity>> getBitcoinDayCharts() { - List ohlcvResponses = chartService.getOHLCVCharts("비트코인", "days"); + List ohlcvResponses = chartService.getOHLCVCharts("비트코인", "days", null); return ApiResponse.onSuccess(SuccessStatus.SUCCESS_GET_BITCOIN_DAY_CHARTS, ohlcvResponses); } + + // 비트코인 차트 (1분봉) 조회 API + @GetMapping("/bit-charts/minutes1") + public ResponseEntity>> getBitcoinOneMinuteCharts() { + + LocalDateTime startDate = dateUtil.calculateDailyStartDate(); + List ohlcvResponses = chartService.getOHLCVCharts("비트코인", "minutes1", startDate); + return ApiResponse.onSuccess(SuccessStatus.SUCCESS_GET_BITCOIN_ONE_MINUTE_CHARTS, ohlcvResponses); + } } \ No newline at end of file