Author

Topic: Displaying active bitcoin stats on my webpage (Read 1039 times)

hero member
Activity: 630
Merit: 500
December 02, 2011, 11:32:18 PM
#3
Here is how I did it on my old mining pool website with PHP and mySQL from TradeHill, which is *very* similar to how you would do it with MtGox, unless you want to use websocket/sockets.io for live AJAX stuff.

Code:
$file = fopen("https://api.tradehill.com/APIv1/USD/Ticker", "rb");
$tradedata = fread($file, 8192);
fclose($file);

$jsonTradedata = json_decode($tradedata, true);

mysql_query("UPDATE `websiteSettings` SET `tradeHillWorth` = '".$jsonTradedata['ticker']['last']."'");
echo $jsonTradedata['ticker']['last'];

This accessed a table in MySQL called websiteSettings in my main DB. You don't need a database, but it makes it easier to reduce load on your website because you can pool every N times, instead of every time the page loads.

Then you run this somewhere in your PHP code before you want to call the variable:

Code:
$tradeHillQ = mysql_query("SELECT `tradeHillWorth` FROM `websiteSettings`");
$tradeHillWorth = mysql_fetch_object($tradeHillQ);

Then you run this when you want to insert the price in the output of the HTML page:

Code:
echo round($tradeHillWorth->tradeHillWorth2);?>

The code above will round it to two decimal places.  Again, this is very, very similar to how you would do it for any exchange.  Just read their API documentation.
full member
Activity: 129
Merit: 100
November 30, 2011, 04:22:58 AM
#2
Is there anyone willing to help? I just want it displayed on my own page that me and a few friends are using.. It's nothing commercial or anything. The BitHopper people aren't helping me any, so i'm looking to the community for help.

Thanks
full member
Activity: 129
Merit: 100
November 28, 2011, 02:45:34 AM
#1
I'm having a hard time figuring out how to display current mtgox stats on my web page.
I honestly have no idea where to start, and I can't find anything helpful online for how to do it.
The page I want to display on is my bithopper mining stats page, so its an html page.

I have the APIs from MtGox and tradehill but I don't know how to use them.
Jump to: