PHP Tutorial : Displaying Live STEEM price from bittrex Api on your website using file_get_contents () function

in #utopian-io7 years ago (edited)

image.png
source

Dear My Friends . . . . .

In this occassion I will share to you all a simple tutorial how to display live price of criptocurrency from bittrex Api on your website, In this case I use STEEM price as sample. In the page that we will create in this tutorial will show automatically and live the the crypto price corresponding on the bittrex site.

Introduction

In fact, many ways can be done to do this. This time I use file_get_content function to retrieve data from bittrex API. file_get_content is one of PHP fuction use to get content from other page and display it on our page.

Requirement

  1. WebServer
    From Linux Os you can use Apache, While on Windows you can use XAMPP (including Apache, MySql, PHP, Perl , etc)
  2. PHP
  3. Editor

Note : in this turial I use windows 7 Operating System, XAMPP server and gedit for editor.

The Steps :

  • ReActivate your Server, Then create a php file and save it on Xampp/htdocs/ if you use XAMPP. While you use Linux save at var/www with the name live.php or eith other name up to you(must php extension).
  • Edit file live.php paste this code bellow:
<?php
$api = file_get_contents("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-steem"); //get content from bittrex API
echo $api; // display the result

You can get bittrex API here : https://bittrex.com/home/api*

  • Save code and run it on browser http://localhost/live.php . The result like this
    image.png
  • Now we split the data using json_decode and display some data which need only. Change the code echo $api; with the code bellow. Then Save and try to run on your browser.
//json fucntion
$data= json_decode($api, true); 
//split array data
$split1= $data['result'];
$split2= $split1[0];
$market=$split2['MarketName'];
$high=$split2['High'];
$low=$split2['Low'];
$last=$split2['Last'];
//displaying data
echo 'Market Name = '. $market;
echo 'High Price  = '. $high;
echo 'Low Price = '. $low;
echo 'Last Price = '. $last;

image.png

  • because the data we need already exists, now let us beautify the look of our web page using html. in this tutorial I will show the data in the table. you may modify it as you like. Delete all the code that for displaying data on live.php and change it with the code bellow. Then save and run it on your browser
// displaying data on talbe
echo '<center>
<h3>Live BTC - STEEM</h3>
<table border="1">
<tr>
<th>Market Name</th>
<th>High Price</th>
<th>Low Price</th>
<th>Last Price</th>
</tr>
<tr>
<td>'.$market.'</td>
<td>'.$high.'</td>
<td>'.$low.'</td>
<td>'.$last.'</td>
</tr>
</table>
<p>The Data according bittrex.com</p>
</center>';

image.png

  • Finally, we have a page to view Live Market of BTC-STEEM with the price according bittrex API. For more questions you can contact me on discord with the same username. Here the Full Code or you can download the file here:
<?php
$api = file_get_contents("https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-steem"); //get content from bittrex API
//json fucntion
$data= json_decode($api, true); 
//split array data
$split1= $data['result'];
$split2= $split1[0];
$market=$split2['MarketName'];
$high=$split2['High'];
$low=$split2['Low'];
$last=$split2['Last'];
// displaying data on talbe
echo '<center>
<h3>Live BTC - STEEM</h3>
<table border="1">
<tr>
<th>Market Name</th>
<th>High Price</th>
<th>Low Price</th>
<th>Last Price</th>
</tr>
<tr>
<td>'.$market.'</td>
<td>'.$high.'</td>
<td>'.$low.'</td>
<td>'.$last.'</td>
</tr>
</table>
<p>The Data according bittrex.com</p>
</center>';

Conclusion

To take live data from another website and display it back on our website, we can use PHP file_get_content function. Usually A website always provides APIs for developers who want to retrieve their data. To get more API you can contact the owner of the website.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Bereh that adoe... Nyoe siat teuk sang droekeuh akan jeut keu sahabat utopian 👍🏻

mandum berkat doa dan dukungan dari ureng droneh.

Hey @sogata I am @utopian-io. I have just upvoted you!

Achievements

  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

bereh rakan.. rupajih meunan cara post tentang PHP biar di aprove di utopian :D

nyo postingan pertama sit rakan. alhamdulillah ka ji vote. ret translation han ek le tapegot. ta translete kedroteh me apui tapeugot. ipeugah tapake google translate.

Hahah..hai meuseu tapeugot tutorial PHP keu youtube ngen keu facebook ek jeut ile ? Mksd di aprove

ne chat lon manteng bak discord nyak mangat tapegah haba. nan akun @sogata cit

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank sir

I like your blogs amazing job thats why i fallow u and upvote u ! Dont stop DO IT!!!! @sogata

Thank you, stay tuned follow me

Keep going forward performing quality content, the best always for you. Bravo my brother @sogata ... !!!.

Thank my bro. Bang na tem neutes meen rot utopian.io??

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 57959.67
ETH 2343.73
USDT 1.00
SBD 2.44