Jump to content

Bitcoin Price Ticker Fix - PLEASE HELP!


jayc67

Recommended Posts

I'm using this bitcoin price ticker that is using Mt.Gox but they're no longer in service unfortunately. I'm trying to replace Mt.Gox with blockchain or something similar. Can anyone please help me fix this?
 
I tried  https://www.bitstamp.net/api/ticker/ and https://blockchain.info/ticker but neither are working. I'm doing this for my site http://www.bitcoinvalues.net. Thanks
 
<?php
        //first fetch the current rate from MtGox
        $ch = curl_init('https://mtgox.com/api/0/data/ticker.php');
                curl_setopt($ch, CURLOPT_REFERER, 'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
                curl_setopt($ch, CURLOPT_USERAGENT, "CakeScript/0.1");
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                $mtgoxjson = curl_exec($ch);
                curl_close($ch);
               
        //decode from an object to array
                $output_mtgox = json_decode($mtgoxjson);
                $output_mtgox_1 = get_object_vars($output_mtgox);
                $mtgox_array = get_object_vars($output_mtgox_1['ticker']);

?>
<br/>
<br/>
Last: <?php echo $mtgox_array['last'];   ?><br/>
High: <?php echo $mtgox_array['high'];   ?><br/>
Low:  <?php echo $mtgox_array['low'];   ?><br/>
Avg:   <?php echo $mtgox_array['avg'];   ?><br/>
Vol:   <?php echo $mtgox_array['vol'];   ?><br/>

 

Link to comment
Share on other sites

Try dumping the $output_mtgox variable after it is decoded to view the array. When looking at blockchain the data is in a json encoded array but there are multiple countries, something mtgox may not have had. I bet you the array will look something like:

array(21){
  usd(5){
    "15m"=>527,
    etc...
  },
  etc....
}

So basically you will need to modify your echo statements to be something like:

<?php echo $mtgox_array['usd']['last'];   ?>

Haven't tested it, but at least that should get you in the right direction.

 

If you use blockchain you could technically go a step further than the example site you gave and provide the results in the various currencies by using a jQuery slideshow or something of the sort.

 

p.s. make sure you change the curl_init statement to the blockchain url  :happy-04: .

 

Good Luck!

 

Josh

Edited by joallen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.