Bitcoin Forum
May 13, 2024, 04:57:59 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Poll
Question: Was it easy && helpful?
Yes
No

Pages: [1] 2 »  All
  Print  
Author Topic: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]  (Read 4991 times)
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 01:33:28 PM
Last edit: May 09, 2016, 11:28:02 PM by Th0ur007
 #1

Added Guide for Altcoin Conversion

Introduction:
Hello All, Today i am going to tell you how to make your own currency converter using PHP and HTML. I know it seems to be difficult but when you understand it properly, it becomes a small piece of work for you. I will simply use https://bitcoinaverage.com/api to make it work. Let's Go.

Steps to Follow:
Kindly follow all the steps and read carefully to understand the meaning of each and every word, so it would be easier to do it yourself.

Step 1 - A Basic HTML Page:
First of all, You should create a basic HTML Page like this in any of your text editor:
Code:
<html>
<head>
<title>Bitcoin Price Converter</title>
</head>

<body>
</body>

</html>

Step 2 - PHP Script:
Now we will put PHP Coding to grab data using API. If you are not aware what is an API, Check this video: What is an API?
Let's start with creating a variable "$url". This variable will be used to grab data from the API Link i.e. https://api.bitcoinaverage.com/ticker/global/USD/
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
?>

Once we get our data from the API, We will have to decode it using JSON. Create a variable called $price in which we will store our decoded information.
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
?>

At this moment we have the API's Information in the variable called $price, It's time to get an exact data which we want i.e. last price. We will create a new variable called $last_price and will store the price in it.
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
?>

You did it, we got all the data and it's time to show it. Simply use echo function of PHP to output the data:
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>

Step 3 - Integrate HTML with PHP:
Now put the PHP Code on the top of the HTML Page we created before like this:
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>


<html>
<head>
<title>Bitcoin Price Converter</title>
</head>

<body>
</body>

</html>

Step 4 - Auto Refresh Page (credit goes to KenR to remind me about this)
Our Converter is ready, we are going to add an auto refresh code to make it display the latest values. Simply add this code:
Code:
<meta content='10' http-equiv='refresh'/> <!-- Reloads Page every 10 seconds -->

FINAL:
That's what we get!
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>


<html>
<head>
<title>Bitcoin Price Converter</title>
<meta content='10' http-equiv='refresh'/> <!-- Reloads Page every 10 seconds -->
</head>

<body>
</body>

</html>

Tada! You did it Wink



Hope this Guide helped you in understanding the concept of API's, Drop me some comments to motivate Smiley
If you want to Donate, Please: 18L6tGTdJfCenGxzc8ZDLsjBNaUfekXzjj
The forum was founded in 2009 by Satoshi and Sirius. It replaced a SourceForge forum.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
locopao
Legendary
*
Offline Offline

Activity: 910
Merit: 1000



View Profile
May 07, 2016, 04:01:30 PM
 #2

Thanks a lot for the real nice guide!

so if someone wants to show the price for different currencies, should do something like this?

Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/EUR/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/GBP/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/JPY/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/RUB/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>

and maybe add some css to format the output?
(was never good in php  Tongue)
radhwane
Hero Member
*****
Offline Offline

Activity: 696
Merit: 500



View Profile
May 07, 2016, 04:38:58 PM
 #3

Thank you very much for this guide really it help me a lot
Its possible to make a bitcoin price like preev.com ?
For example I writ 0.0153 in bitcoin and i see the result in USD ?
Thanks again
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 04:54:01 PM
 #4

Thanks a lot for the real nice guide!

so if someone wants to show the price for different currencies, should do something like this?

Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/EUR/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/GBP/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/JPY/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/RUB/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>

and maybe add some css to format the output?
(was never good in php  Tongue)
Yup, Thats the way to add the other currency support.
Thank you for your comment.
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 04:56:54 PM
 #5

