Skip to content

Commit

Permalink
add volume from osmosis usd
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTFM committed Jan 17, 2024
1 parent 7548542 commit bb18138
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public OsmosisTokenPrice tokenPriceFromPriceInTime(TokenPriceDto.PriceInTime pri

OsmosisTokenPrice tokenPrice = new OsmosisTokenPrice(tokenPriceId);
tokenPrice.setOsmosisSymbolPriceInUsd(priceInTime.getPrice());
tokenPrice.setOsmosisSymbolTotalVolumesInUsd(priceInTime.getTotalVolumes());
return tokenPrice;
}

@Override
public void setPriceInUsd(BigDecimal tokenPrice, BigDecimal marketCap, BigDecimal totalVolumes) {
this.setOsmosisSymbolPriceInUsd(tokenPrice);
this.setOsmosisSymbolTotalVolumesInUsd(totalVolumes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public abstract class TokenPrice<E extends TokenPrice<E>> {
@Column(name = "COINGECKO_SYMBOL_TOTAL_VOLUMES_IN_USD")
private BigDecimal coingeckoSymbolTotalVolumesInUsd;

@Column(name = "OSMOSIS_SYMBOL_TOTAL_VOLUMES_IN_USD")
private BigDecimal osmosisSymbolTotalVolumesInUsd;

@Column(name = "SYMBOL_SUPPLY")
private BigDecimal symbolSupply;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ public OsmosisTokenPriceDto(List<OsmosisTokenPrice> osmosisTokenPriceList) {
@Override
public TokenPriceDto toTokenPrice() {
List<TokenPriceDto.PriceInTime> priceInTimeList = new ArrayList<>();
osmosisTokenPriceList.forEach(osmosisTokenPrice -> priceInTimeList.add(new TokenPriceDto.PriceInTime(TimeHelper.millisToLocalDateTime(osmosisTokenPrice.getTime() * 1000), setOsmosisSymbolPriceInUsdFromDto(osmosisTokenPrice))));
osmosisTokenPriceList.forEach(osmosisTokenPrice -> priceInTimeList.add(
new TokenPriceDto.PriceInTime(
TimeHelper.millisToLocalDateTime(osmosisTokenPrice.getTime() * 1000),
setOsmosisSymbolPriceInUsdFromDto(osmosisTokenPrice),
setOsmosisSymbolTotalVolumesInUsd(osmosisTokenPrice)
)
)
);
return new TokenPriceDto(priceInTimeList);
}

private BigDecimal setOsmosisSymbolPriceInUsdFromDto(OsmosisTokenPrice osmosisTokenPrice) {
return osmosisTokenPrice.getClose().add(osmosisTokenPrice.getOpen()).add(osmosisTokenPrice.getHigh()).add(osmosisTokenPrice.getLow()).divide(BigDecimal.valueOf(4), RoundingMode.DOWN);
}

private BigDecimal setOsmosisSymbolTotalVolumesInUsd(OsmosisTokenPrice osmosisTokenPrice) {
return osmosisTokenPrice.getVolume();
}

@Data
public static class OsmosisTokenPrice {
@JsonProperty("time")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public PriceInTime(LocalDateTime time, BigDecimal price) {
this.price = price;
}

public PriceInTime(LocalDateTime time, BigDecimal price, BigDecimal totalVolumes) {
this.time = time;
this.price = price;
this.totalVolumes = totalVolumes;
}

public PriceInTime(LocalDateTime time, BigDecimal price, BigDecimal marketCap, BigDecimal totalVolumes) {
this.time = time;
this.price = price;
Expand Down

0 comments on commit bb18138

Please sign in to comment.