Hello,
I am not really a programmer, but I was bored and looked at it
.
I only slightly changed some print statements etc and commented the line "output_message"
And this code here works on my server, so your code is probably fine?!
You could test putting this into a file, test.php for example and see if it works:
<?php
function mtgox()
{
// output_message("Reading https://mtgox.com/api/0/data/ticker.php");
$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']);
print "USD BUY: $mtgox_array[buy]<br/>";
//return $mtgox_array[buy];
}
function mtgox_euro()
{
// fetch from mtgox with cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/api/1/BTCEUR/public/ticker');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = json_decode(curl_exec($ch));
curl_close($ch);
// add to variables
$buy = $data->return->buy->value;
$sell = $data->return->sell->value;
print "EUR BUY: $buy<br/>";
print "EUR SELL: $sell<br/>";
// 5% margin
$buy_price_1btc = $buy * 0.95;
$sell_price_1btc = $sell * 1.05;
print "BUY 1BTC: $buy_price_1btc<br/>";
print "SELL 1BTC: $sell_price_1btc<br/>";
}
mtgox();
mtgox_euro();
?>
Output is:
USD BUY: 12.29
EUR BUY: 9.50100
EUR SELL: 9.50148
BUY 1BTC: 9.02595
SELL 1BTC: 9.976554
It looks like this gets called everytime someone visits your website, maybe mtgox blocked your ip?
Probably would be better to use some caching, so that it checks mtgox only every 5 minutes or so.