Bitcoin Forum

Bitcoin => Project Development => Topic started by: QsoftStudios on November 09, 2013, 07:43:14 AM



Title: Chart for website.
Post by: QsoftStudios on November 09, 2013, 07:43:14 AM
Hello, I would like to put a chart on my website that shows the current BTC-e and Bitstamp BTC price. However I am not quite sure how to do this. I have a feeling it would be PHP parsing JSON from the exchanges but I'm not quite sure. Anyone know how to do this that could help? :)


Title: Re: Chart for website.
Post by: duxZero on November 09, 2013, 09:44:36 AM
Just use the API's for the big popular exchanges.

I can even give you a snippet that does this if need be.


Title: Re: Chart for website.
Post by: QsoftStudios on November 09, 2013, 09:47:48 AM
Just use the API's for the big popular exchanges.

I can even give you a snippet that does this if need be.


That be awesome thank you! I need to learn more about how JSON and how the different APIs work lol.


Title: Re: Chart for website.
Post by: duxZero on November 09, 2013, 10:08:05 AM
https://www.bitstamp.net/api/

https://btc-e.com/api/2/btc_usd/ticker

Code:
<?php

        
function getStats($e) {
            
$cookies tmpfile();
            
$userAgent 'duxZero';

            
$eURL NULL;

            switch (
$e) {
                case 
"btc-e":
                    
$eURL "https://btc-e.com/api/2/btc_usd/ticker";
                    break;
                case 
"bitstamp":
                    
$eURL "https://www.bitstamp.net/api/ticker/";
                    break;
                default:
                    
$eURL "https://www.bitstamp.net/api/ticker/";
                    break;
            }

            
$cURL curl_init($eURL);

            
$options = array(
                
CURLOPT_CONNECTTIMEOUT => 20,
                
CURLOPT_USERAGENT => $userAgent,
                
CURLOPT_AUTOREFERER => true,
                
CURLOPT_FOLLOWLOCATION => true,
                
CURLOPT_RETURNTRANSFER => true,
                
CURLOPT_COOKIEFILE => $cookies,
                
CURLOPT_COOKIEJAR => $cookies,
                
CURLOPT_SSL_VERIFYPEER => 0,
                
CURLOPT_SSL_VERIFYHOST => 0
            
);

            
curl_setopt_array($cURL$options);
            
$contents curl_exec($cURL);
            
curl_close($cURL);
            return 
json_decode($contentstrue);
        }

        
$a getStats("btc-e");
        echo 
$a['ticker']['high'];

        echo 
"<br/>";

        
$b getStats("bitstamp");
        echo 
$b['high'];
        
?>



Title: Re: Chart for website.
Post by: QsoftStudios on November 09, 2013, 10:43:12 AM
https://www.bitstamp.net/api/

https://btc-e.com/api/2/btc_usd/ticker

Code:
<?php

        
function getStats($e) {
            
$cookies tmpfile();
            
$userAgent 'duxZero';

            
$eURL NULL;

            switch (
$e) {
                case 
"btc-e":
                    
$eURL "https://btc-e.com/api/2/btc_usd/ticker";
                    break;
                case 
"bitstamp":
                    
$eURL "https://www.bitstamp.net/api/ticker/";
                    break;
                default:
                    
$eURL "https://www.bitstamp.net/api/ticker/";
                    break;
            }

            
$cURL curl_init($eURL);

            
$options = array(
                
CURLOPT_CONNECTTIMEOUT => 20,
                
CURLOPT_USERAGENT => $userAgent,
                
CURLOPT_AUTOREFERER => true,
                
CURLOPT_FOLLOWLOCATION => true,
                
CURLOPT_RETURNTRANSFER => true,
                
CURLOPT_COOKIEFILE => $cookies,
                
CURLOPT_COOKIEJAR => $cookies,
                
CURLOPT_SSL_VERIFYPEER => 0,
                
CURLOPT_SSL_VERIFYHOST => 0
            
);

            
curl_setopt_array($cURL$options);
            
$contents curl_exec($cURL);
            
curl_close($cURL);
            return 
json_decode($contentstrue);
        }

        
$a getStats("btc-e");
        echo 
$a['ticker']['high'];

        echo 
"<br/>";

        
$b getStats("bitstamp");
        echo 
$b['high'];
        
?>


Thank you very much!


Title: Re: Chart for website.
Post by: duxZero on November 09, 2013, 10:47:43 AM
Anytime, i made it easy to implement other exchanges in the future to.