Thank you very much for this guide really it help me a lot
Its possible to make a bitcoin price like preev.com ?
For example I writ 0.0153 in bitcoin and i see the result in USD ?
Thanks again
Yup, Here are some steps how it will go:
- Get Current 1 BTC Rate
- Multiply Current BTC Rate with your value 'X'

In your case:
0.0153*458=7.021

Cheers.
socks435
Legendary
*
Offline Offline

Activity: 2016
Merit: 1030

Privacy is always important


View Profile
May 07, 2016, 05:03:04 PM
 #6

Very nice guide for me and it help to to put it in my site..
Also i want to use this for reference to make a converter for other altcoin.. i hope i can make mine with CBX price converter..
I am looking for other codes to increase my knowledge for making a new site which exchange site.. thanks again for this guide..

Solving blocks can't be solved without my rigs.
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 05:06:48 PM
Last edit: May 07, 2016, 05:30:51 PM by Th0ur007
 #7

Very nice guide for me and it help to to put it in my site..
Also i want to use this for reference to make a converter for other altcoin.. i hope i can make mine with CBX price converter..
I am looking for other codes to increase my knowledge for making a new site which exchange site.. thanks again for this guide..
Your welcome mate, You can use any API to make one for any altcoin.
Simply change the URL of API and other is same.

I will PM you an example of CBX once im free.
Cheers.

EDIT:
CBX-USD:
Code:
<?php 
$url 
"https://www.cryptonator.com/api/ticker/cbx-usd";
$data json_decode(file_get_contents($url), true);
$ticker $data['ticker'];
$latest_price $ticker['price'];
echo 
"$latest_price";
?>


<html>
<head>
<title>CBX Price Converter</title>
</head>

<body>
</body>

</html>
socks435
Legendary
*
Offline Offline

Activity: 2016
Merit: 1030

Privacy is always important


View Profile
May 07, 2016, 05:38:47 PM
 #8

Very nice guide for me and it help to to put it in my site..
Also i want to use this for reference to make a converter for other altcoin.. i hope i can make mine with CBX price converter..
I am looking for other codes to increase my knowledge for making a new site which exchange site.. thanks again for this guide..
Your welcome mate, You can use any API to make one for any altcoin.
Simply change the URL of API and other is same.

I will PM you an example of CBX once im free.
Cheers.

EDIT:
CBX-USD:
Code:
<?php 
$url 
"https://www.cryptonator.com/api/ticker/cbx-usd";
$data json_decode(file_get_contents($url), true);
$ticker $data['ticker'];
$latest_price $ticker['price'];
echo 
"$latest_price";
?>


<html>
<head>
<title>CBX Price Converter</title>
</head>

<body>
</body>

</html>
Wow great i will try it in free domain and hosting and i hope it will work..
And i hope i can see the sample once you are free,, thanks

Solving blocks can't be solved without my rigs.
KenR
Hero Member
*****
Offline Offline

Activity: 910
Merit: 1000


「きみはこれ&#


View Profile
May 07, 2016, 05:51:39 PM
 #9

That is a very easy one.You can simply get in down with lot of other API's.Problem here is what is the refresh rate in seconds ? How often the page reloads to display the latest values ? I don't see any code for that.

  ████
█ ████
█ ████
█ ████
█ ████ █
█ ████ █
█ ████ █
█ ████ █
█ ████ █
  ████ █
  ████ █
  ████ █
  ████
  ████
█ ████
█ ████
█ ████
█ ████ █
█ ████ █
█ ████ █
█ ████ █
█ ████ █
  ████ █
  ████ █
  ████ █
  ████
  .WEBSITE.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  .ANN THREAD.
.
▄▄▄▄▄▄▄▄
  ████
█ ████
█ ████
█ ████
█ ████ █
█ ████ █
█ ████ █
█ ████ █
█ ████ █
  ████ █
  ████ █
  ████ █
  ████
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 05:57:06 PM
 #10

That is a very easy one.You can simply get in down with lot of other API's.Problem here is what is the refresh rate in seconds ? How often the page reloads to display the latest values ? I don't see any code for that.
Thank you for your comment. It was just a simple script to use API to convert price.
To refresh the page after every 10 seconds, add this line in <head>:
Code:
<meta content='10' http-equiv='refresh'/>

