2

Are there any APIs currently available that let you fetch Cardano native token prices without web-scraping?

SundaeSwap, ADAX, MuesliSwap, and MinSwap don't appear to have this functionality.

ErgoDEX may have it in the future but is there anything right now that works?

Just want to get the last known token prices for specific pairs. Doesn't matter if it's in ADA or USD.

1 Answer 1

3

MuesliSwap does provide some API endpoints that you could look into: https://docs.muesliswap.com/cardano/api

There's a ticker that provides "24-hour pricing and volume summary for each market pair available on the exchange": http://analytics.muesliswap.com/ticker

And you can also get more detailed historical price (or volume) data on each token, eg: https://analytics.muesliswap.com/price?policy-id=8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa&tokenname=MILK&interval=hourly

Here's an example site powered by their API according to the docs: https://cardanoassets.com/


On how to get the number of decimals of a token to convert the pricing data:

I couldn't find that info in the MuesliSwap API, though it could still be hidden in there somewhere.

In general though that info can be derived from the metadata of the minting transaction, eg here:

https://cardanoscan.io/transaction/d74798c4a1e453fbc6ba4fbb1d785e0534fb8531fd1bc054ceff5b086240d3b5?tab=metadata

(Check under label "20", which is defined in CIP-38 here: https://github.com/cardano-foundation/CIPs/pull/137)

If you need to automatically get this info, one way would be to use a service like Blockfrost to query it.

Once you have the policy id and asset name (eg from the muesliswap api), you could use this endpoint to fetch the asset details, including the metadata with the decimals field:

https://cardano-mainnet.blockfrost.io/api/v0/assets/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145

(You'll need to convert the asset name "SUNDAE" from the MuesliSwap API to hex "53554e444145" and add it to the policy id)

7
  • Thank you. But some have very strange decimal numbers. For example SUNDAE_ADA: analytics.muesliswap.com/trades/… How do I fix the prices with these decimal points? Commented Mar 31, 2022 at 7:31
  • If you're in Javascript, you could simply call "toFixed()" on those numbers to convert the floating point to fixed point representations, eg "(2.5e-3).toFixed(4)" becomes "0.0025", if you want 4 decimal places; for those smaller numbers you'll need more decimal places (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…)
    – sean
    Commented Mar 31, 2022 at 8:54
  • 1
    Ah I see, okay thats because 1 SUNDAE has 6 decimals, so technically 1 SUNDAE is a million "tokens" (like 1 Ada is 1,000,000 Lovelace) - so you can just multiply the price by a million like so: (2.5e-7 * 1e6).toFixed(2) to get 0.25 (the actual SUNDAE price in Ada)
    – sean
    Commented Mar 31, 2022 at 17:59
  • 1
    Added the info to the answer above. There might be a better solution, but blockfrost definitely works for that. You'd probably just query this info once and store it on your end, so you should just need very few requests, ie one per token.
    – sean
    Commented Apr 2, 2022 at 6:43
  • 1
    just to add, in case there's a token that doesn't follow the CIP-38 yet, you can also check the token registry here for the info github.com/cardano-foundation/cardano-token-registry, eg here's the entry for SUNDAE: github.com/cardano-foundation/cardano-token-registry/blob/… đź‘Ť
    – sean
    Commented Apr 3, 2022 at 11:38

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.