Bitcoin Forum

Bitcoin => Project Development => Topic started by: lordfox8 on December 07, 2022, 11:40:09 PM



Title: How to add current quote on website?
Post by: lordfox8 on December 07, 2022, 11:40:09 PM
Hello guys...
I'm looking for a way in php to add the current quote value of cryptocurrency like BTC and ETH? Where do I get this information and where can I get it from?

I'm putting together a website and would like to add this updated quote...


Title: Re: How to add current quote on website?
Post by: TryNinja on December 08, 2022, 12:17:27 AM
Using Coingecko's API:

Code:
<?php
$ch 
curl_init("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd");
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_HEADER0);
$data curl_exec($ch);
curl_close($ch);
$price json_decode($data)->bitcoin->usd;

echo 
"Price is {$price}"
?>


Or just switch to another API and get the data according to the resulting structure. Honestly, that's something you should definitely know how to do if you are coding your own website. :P


Title: Re: How to add current quote on website?
Post by: Stalker22 on December 08, 2022, 12:20:45 AM
TryNinja is right, the simplest way would be using some of the freely available API endpoints.

For example:
https://www.coingecko.com/en/api
https://www.blockchain.com/explorer/api
https://coinmarketcap.com/api/


Title: Re: How to add current quote on website?
Post by: seoincorporation on December 15, 2022, 03:39:29 PM
TryNinja already give you a nice solution, but there are some other ways to do this, maybe you can try with a JS widget. If you search for them then you will find tons of it. But I would like to recommend the one from co-in.

Code:
<!-- Cryptocurrency Price Widget --><script>!function(){var e=document.getElementsByTagName("script"),t=e[e.length-1],n=document.createElement("script");function r(){var e=crCryptocoinPriceWidget.init({base:"USD,EUR,CNY,GBP",items:"BTC,ETH,LTC,XMR,DASH",backgroundColor:"FFFFFF",streaming:"1",rounded:"1",boxShadow:"1",border:"1"});t.parentNode.insertBefore(e,t)}n.src="https://co-in.io/widget/pricelist.js?items=BTC%2CETH%2CLTC%2CXMR%2CDASH",n.async=!0,n.readyState?n.onreadystatechange=function(){"loaded"!=n.readyState&&"complete"!=n.readyState||(n.onreadystatechange=null,r())}:n.onload=function(){r()},t.parentNode.insertBefore(n,null)}();</script><a href="https://currencyrate.today/" rel="noopener" target="_blank">CurrencyRate.Today</a><!-- /Cryptocurrency Price Widget -->

I like this one because you can personalize the coins and the colors you want to use for your widget. And it looks like this:


Source: https://co-in.io/crypto-price-widget/