Bitcoin Forum
November 08, 2024, 06:06:03 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: mtgox api scripts stopped working  (Read 3335 times)
2weiX (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1005

this space intentionally left blank


View Profile
September 27, 2012, 06:37:17 AM
Last edit: September 27, 2012, 11:50:50 AM by 2weiX
 #1

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
Code:
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
Code:
// 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.
2weiX (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1005

this space intentionally left blank


View Profile
September 27, 2012, 11:57:32 AM
 #2

bumping this as it was previously shit.
nomnomnom
Sr. Member
****
Offline Offline

Activity: 313
Merit: 250



View Profile
September 28, 2012, 06:01:25 AM
 #3

Hello,

I am not really a programmer, but I was bored and looked at it  Cool.
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:
Code:
<?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($chCURLOPT_REFERER'Mozilla/5.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($chCURLOPT_USERAGENT"CakeScript/0.1");
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
$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($chCURLOPT_URL'https://mtgox.com/api/1/BTCEUR/public/ticker');
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_USERAGENT "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($chCURLOPT_CONNECTTIMEOUT10);
curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
$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:
Code:
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.
2weiX (OP)
Legendary
*
Offline Offline

Activity: 2058
Merit: 1005

this space intentionally left blank


View Profile
September 28, 2012, 08:51:01 AM
 #4

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.
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!