Title: mtgox api scripts stopped working
Post by: 2weiX on September 27, 2012, 06:37:17 AM
hi, as of almost 24h ago, two of my api-scrapers stopped workin. I have had these scripts written for me, so I am bouncing this off you for ideas. first API: https://mtgox.com/api/0/data/ticker.php see the resulting errorcodes here: http://bitcoinsinberlin.com/ via 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_pre($mtgox_array ; return $mtgox_array[buy]; }
and https://mtgox.com/api/1/BTCEUR/public/ticker via // 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; // 5% margin $buy_price_1btc = $buy * 0.95; $sell_price_1btc = $sell * 1.05; Any advice? Generous tipper for those who know and maybe solve the problem.
Title: Re: mtgox api scripts stopped working
Post by: 2weiX on September 27, 2012, 11:57:32 AM
bumping this as it was previously shit.
Title: Re: mtgox api scripts stopped working
Post by: nomnomnom on September 28, 2012, 06:01:25 AM
Hello, I am not really a programmer, but I was bored and looked at it 8). 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.
Title: Re: mtgox api scripts stopped working
Post by: 2weiX on September 28, 2012, 08:51:01 AM
yeah, might could be. helpdesk is referencing that i can only call "full depth" every 5 minutes, which is funny because neither of those is "full depth", the way I see it.
I have three scripts, all calling different APIs, on different servers... all blocked.
|