-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<>(){}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/no/jansoren/defillama/model/coins/Coins.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Coin> coins | ||
){ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |