diff --git a/src/main/java/no/jansoren/defillama/CoinsClient.java b/src/main/java/no/jansoren/defillama/CoinsClient.java new file mode 100644 index 0000000..2aefa7a --- /dev/null +++ b/src/main/java/no/jansoren/defillama/CoinsClient.java @@ -0,0 +1,19 @@ +package no.jansoren.defillama; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import no.jansoren.defillama.model.coins.Coins; +import no.jansoren.defillama.model.protocols.BaseClient; + +import java.net.http.HttpClient; + +public class CoinsClient extends BaseClient { + + public CoinsClient(HttpClient httpClient, ObjectMapper objectMapper) { + super(httpClient, objectMapper); + } + + public Coins getPricesOfTokensByContractAddress(String coins, String searchWidth) { + return get("https://coins.llama.fi/prices/current/"+coins+"?searchWidth="+searchWidth, new TypeReference<>(){}); + } +} diff --git a/src/main/java/no/jansoren/defillama/model/coins/Coin.java b/src/main/java/no/jansoren/defillama/model/coins/Coin.java new file mode 100644 index 0000000..78f8d2e --- /dev/null +++ b/src/main/java/no/jansoren/defillama/model/coins/Coin.java @@ -0,0 +1,24 @@ +package no.jansoren.defillama.model.coins; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.math.BigDecimal; + +public record Coin( + + @JsonProperty("symbol") + String symbol, + + @JsonProperty("price") + BigDecimal price, + + @JsonProperty("decimals") + Integer decimals, + + @JsonProperty("confidence") + BigDecimal confidence, + + @JsonProperty("timestamp") + Integer timestamp +) { +} \ No newline at end of file diff --git a/src/main/java/no/jansoren/defillama/model/coins/Coins.java b/src/main/java/no/jansoren/defillama/model/coins/Coins.java new file mode 100644 index 0000000..4638b15 --- /dev/null +++ b/src/main/java/no/jansoren/defillama/model/coins/Coins.java @@ -0,0 +1,12 @@ +package no.jansoren.defillama.model.coins; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Map; + +public record Coins( + + @JsonProperty("coins") + Map coins +){ +} diff --git a/src/test/java/no/jansoren/defillama/CoinsClientTest.java b/src/test/java/no/jansoren/defillama/CoinsClientTest.java new file mode 100644 index 0000000..7f12213 --- /dev/null +++ b/src/test/java/no/jansoren/defillama/CoinsClientTest.java @@ -0,0 +1,30 @@ +package no.jansoren.defillama; + +import com.fasterxml.jackson.databind.ObjectMapper; +import no.jansoren.defillama.model.coins.Coins; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.http.HttpClient; + +public class CoinsClientTest { + + private CoinsClient client; + + @BeforeEach + void before() { + var httpClient = HttpClient.newBuilder().build(); + var objectMapper = new ObjectMapper(); + client = new CoinsClient(httpClient, objectMapper); + } + + @Test + void testGetPricesOfTokensByContractAddress() { + var contractAddresses = "ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8"; + var searchWidth = "4h"; + Coins coins = client.getPricesOfTokensByContractAddress(contractAddresses, searchWidth); + Assertions.assertNotNull(coins); + } + +}