Bitcoin Forum
December 06, 2016, 06:16:01 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: MT Gox API- am I too stupid?  (Read 1081 times)
Tosh
Newbie
*
Offline Offline

Activity: 3


View Profile
July 01, 2011, 11:28:22 AM
 #1

Hi all!

I tried to scrape the tickerdata from Mt Gox, but it doesn't work.
I tested it several ways, but nothing works. When I open the API-adress in the browser, I get a download with getDepth.php or Ticker.php in which the data is included, but there is no way to scrape it.
I saw somebody writing here, that Mt.Gox needs to be accessed with an Useragent set, but even that changes nothing.


Can someone help me please, and tell me, what I'm doing wrong?

Here is a php snippet which works for all other sites out there but not for Mt Gox

Code:
function get_data($url)
{
  $useragent="Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0";
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
$site="https://mtgox.com/code/data/getDepth.php";
$data=get_data($site);
echo $data;

Thanks

Maybe we are all early adopters...
1481048161
Hero Member
*
Offline Offline

Posts: 1481048161

View Profile Personal Message (Offline)

Ignore
1481048161
Reply with quote  #2

1481048161
Report to moderator
1481048161
Hero Member
*
Offline Offline

Posts: 1481048161

View Profile Personal Message (Offline)

Ignore
1481048161
Reply with quote  #2

1481048161
Report to moderator
1481048161
Hero Member
*
Offline Offline

Posts: 1481048161

View Profile Personal Message (Offline)

Ignore
1481048161
Reply with quote  #2

1481048161
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481048161
Hero Member
*
Offline Offline

Posts: 1481048161

View Profile Personal Message (Offline)

Ignore
1481048161
Reply with quote  #2

1481048161
Report to moderator
Bitcoinreminder.com
Full Member
***
Offline Offline

Activity: 225



View Profile WWW
July 01, 2011, 12:13:14 PM
 #2

If you know Ruby, then maybe this helps you.

http://forum.bitcoin.org/index.php?topic=24504.0
Tosh
Newbie
*
Offline Offline

Activity: 3


View Profile
July 01, 2011, 01:13:14 PM
 #3

Thanks for your help, but I never touched Ruby before.

I've got a trading bot that worked fine before the Mt Gox hack and now I don't get the API things to work. It's a little bit annoying...

Maybe we are all early adopters...
zybron
Member
**
Offline Offline

Activity: 66



View Profile
July 01, 2011, 01:28:02 PM
 #4

What might help and is not apparent from their API page is that you have to POST your username and password, even for the 'public' API addresses. Or, at least, I was only able to successfully retrieve data after doing so. I'm using vb.net, however, so I'm not sure how to code the same methods in PHP.

SlipperySlope
Hero Member
*****
Offline Offline

Activity: 686

Stephen Reed


View Profile
July 01, 2011, 02:28:17 PM
 #5

This works for me.  I am developing a Java client for the Mt Gox API and use the linux curl utility for testing.
Code:
curl -v -k --referer https://mtgox.com https://mtgox.com/code/data/getDepth.php

The -v option gives a verbose trace of the HTTP protocol, and is not otherwise needed. The -k option ignores the Mt Gox SSL certificate checking - and should not be used in a production script.
Tosh
Newbie
*
Offline Offline

Activity: 3


View Profile
July 01, 2011, 04:38:33 PM
 #6

Thank you all for your help, now it works!

For those who want to do some stuff with the Mt Gox API via php, that works:

Puplic stuff
Code:
function get_data($url)
{
  $useragent="Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0";
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
$site="https://mtgox.com/code/data/getDepth.php";
$data=get_data($site);
echo $data;

Account stuff:
Code:
function get_data($url)
{
  $useragent="Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0";
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "name=yourname&pass=yourpass");
  curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
$site="https://mtgox.com/code/getFunds.php";
$data=get_data($site);
echo $data;

A referrer is not necessary, but you have to set the useragent.

Maybe we are all early adopters...
SlipperySlope
Hero Member
*****
Offline Offline

Activity: 686

Stephen Reed


View Profile
July 01, 2011, 08:14:39 PM
 #7

Thanks, I saved your samples and was not aware of the curl_setopt feature.
angelo95
Member
**
Offline Offline

Activity: 84


View Profile
July 04, 2011, 09:03:30 PM
 #8

Mate you can do all of this with a one-liner...

Code:
curl -s -k https://mtgox.com/code/data/getDepth.php
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!