<p>MuesliSwap does provide some API endpoints that you could look into:
<a href="https://docs.muesliswap.com/cardano/api" rel="nofollow noreferrer">https://docs.muesliswap.com/cardano/api</a></p>
<p>There's a ticker that provides <em>&quot;24-hour pricing and volume summary for each market pair available on the exchange&quot;</em>:
<a href="http://analytics.muesliswap.com/ticker" rel="nofollow noreferrer">http://analytics.muesliswap.com/ticker</a></p>
<p>And you can also get more detailed historical price <em>(or volume)</em> data on each token, eg: <a href="https://analytics.muesliswap.com/price?policy-id=8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa&amp;tokenname=MILK&amp;interval=hourly" rel="nofollow noreferrer">https://analytics.muesliswap.com/price?policy-id=8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa&amp;tokenname=MILK&amp;interval=hourly</a></p>
<p>Here's an example site powered by their API according to the docs: <a href="https://cardanoassets.com/" rel="nofollow noreferrer">https://cardanoassets.com/</a></p>
<hr />
<p>On how to get the number of decimals of a token to convert the pricing data:</p>
<p>I couldn't find that info in the MuesliSwap API, though it could still be hidden in there somewhere.</p>
<p>In general though that info can be derived from the metadata of the minting transaction, eg here:</p>
<p><a href="https://cardanoscan.io/transaction/d74798c4a1e453fbc6ba4fbb1d785e0534fb8531fd1bc054ceff5b086240d3b5?tab=metadata" rel="nofollow noreferrer">https://cardanoscan.io/transaction/d74798c4a1e453fbc6ba4fbb1d785e0534fb8531fd1bc054ceff5b086240d3b5?tab=metadata</a></p>
<p><em>(Check under label &quot;20&quot;, which is defined in CIP-38 here: <a href="https://github.com/cardano-foundation/CIPs/pull/137" rel="nofollow noreferrer">https://github.com/cardano-foundation/CIPs/pull/137</a>)</em></p>
<p>If you need to automatically get this info, one way would be to use a service like Blockfrost to query it.</p>
<p>Once you have the policy id and asset name <em>(eg from the muesliswap api)</em>, you could use this endpoint to fetch the asset details, including the metadata with the decimals field:</p>
<p><a href="https://cardano-mainnet.blockfrost.io/api/v0/assets/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145" rel="nofollow noreferrer">https://cardano-mainnet.blockfrost.io/api/v0/assets/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145</a></p>
<p><em>(You'll need to convert the asset name &quot;SUNDAE&quot; from the MuesliSwap API to hex &quot;53554e444145&quot; and add it to the policy id)</em></p>

CC BY-SA 4.0
2022-03-31T07:31:51.153Z
Thank you. But some have very strange decimal numbers. For example SUNDAE_ADA: http://analytics.muesliswap.com/trades/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77.SUNDAE_ADA

How do I fix the prices with these decimal points?
Ran Shorowitz
CC BY-SA 4.0
2022-03-31T08:54:35.703Z
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 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
sean
CC BY-SA 4.0
2022-03-31T17:17:08.503Z
But the problem is those aren't the correct prices. 2.5e-7 = 0.00000025 for the SUNDAE token. But the actual SUNDAE price on MuesliSwap is 0.25 ADA. Why is the price incorrect on the MuesliSwap api and how do I properly convert it?
Ran Shorowitz
CC BY-SA 4.0
2022-03-31T17:59:47.320Z
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
CC BY-SA 4.0
2022-04-01T21:03:31.083Z
How do I automatically retrieve the number of decimals though?
Ran Shorowitz
CC BY-SA 4.0
2022-04-02T06:43:50.090Z
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
CC BY-SA 4.0
2022-04-03T11:38:21.100Z
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 https://github.com/cardano-foundation/cardano-token-registry/, eg here's the entry for SUNDAE: https://github.com/cardano-foundation/cardano-token-registry/blob/master/mappings/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145.json 
sean
CC BY-SA 4.0
2022-03-31T06:23:02.113Z
2022-04-02T06:43:35.157Z
2022-04-02T06:43:35.157Z
sean
<p>Are there any APIs currently available that let you fetch Cardano native token prices without web-scraping?</p>
<p>SundaeSwap, ADAX, MuesliSwap, and MinSwap don't appear to have this functionality.</p>
<p>ErgoDEX may have it in the future but is there anything right now that works?</p>
<p>Just want to get the last known token prices for specific pairs. Doesn't matter if it's in ADA or USD.</p>

<api><sundaeswap><dex>
Fetching exchange prices via an API?
# Fetching exchange prices via an API?

(Asked by: username_0 on 2022-03-30)

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.

**Tags:** api, sundaeswap, dex

---

## 1 answers

### Answer by username_1 on 2022-03-31. Score: 3 | Accepted answer

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)*

> **Comments:**
> **username_0**: Thank you. But some have very strange decimal numbers. For example SUNDAE_ADA: http://analytics.muesliswap.com/trades/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77.SUNDAE_ADA  How do I fix the prices with these decimal points?  
> **username_1**: 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 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)  
> **username_0**: But the problem is those aren't the correct prices. 2.5e-7 = 0.00000025 for the SUNDAE token. But the actual SUNDAE price on MuesliSwap is 0.25 ADA. Why is the price incorrect on the MuesliSwap api and how do I properly convert it?  
> **username_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)  
> **username_0**: How do I automatically retrieve the number of decimals though?  
> **username_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.  
> **username_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 https://github.com/cardano-foundation/cardano-token-registry/, eg here's the entry for SUNDAE: https://github.com/cardano-foundation/cardano-token-registry/blob/master/mappings/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145.json   

---

