Skip to content

Commit

Permalink
#16 [feat] : 백테스팅 관련 에러 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Jun 9, 2024
1 parent 9fea88a commit 6532865
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
@Getter
@RequiredArgsConstructor
public enum BackTestingErrorResult implements BaseErrorCode {
NOT_FOUND_START_INDEX(HttpStatus.NOT_FOUND, "404", "시작 인덱스를 찾을 수 없습니다.");
NOT_FOUND_START_INDEX(HttpStatus.NOT_FOUND, "404", "시작 인덱스를 찾을 수 없습니다."),
START_DATE_AFTER_END_DATE(HttpStatus.BAD_REQUEST, "400", "시작일이 종료일보다 늦습니다."),
N_DAY_LONGER_THAN_M_DAY(HttpStatus.BAD_REQUEST, "400", "N일이 M일보다 큽니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.dgu.backend.domain.*;
import org.dgu.backend.dto.BackTestingDto;
import org.dgu.backend.exception.PortfolioErrorResult;
import org.dgu.backend.exception.PortfolioException;
import org.dgu.backend.exception.*;
import org.dgu.backend.repository.*;
import org.dgu.backend.util.CandleUtil;
import org.dgu.backend.util.DateUtil;
Expand Down Expand Up @@ -53,8 +52,17 @@ protected BackTestingDto.BackTestingResponse fetchBackTestingResult(String autho
Candle candle = candleRepository.findByCandleName(stepInfo.getCandleName());
LocalDateTime startDate = dateUtil.convertToLocalDateTime(stepInfo.getStartDate());
LocalDateTime endDate = dateUtil.convertToLocalDateTime(stepInfo.getEndDate());
if (startDate.isAfter(endDate)) {
throw new BackTestingException(BackTestingErrorResult.START_DATE_AFTER_END_DATE);
}
if (stepInfo.getNDate() > stepInfo.getMDate()) {
throw new BackTestingException(BackTestingErrorResult.N_DAY_LONGER_THAN_M_DAY);
}

List<CandleInfo> candles = candleInfoRepository.findFilteredCandleInfo(market, candle, startDate, endDate);
if (candles.isEmpty()) {
throw new CandleException(CandleErrorResult.NOT_FOUND_CANDLES);
}
candles = candleUtil.removeDuplicatedCandles(candles);

// 골든 크로스 지점 찾기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import org.dgu.backend.domain.Candle;
import org.dgu.backend.domain.CandleInfo;
import org.dgu.backend.domain.Market;
import org.dgu.backend.exception.CandleErrorResult;
import org.dgu.backend.exception.CandleException;
import org.dgu.backend.exception.MarketErrorResult;
import org.dgu.backend.exception.MarketException;
import org.dgu.backend.repository.CandleInfoRepository;
import org.dgu.backend.repository.CandleRepository;
import org.dgu.backend.repository.MarketRepository;
Expand All @@ -28,7 +32,13 @@ public class CandleInfoUpdater {
// 현재 시각을 기준으로 캔들 정보를 최신화하는 메서드
public void ensureCandleInfoUpToDate(String koreanName, String candleName) {
Market market = marketRepository.findByKoreanName(koreanName);
if (Objects.isNull(market)) {
throw new MarketException(MarketErrorResult.NOT_FOUND_MARKET);
}
Candle candle = candleRepository.findByCandleName(candleName);
if (Objects.isNull(candle)) {
throw new CandleException(CandleErrorResult.NOT_FOUND_CANDLE);
}

// 가장 최근 캔들 차트
CandleInfo latestCandleInfo = candleInfoRepository.findTopByMarketAndCandleOrderByTimestampDesc(market, candle);
Expand Down

0 comments on commit 6532865

Please sign in to comment.