Bitcoin Forum
May 04, 2024, 08:52:06 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [PHP] Simple Current Rate Snippet  (Read 912 times)
daniel_zane (OP)
Newbie
*
Offline Offline

Activity: 20
Merit: 0


View Profile
March 08, 2013, 08:20:56 PM
 #1

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.
1714812726
Hero Member
*
Offline Offline

Posts: 1714812726

View Profile Personal Message (Offline)

Ignore
1714812726
Reply with quote  #2

1714812726
Report to moderator
You get merit points when someone likes your post enough to give you some. And for every 2 merit points you receive, you can send 1 merit point to someone else!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714812726
Hero Member
*
Offline Offline

Posts: 1714812726

View Profile Personal Message (Offline)

Ignore
1714812726
Reply with quote  #2

1714812726
Report to moderator
1714812726
Hero Member
*
Offline Offline

Posts: 1714812726

View Profile Personal Message (Offline)

Ignore
1714812726
Reply with quote  #2

1714812726
Report to moderator
hamdi
Hero Member
*****
Offline Offline

Activity: 826
Merit: 500



View Profile
March 08, 2013, 08:34:54 PM
 #2

have a minute, i build you one.
hamdi
Hero Member
*****
Offline Offline

Activity: 826
Merit: 500



View Profile
March 08, 2013, 08:41:38 PM
 #3


Code:
$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
Hero Member
*****
Offline Offline

Activity: 826
Merit: 500



View Profile
March 08, 2013, 08:42:53 PM
 #4

if you feel like thanking me, do it here:

1tHXmntuyAvFmJrZfrRNWkrnB9Rq3nnu4


thanks
daniel_zane (OP)
Newbie
*
Offline Offline

Activity: 20
Merit: 0


View Profile
March 08, 2013, 08:52:47 PM
 #5

Shows up blank? Nothing shows up.
hamdi
Hero Member
*****
Offline Offline

Activity: 826
Merit: 500



View Profile
March 08, 2013, 08:57:16 PM
 #6

php scripts should start with

<?

and also you need CURL installed on your server.

alternatively try this:

Code:
$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 Offline

Activity: 1498
Merit: 1000


View Profile
March 08, 2013, 08:58:13 PM
 #7

Code:
$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
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
March 08, 2013, 10:06:37 PM
 #8

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.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
hamdi
Hero Member
*****
Offline Offline

Activity: 826
Merit: 500



View Profile
March 09, 2013, 02:04:56 PM
 #9

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 Offline

Activity: 105
Merit: 10



View Profile
March 30, 2013, 04:16:49 AM
 #10

Here's a version with the v2 API

Code:
$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";
Pages: [1]
  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!