Get the current price of my token in html for my website

Hello, I want to insert the current price of my token on my website, I am not a programmer, I would like to have an html code so that I can only insert it on my website.

1 Like

Hello Hector, HTML alone cannot do that, you needs javascript, try to add this in your javascript code or directly at the end of your html document before /html:

  <script>
let assetId = "9sQutD5HnRvjM1uui5cVC4w9xkMPAfYEV8ymug3Mon2Y"
let target = ".lastPrice"
let tokenDecimal = 8 // your token decimal
let lastPrice = fetch("https://matcher.waves.exchange/matcher/orderbook/"+assetId+"/WAVES/status")
.then(res => res.json())
.then(asset => { 
    document.querySelectorAll(target).forEach(res => {
      res.textContent = asset.lastPrice / 10 ** tokenDecimal
    })
})
.catch(function (err) { console.log(err) })
</script>

Change your assetID in the code, then everywhere you want display the price in your page, add the lastPrice class or change the “target” value in code.

3 Likes

Do you know how to show the price in Waves instead of wavelets?

Good call, i edited, make more sens, thanks

1 Like

Thanks. I edited the code to check last price, ask and bid prices and it works.

<script>
let assetId = "WAVES"
let target1 = ".ask"
let target2 = ".lastPrice"
let target3 = ".bid"
let tokenDecimal = 2 // your token decimal
let lastPrice = fetch("https://matcher.waves.exchange/matcher/orderbook/"+assetId+"/Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck/status")
.then(res => res.json())
.then(asset => { 
    document.querySelectorAll(target1).forEach(res => {
      res.textContent = asset.ask / 10 ** tokenDecimal
    })
})
let ask = fetch("https://matcher.waves.exchange/matcher/orderbook/"+assetId+"/Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck/status")
.then(res => res.json())
.then(asset => { 
    document.querySelectorAll(target2).forEach(res => {
      res.textContent = asset.lastPrice / 10 ** tokenDecimal
    })
})
let bid = fetch("https://matcher.waves.exchange/matcher/orderbook/"+assetId+"/Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck/status")
.then(res => res.json())
.then(asset => { 
    document.querySelectorAll(target3).forEach(res => {
      res.textContent = asset.bid / 10 ** tokenDecimal
    })
})
.catch(function (err) { console.log(err) })
</script>

Do you know if it is possible to short the code above and how i could edit it so i can check the price of 2 or more assets?

I tried to use this script, it does not return, it does not present errors, what can it be?

1 Like

if you exactly copied the script, without any modification, there may be errors in the html code

I ran exactly as it is to know where to modify, only when inserted in the html it does not return, it was to read at least some error.
The display screen is completely white.

Share a link or the html code

1 Like

In the community we offer the option to embed code.
I want to make it easier for everyone to have data from your token.
You can follow her through the link.
https://community.toret-tecnology.com/

1 Like

I mean that you had to write your html code here or you had to link to the page where you had entered the code so that we could see where the error was.

I don’t see my script on your linked page. So, having nothing to check, I suggest you see if you added also in your code:
<p class="lastPrice"></p>
<p class="ask"></p>
<p class="bid"></p>

as @crashbdx said before

Thanks for the tips, now it worked.
The problem was in the I just couldn’t add other reference currencies like USDN and USDT for listing, the rest is perfect, thanks!

1 Like

Hi.
Can you share the finished code? for just putting my Id of my token and paste it on my website. I still can’t.

Hola.
¿Puedes compartir el código terminado? por solo poner mi ID de mi token y pegarlo en mi sitio web. Aún no puedo.

 

 

 

[quote="hector2, post:1, topic:19489, full:true"]

Hello, I want to insert the current price of my token on my website, I am not a programmer, I would like to have an html code so that I can only insert it on my website.Preformatted text

I couldn’t post the code here in the forum, but I did it in the Toret community

1 Like

It only works for a few minutes, and adds all the information read after updating the browser.

The asset id works only once, then the reading disappears, I have already changed several functions and nothing happens.

The script works well, just replace the cusd asset id with that of a tradable token (i.e. BTC -> 8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS) because Waves Exchange stopped the trading of cusd and ceur 2 days ago and for this reason you get an error now.

Or tell me the pair you need, i’ll post here the full code.

Now it’s working perfectly thanks!