Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: de_bert on June 18, 2011, 06:54:48 PM



Title: Mt. Gox API problems
Post by: de_bert on June 18, 2011, 06:54:48 PM
Hi,

I have a problem with the Mt. Gox trading API, namely with the buy and sell scripts:
Code:
https://www.mtgox.com/code/sellBTC.php?name=USERNAME&pass=PASS&amount=3&price=30
will give me "{"error": "Not logged in. <a href='/users/login'>Log in</a>"}".
A call to
Code:
https://mtgox.com/code/getOrders.php?name=USERNAME&pass=PASS
works, however.

It does not work in a browser, but it also does not work in JS:
Code:
$.ajax({
            type: 'POST',
            url: 'https://mtgox.com/code/sellBTC.php?name=USERNAME&pass=PASS&amount=' + numAmount + '&price=' + numPrice,
            dataType: 'json',
            data: {},
            success: this.onSellSuccess.bind(this, funCallback),
            error: this.onSellFailure.bind(this, funCallback)
        }); 
will not work either, yielding the same error.

As I found few people having the same problem and no answers, I'm wondering whether I'm doing something wrong....
Also Mt. Gox support did not answer my request for help.


Title: Re: Mt. Gox API problems
Post by: jhansen858 on June 19, 2011, 07:02:05 AM
I had a perfectly working script and now all it does is crank away forever never getting results back from mtgox.. I have spent over 3 hours trying to fix to no avail..



Title: Re: Mt. Gox API problems
Post by: phorensic on June 19, 2011, 07:38:04 AM
I had a working file_get_contents script to show the last price.  Then my page started to run infinitely with no results yesterday.  Switched file_get_contents to the cURL method.  Now curl times out before getting any results, even though the command line curl works.  I don't know what happened, but all of a sudden I can't use their API!


Title: Re: Mt. Gox API problems
Post by: redshark1802 on June 19, 2011, 07:52:08 AM
I had a working file_get_contents script to show the last price.  Then my page started to run infinitely with no results yesterday.  Switched file_get_contents to the cURL method.  Now curl times out before getting any results, even though the command line curl works.  I don't know what happened, but all of a sudden I can't use their API!

I have the same problems. I have no idea what is going wrong on their side.
Has anybody an alternative solution?

kind regards, redshark1802


Title: Re: Mt. Gox API problems
Post by: de_bert on June 19, 2011, 08:23:11 AM
Well, I finally found the solution to my problem, and realized that the API description is just very misleading.
Instead of
Code:
https://mtgox.com/code/buyBTC.php?name=blah&pass=blah&amount=#&price=#
it should say
Code:
https://mtgox.com/code/buyBTC.php
with POST parameters name, pass, amount, price:

Code:
 $.ajax({
                type: 'POST',
                url: 'https://mtgox.com/code/sellBTC.php',
                dataType: 'json',
                data: {name: this.strUser,
                       pass: this.strPass,
                       amount: numAmount,
                       price: numPrice},
                success: this.onSellSuccess.bind(this, funCallback),
                error: this.onSellFailure.bind(this, funCallback)
            });

Ticker data, i.e. last price, should work, however you have to be careful to always use "https" - I had some issues where "http" would return an error, but not always...


Title: Re: Mt. Gox API problems
Post by: jhansen858 on June 19, 2011, 09:41:02 AM
what if your just trying to pull pricing and not do transactions.


Title: Re: Mt. Gox API problems
Post by: redshark1802 on June 19, 2011, 01:30:25 PM
what if your just trying to pull pricing and not do transactions.

Hi,

that's my code:
Code:
$mtgoxJSON = file_get_contents("https://mtgox.com/code/data/ticker.php");
$mtgoxJSON = utf8_encode($mtgoxJSON);
$mtgoxJSON = json_decode($mtgoxJSON);

I tried various timeout options but not one is working.

regards, redshark1802


Title: Re: Mt. Gox API problems
Post by: de_bert on June 19, 2011, 04:02:05 PM
There was another thread, i'm to lazy to look it up now, where they found that you have to supply some user agent string. Does not matter what, but you need to supply one.
Maybe your function does not do that?


Title: Re: Mt. Gox API problems
Post by: redshark1802 on June 19, 2011, 04:27:59 PM
There was another thread, i'm to lazy to look it up now, where they found that you have to supply some user agent string. Does not matter what, but you need to supply one.
Maybe your function does not do that?

Thats right, it does not. But it worked, suddenly it just runs endless.
I havent changed anything, it must be a change withing mtgox.
Thanks for your help.

regards, redshark1802


Title: Re: Mt. Gox API problems
Post by: de_bert on June 19, 2011, 06:21:17 PM
Thats right, it does not. But it worked, suddenly it just runs endless.
I havent changed anything, it must be a change withing mtgox.

Jup, I assume they did it because of the DDoS attacks - although I would guess this does not change a thing, really.
But they apparently really changed something, so you'll have to change your code.

That's exactly the problem with Mt. Gox - or let's say the biggest problem - they would not communicate if their life depended on it. Central change in the API? Why worry! Nobody needs to know...