daniel_zane (OP)
Newbie
Offline
Activity: 20
Merit: 0
|
|
March 08, 2013, 08:20:56 PM |
|
I've searched and found quite a few WP plugin and other random codes but none seem to work. I found a javascript one but its too slow.
I'm looking for a simple PHP script to get the current BTC rate. Non-WP.
|
|
|
|
hamdi
|
|
March 08, 2013, 08:34:54 PM |
|
have a minute, i build you one.
|
|
|
|
hamdi
|
|
March 08, 2013, 08:41:38 PM |
|
$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_URL,"https://mtgox.com/api/0/data/ticker.php"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0;"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $gox=curl_exec($ch);curl_close ($ch); $gox=explode(",\"buy\":",$gox);$gox=explode(",",$gox[1]);$gox=$gox[0];
echo $gox; in the end you get the current buy rate on the variable "$gox".
|
|
|
|
hamdi
|
|
March 08, 2013, 08:42:53 PM |
|
if you feel like thanking me, do it here:
1tHXmntuyAvFmJrZfrRNWkrnB9Rq3nnu4
thanks
|
|
|
|
daniel_zane (OP)
Newbie
Offline
Activity: 20
Merit: 0
|
|
March 08, 2013, 08:52:47 PM |
|
Shows up blank? Nothing shows up.
|
|
|
|
hamdi
|
|
March 08, 2013, 08:57:16 PM |
|
php scripts should start with <? and also you need CURL installed on your server. alternatively try this: $gox=file_get_contents("https://mtgox.com/api/0/data/ticker.php"); $gox=explode(",\"buy\":",$gox);$gox=explode(",",$gox[1]);$gox=$gox[0];
echo $gox; if both doesn't work, your server is not allowing outgoing connections.
|
|
|
|
gweedo
Legendary
Offline
Activity: 1498
Merit: 1000
|
|
March 08, 2013, 08:58:13 PM |
|
$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_URL,"https://mtgox.com/api/1/BTCUSD/ticker"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0;"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $gox=json_decode(curl_exec($ch), true); curl_close ($ch); $gox=$gox["return"]["last"]["display_short"];
echo $gox;
That should work for you better, since API v0 was phased out Donation Address in sig.
|
|
|
|
Bitsky
|
|
March 08, 2013, 10:06:37 PM |
|
Note that directly calling mtgox each time the page gets loaded makes it possible to get your website blocked by mtgox. Either someone keeps F5 pressed or your site gets enough normal traffic. Your server then would hammer mtgox with API requests what will get you banned. It's better to add some local caching to protect yourself from that.
|
|
|
|
hamdi
|
|
March 09, 2013, 02:04:56 PM |
|
that's another story. but i sure won't code these 3 lines into it now, for a guy who can't even say thanks.
|
|
|
|
matt.collier
Member
Offline
Activity: 105
Merit: 10
|
|
March 30, 2013, 04:16:49 AM |
|
Here's a version with the v2 API $tuCurl = curl_init(); curl_setopt($tuCurl, CURLOPT_URL, "https://data.mtgox.com/api/2/BTCUSD/money/ticker"); curl_setopt($tuCurl, CURLOPT_PORT , 443); curl_setopt($tuCurl, CURLOPT_HEADER, 0); curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, true); $tuData = curl_exec($tuCurl); $obj = json_decode($tuData); $averagePrice = $obj->data->avg->value; $lastPrice = $obj->data->last->value; echo $averagePrice."\n"; echo $lastPrice."\n";
|
|
|
|
|