It becomes:
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>


<html>
<head>
<title>Bitcoin Price Converter</title>
<meta content='10' http-equiv='refresh'/> <!-- Reloads Page every 10 seconds -->
</head>

<body>
</body>

</html>
KenR
Hero Member
*****
Offline Offline

Activity: 910
Merit: 1000


「きみはこれ&#


View Profile
May 07, 2016, 06:00:53 PM
 #11

Thank you for your comment. It was just a simple script to use API to convert price.
To refresh the page after every 10 seconds, add this line in <head>:

Better now.Might as well want to update that in the main post as this is a must if someone will be using the code. Smiley

  ████
█ ████
█ ████
█ ████
█ ████ █
█ ████ █
█ ████ █
█ ████ █
█ ████ █
  ████ █
  ████ █
  ████ █
  ████
  ████
█ ████
█ ████
█ ████
█ ████ █
█ ████ █
█ ████ █
█ ████ █
█ ████ █
  ████ █
  ████ █
  ████ █
  ████
  .WEBSITE.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  .ANN THREAD.
.
▄▄▄▄▄▄▄▄
  ████
█ ████
█ ████
█ ████
█ ████ █
█ ████ █
█ ████ █
█ ████ █
█ ████ █
  ████ █
  ████ █
  ████ █
  ████
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 06:01:21 PM
 #12

Thank you for your comment. It was just a simple script to use API to convert price.
To refresh the page after every 10 seconds, add this line in <head>:

Better now.Might as well want to update that in the main post as this is a must if someone will be using the code. Smiley
Already did, Thank you for your suggestion. Smiley
lixer
Hero Member
*****
Offline Offline

Activity: 2506
Merit: 586



View Profile
May 07, 2016, 06:27:45 PM
 #13

I appreciate the guide and I'm pretty sure I'm not the only one.
I bookmarked it and copy-pasted the content to a document just in case because I just don't think this is in the right section.

lofty
Newbie
*
Offline Offline

Activity: 49
Merit: 0


View Profile WWW
May 07, 2016, 06:46:42 PM
 #14

This is nice ! I was bored so I made this using JQuery Smiley Hope OP won't mind me sharing that.

https://jsfiddle.net/aveavaeva/kttyh4d2/
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 06:54:34 PM
 #15

I appreciate the guide and I'm pretty sure I'm not the only one.
I bookmarked it and copy-pasted the content to a document just in case because I just don't think this is in the right section.
Thank you for the comment, Mod will move it to perfect place if he wants to Smiley

Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 07, 2016, 06:56:18 PM
 #16

This is nice ! I was bored so I made this using JQuery Smiley Hope OP won't mind me sharing that.

https://jsfiddle.net/aveavaeva/kttyh4d2/
That's nice, I could do it in PHP but just wanted to make it easy to understand Smiley
mookid
Sr. Member
****
Offline Offline

Activity: 446
Merit: 251



View Profile WWW
May 08, 2016, 01:10:20 AM
 #17

A pretty simple and clear guide, thanks for sharing this! It would be awsome if you can make a similar guide about how to create a script to get info from an exchange via API's.
Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 08, 2016, 05:02:35 AM
 #18

A pretty simple and clear guide, thanks for sharing this! It would be awsome if you can make a similar guide about how to create a script to get info from an exchange via API's.
Will try it, Thanks alot.
locopao
Legendary
*
Offline Offline

Activity: 910
Merit: 1000



View Profile
May 08, 2016, 12:26:41 PM
 #19

here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site



According to BitcoinAverage it's free to use their API as long as you credit them

Th0ur007 (OP)
Full Member
***
Offline Offline

Activity: 210
Merit: 101


View Profile
May 08, 2016, 12:48:40 PM
 #20

here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site



According to BitcoinAverage it's free to use their API as long as you credit them


Looks cool Smiley
Cheers.
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!