0

I need to get Solana blockchain ticker data for prices.

2 Answers 2

2

you have a variety of options to chose from.

Here's my non-exhaustive list

  1. coingecko API - https://www.coingecko.com/en/api
  2. coinmarketcap API - https://coinmarketcap.com/api/
  3. Binance spot API - https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md
  4. Coinbase spot API - https://docs.cdp.coinbase.com/sign-in-with-coinbase/docs/api-prices/

Should you need a token specific to Solana

  1. https://station.jup.ag/docs/apis/price-api
0

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();
    }
}
1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.