I need to get Solana blockchain ticker data for prices.
2 Answers
you have a variety of options to chose from.
Here's my non-exhaustive list
- coingecko API - https://www.coingecko.com/en/api
- coinmarketcap API - https://coinmarketcap.com/api/
- Binance spot API - https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md
- Coinbase spot API - https://docs.cdp.coinbase.com/sign-in-with-coinbase/docs/api-prices/
Should you need a token specific to Solana
Coded my tg bot in java and used this to do /price
} else if ("/price".equals(messageText)) {
String tokenPrice = fetchTokenPrice(tokenAddress);
bot.execute(new SendMessage(update.message().chat().id(), tokenPrice));
private static String fetchTokenPrice(String tokenAddress) {
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("public-api.birdeye.so")
.addPathSegment("defi")
.addPathSegment("price")
.addQueryParameter("address", tokenAddress)
.addQueryParameter("chainId", "101") // replace with your correct chainId
.build();
Request request = new Request.Builder()
.url("https://public-api.birdeye.so/defi/price?include_liquidity=true&address=4bEMorkYYDojk98Pk2hRTScvh6HwKgvrikzEcP2dY545")
.get()
.addHeader("X-API-KEY", System.getenv("birdeyeapikey"))
.build();
try {
Response response = httpClient.newCall(request).execute();
if (!response.isSuccessful()) {
return "Error: " + response;
}
JSONObject jsonObject = new JSONObject(response.body().string());
double price = jsonObject.getJSONObject("data").getDouble("value"); // Retrieve the price from the "value" field within the "data" object
DecimalFormat df = new DecimalFormat("0.00000000000"); // adjust to desired precision
return "The current price of $MINDN is: " + "$" + df.format(price) + " USD";
} catch (IOException e) {
return "Exception when making request - " + e.getMessage();
}
}
-
Welcome to Stack Overflow! Thanks for answering but usually you should add some text. Something like 'I used Birdeye, here's a link to their API docs' and then the code.– mikemaccana ♦Commented Jul 4 at 10:51