Bitcoin Forum
May 03, 2024, 10:45:19 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MT Gox API- am I too stupid?  (Read 1259 times)
Tosh (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


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
1714776319
Hero Member
*
Offline Offline

Posts: 1714776319

View Profile Personal Message (Offline)

Ignore
1714776319
Reply with quote  #2

1714776319
Report to moderator
Whoever mines the block which ends up containing your transaction will get its fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714776319
Hero Member
*
Offline Offline

Posts: 1714776319

View Profile Personal Message (Offline)

Ignore
1714776319
Reply with quote  #2

1714776319
Report to moderator
1714776319
Hero Member
*
Offline Offline

Posts: 1714776319

View Profile Personal Message (Offline)

Ignore
1714776319
Reply with quote  #2

1714776319
Report to moderator
1714776319
Hero Member
*
Offline Offline

Posts: 1714776319

View Profile Personal Message (Offline)

Ignore
1714776319
Reply with quote  #2

1714776319
Report to moderator
Bitcoinreminder.com
Sr. Member
****
Offline Offline

Activity: 240
Merit: 250


View Profile
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 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


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...
zybron
Member
**
Offline Offline

Activity: 66
Merit: 10



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
Merit: 501

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 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


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.
SlipperySlope
Hero Member
*****
Offline Offline

Activity: 686
Merit: 501

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
Merit: 10


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:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!