Skip to content

Commit

Permalink
getHistoricalPricesOfTokensByContractAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
SORJAS committed Sep 21, 2023
1 parent b2c0a46 commit 32f864e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/no/jansoren/defillama/CoinsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public CoinsClient(HttpClient httpClient, ObjectMapper objectMapper) {
public Coins getPricesOfTokensByContractAddress(String coins, String searchWidth) {
return get("https://coins.llama.fi/prices/current/"+coins+"?searchWidth="+searchWidth, new TypeReference<>(){});
}

public Coins getHistoricalPricesOfTokensByContractAddress(String coins, int timestamp, String searchWidth) {
return get("https://coins.llama.fi/prices/historical/" + timestamp + "/" +coins+"?searchWidth="+searchWidth, new TypeReference<>(){});
}
}
9 changes: 9 additions & 0 deletions src/test/java/no/jansoren/defillama/CoinsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ void testGetPricesOfTokensByContractAddress() {
Assertions.assertNotNull(coins);
}

@Test
void testGetHistoricalPricesOfTokensByContractAddress() {
var contractAddresses = "ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8";
var timestamp = 1648680149;
var searchWidth = "4h";
Coins coins = client.getHistoricalPricesOfTokensByContractAddress(contractAddresses, timestamp, searchWidth);
Assertions.assertNotNull(coins);
}

}

0 comments on commit 32f864e

Please sign in to comment.