Skip to content

Commit

Permalink
#53 [feat] : 차트 DTO 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Jun 8, 2024
1 parent a267b97 commit 97149b7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions backend/src/main/java/org/dgu/backend/dto/ChartDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.dgu.backend.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.dgu.backend.domain.CandleInfo;
import org.dgu.backend.util.BigDecimalSerializer;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class ChartDto {
@Builder
@Getter
@AllArgsConstructor
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class OHLCVResponse {
private String date;
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal openingPrice;
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal highPrice;
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal lowPrice;
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal closePrice;
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal volume;

public static ChartDto.OHLCVResponse of(CandleInfo candleInfo) {
return OHLCVResponse.builder()
.date(String.valueOf(candleInfo.getDateTime()))
.openingPrice(BigDecimal.valueOf(candleInfo.getOpeningPrice()))
.lowPrice(BigDecimal.valueOf(candleInfo.getLowPrice()))
.highPrice(BigDecimal.valueOf(candleInfo.getHighPrice()))
.closePrice(BigDecimal.valueOf(candleInfo.getTradePrice()))
.volume(BigDecimal.valueOf(candleInfo.getAccTradeVolume()).setScale(3, RoundingMode.HALF_UP))
.build();
}
}
}

0 comments on commit 97149b7

Please sign in to comment.