Author

Topic: Last price from Mt Gox json (Read 1369 times)

hero member
Activity: 700
Merit: 501
August 10, 2011, 05:06:06 PM
#8
Sorry, forgot to post here that I already got this working with help from another thread. Thanks!
member
Activity: 114
Merit: 10
August 10, 2011, 01:20:53 PM
#7
Code:
$opts = array(
  
'http'=> array(
    
'method'=>   "GET",
    
'user_agent'=>    "MozillaXYZ/1.0"));
$context stream_context_create($opts);
$json file_get_contents('https://mtgox.com/code/data/ticker.php'false$context);
$json json_decode($json);
echo 
$json->{'ticker'}->{'last'};
?>

member
Activity: 62
Merit: 10
August 10, 2011, 12:00:59 PM
#6
Just wanted to get it out there,  BOTs are easily written to appear as browsers or even do it the dirty way and run in the browser.

The useragent is configurable in the HTTP headers that you send with the request.  Also, MT.Gox likes a unique user-agent.
hero member
Activity: 518
Merit: 500
August 08, 2011, 07:41:29 PM
#5
acutally a user agent seems not to be required. In my android App I don't use one either. And It would not really make sense, at least when using the MtGox API, as this one is intended for non-browser traffic
legendary
Activity: 2940
Merit: 1090
August 07, 2011, 09:50:33 PM
#4
I read somewhere too that useragents that actually send a useragent field might be favoured over those  that do not?

(Dunno if bots would actually be requred to pretend to be (vanilla ?) browsers in order to be permitted to use the bot-enabling API though, has anyone tried being honest about which version of which bot is making the request?)

-MarkM-
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
August 07, 2011, 04:42:47 PM
#3
Yeah, you should use https://mtgox.com/code/data/ticker.php ... The URL that you use requires logging in.

legendary
Activity: 1176
Merit: 1260
May Bitcoin be touched by his Noodly Appendage
August 07, 2011, 04:41:51 PM
#2
Here's what I usually use
Code:
$a=ouvrirpage("https://mtgox.com/code/data/ticker.php");
$res=json_decode($atrue);
echo 
$res['ticker']['last'];


function 
ouvrirpage($site){
$ch curl_init($site);
curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$res curl_exec($ch);
curl_close($ch);
return $res;
}
?>

Maybe MtGox needs an useragent header
hero member
Activity: 700
Merit: 501
August 07, 2011, 04:15:43 PM
#1
Can anyone help? I'm trying to grab the last price from Mt Gox using the following code:

    $url = 'https://mtgox.com/api/0/data/ticker.php';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    $json = curl_exec($ch);
    curl_close($ch);
    echo $json;//['ticker']['last'];
?>

and it's just hanging. Can anyone spot an error or if it's completely wrong just give me the right code? 1 BTC bounty if it works!

Thanks!
Jump to: