Pages:
Author

Topic: mtGox Trading API down? [solved] (Read 2342 times)

newbie
Activity: 32
Merit: 0
July 10, 2011, 08:57:47 AM
#25
No need to get token or cookie:


        public static string GetOpenOrders(string userName, string password)
        {
            // parameters: name1=value1&name2=value2
            var parameters = "name=" + HttpUtility.UrlEncode(userName)
                 + "&pass=" + HttpUtility.UrlEncode(password);

            var req = (HttpWebRequest)WebRequest.Create("https://mtgox.com/code/getOrders.php");

            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";
            req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
            //req.Accept = "application/json";

            byte[] bytes = Encoding.ASCII.GetBytes(parameters);
            req.ContentLength = bytes.Length;

            Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);
            os.Close();

            WebResponse resp = req.GetResponse();

            try
            {
                var sr = new StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd().Trim();
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                Logger.FatalException(ex.InnerException.ToString(), ex);   
                return null;
            }
        } // end HttpPost


(Convert to your most favorite programming language Wink

Cheers
txcoin
newbie
Activity: 40
Merit: 0
July 09, 2011, 01:23:55 PM
#24
I get:

{"error":"Bad token"}

Regards,

oooo I think I figured out what the problem is.  You have to submit a token variable.  It is given in the html when you log in.

Code:



so to get the order data, you do this:

1) login
2) in the trade HTML, it will give you a token value (see above).
3) HTTP POST https://mtgox.com/code/getOrders.php
   Request Headers:
      Host[mtgox.com]
      User-Agent[Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0]
      Accept[application/json, text/javascript, */*; q=0.01]
      Accept-Language[en-gb,en;q=0.5]
      Accept-Encoding[gzip, deflate]
      Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
      Connection[keep-alive]
      Content-Type[application/x-www-form-urlencoded; charset=UTF-8]
      X-Requested-With[XMLHttpRequest]
      Referer[https://mtgox.com/]
      Content-Length[38]
      Cookie[MAKE SURE YOU POST WITH LOGIN COOKIE]
      Pragma[no-cache]
      Cache-Control[no-cache]
   Post Data:
      token[PUT TOKEN HERE]
   Response Headers:
      Date[Sat, 09 Jul 2011 18:18:13 GMT]
      Server[Apache]
      X-Powered-By[PHP/5.3.6]
      Expires[Thu, 19 Nov 1981 08:52:00 GMT]
      Cache-Control[no-store, no-cache, must-revalidate, post-check=0, pre-check=0]
      Pragma[no-cache]
      Strict-Transport-Security[max-age=1209600]
      Content-Encoding[gzip]
      Vary[Accept-Encoding]
      Content-Length[220]
      Keep-Alive[timeout=15, max=95]
      Connection[Keep-Alive]
      Content-Type[application/json]

newbie
Activity: 32
Merit: 0
July 09, 2011, 11:43:28 AM
#23
@NYConsultant

Still interested in you version of the API. But at least I got the basics working:


For all the C# devs around here: This is the basic code to use the API as of today.

        public static string GetBalance(string userName, string password)
        {
            // parameters: name1=value1&name2=value2
            var parameters = "name=" + HttpUtility.UrlEncode(userName)
                 + "&pass=" + HttpUtility.UrlEncode(password);

            var req = (HttpWebRequest) WebRequest.Create("https://mtgox.com/code/getFunds.php");

            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";
            req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
            req.Accept = "application/json";

            byte[] bytes = Encoding.ASCII.GetBytes(parameters);
            req.ContentLength = bytes.Length;

            Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);
            os.Close();

            WebResponse resp = req.GetResponse();

            try
            {
                var sr = new StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd().Trim();
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                Logger.FatalException(ex.InnerException.ToString(), ex);   
                return null;
            }
        } // end HttpPost


What got me stuck in the very beginning was that I lacked the UserAgent. This lead to TimeOuts without any (for me obvious) reason. After that I was having some issues with the combination of Url/HtmlEncode and the ContentType...

Any feedback appreciated.


Cheers
txcoin

PS:
As this may become out of date pretty much any moment, also look out for comments by "SlipperySlope" on how to do it in Java. The only change you have to make is that whenever we writes that he is using HtmlEncoding, in C# the UrlEncoding is needed.

PPS: Now I know why I need UrlEncode instead of HtmlEncode: it is the ContentType header Cheesy

PPPS: Yes, this is some kind of x-post to the thread http://forum.bitcoin.org/index.php?topic=25644
newbie
Activity: 32
Merit: 0
July 09, 2011, 10:46:34 AM
#22
@NYConsultant

I'd like to see you C# code as I am still stuck at the error must log in stage...

Would you post it here?

Otherwise, feel free to email me the cs file. I am using gmail with the same username.

Cheers
txcoin
newbie
Activity: 21
Merit: 0
July 09, 2011, 12:11:13 AM
#21
You guys do realize that you need to issue a POST to that url with your credentials as POST'ed variables?  Hitting it from the browser with your credentials as query string parameters will always yield that error message.

If you need some C# code to illustrate this, let me know; i've written a c# api that will talk to the MTGox api for you
newbie
Activity: 40
Merit: 0
July 08, 2011, 04:42:03 PM
#20
I get:

{"error":"Bad token"}

Regards,

I just said screw it and wrote my program to use the normal user interface.
member
Activity: 84
Merit: 10
July 08, 2011, 03:12:11 AM
#19
OK, small update. I just realized my script was not working anymore because they added something new in the ticker ("average"). If it can save you some time... Wink)

does that mean the trade API is working?

API was working perfectly 2 days ago. I stopped using it yesterday to update my computer but till there it was OK. However sometimes it's slow to get some feeds like balance or orders (the ones you have to log in).
sr. member
Activity: 387
Merit: 250
July 07, 2011, 10:20:43 PM
#18
Mtgox's feed seem to go up and down all the time.  An easy way to see if the problem is you or them is to look at other sites like bitcoinity.com to see if their feed is stuck, too.
hero member
Activity: 540
Merit: 500
The future begins today
July 07, 2011, 08:15:39 PM
#17
I get:

{"error":"Bad token"}

Regards,
newbie
Activity: 13
Merit: 0
July 07, 2011, 12:45:27 PM
#16
I can confirm the "basic" api of mt gox and tradehill works

price / market / orders / buy and sell
newbie
Activity: 40
Merit: 0
July 07, 2011, 12:31:34 PM
#15
OK, small update. I just realized my script was not working anymore because they added something new in the ticker ("average"). If it can save you some time... Wink)

does that mean the trade API is working?
member
Activity: 84
Merit: 10
June 30, 2011, 05:17:02 PM
#14
OK, small update. I just realized my script was not working anymore because they added something new in the ticker ("average"). If it can save you some time... Wink)
member
Activity: 84
Merit: 10
June 30, 2011, 04:03:59 PM
#13
I just tried my test scripts for the Mt Gox Trading API and they also gave me the reported error.  However in my development work yesterday I discovered a sequence of commands that works.  Once logged in, only the last command needs to be input.  These are using the curl linux command line utility.  And I also have a Java version that I'm now updating to recover from the reported error using this protocol.  Note that the user and password must be HTML encoded.

Code:
curl -v -k --referer https://mtgox.com https://mtgox.com/users/login

curl -v -k --referer https://mtgox.com/users/login --data "name=XXX&pass=YYY" https://mtgox.com/users/login

curl -v -k --referer https://mtgox.com/users/login https://mtgox.com/

curl -v -k --referer http://mtgox.com/ --data "name=XXX&pass=YYY" -H "Accept: application/json" https://mtgox.com/code/getFunds.php

Thanks for sharing this. I am using curl as well, fantastic little utility. FYI here below are the lines I use:

Code:
curl -s -k https://mtgox.com/code/data/ticker.php
curl -s -k -d "name=$user&pass=$pass" https://mtgox.com/code/getFunds.php
curl -s -k -d "name=$user&pass=$pass&oid=$oid&type=$type" https://mtgox.com/code/cancelOrder.php
curl -s -k -d "name=$user&pass=$pass&amount=$amount_to_buy&price=$buy" https://mtgox.com/code/buyBTC.php

So it's a bit different... but yours work at the moment, mine was working before. If it's not fixed by this weekend I will modify my code.
newbie
Activity: 4
Merit: 0
June 30, 2011, 02:50:12 PM
#12
Hey,

yeah, thanks for the reply in the other thread. Well, i'm getting this ticker stuff working but now i'm trying to implement the "trading" functionality, but it's hard to develop a communication with an API, which does not work...Please inform me, when you are able to communicate in JAVA with the API, for example if you can place a buy or sell.
Thanks for the help!
hero member
Activity: 686
Merit: 501
Stephen Reed
June 30, 2011, 10:47:59 AM
#11
Have the same Problems.
By the way...Anyone knows an existing Java implementation für the Mt.Gox-API ? I have Problems to set a POST https-message.
If anyone has a short JAVA-script for me, i would be so thankful!

Hi.  Did you see my Java HTTPS snippet posted to your request on another thread?  If not, just respond here and I'll post my latest Java POST to get the Mt Gox funds balance - assuming that one is properly logged in.
hero member
Activity: 686
Merit: 501
Stephen Reed
June 30, 2011, 10:31:21 AM
#10
I just tried my test scripts for the Mt Gox Trading API and they also gave me the reported error.  However in my development work yesterday I discovered a sequence of commands that works.  Once logged in, only the last command needs to be input.  These are using the curl linux command line utility.  And I also have a Java version that I'm now updating to recover from the reported error using this protocol.  Note that the user and password must be HTML encoded.

Code:
curl -v -k --referer https://mtgox.com https://mtgox.com/users/login

curl -v -k --referer https://mtgox.com/users/login --data "name=XXX&pass=YYY" https://mtgox.com/users/login

curl -v -k --referer https://mtgox.com/users/login https://mtgox.com/

curl -v -k --referer http://mtgox.com/ --data "name=XXX&pass=YYY" -H "Accept: application/json" https://mtgox.com/code/getFunds.php
member
Activity: 84
Merit: 10
June 30, 2011, 04:19:18 AM
#9
FYI just received this message from Mtgox:

Quote
Hello,

It will be active by beginning of next week.

Sorry for the inconvenience and thank you for using our site and you have any other questions feel free to contact us by sending us an

mail.

Thanks,

MtGox.com Team
member
Activity: 84
Merit: 10
June 28, 2011, 04:26:31 PM
#8
I am sure some will be interested in your C# library. For now I am just starting with C++...  Cheesy Thanks anyway!
newbie
Activity: 40
Merit: 0
June 28, 2011, 03:57:15 PM
#7
I am thinking about just skipping over the API and just logging into the site like a "normal user."

Slightly unrelated, but would anyone be interested in me releasing my mtGox C# library?
member
Activity: 179
Merit: 18
June 28, 2011, 03:32:58 PM
#6
down for me as well. when will mt.gox run smoothly? seems like they're always encountering problems.
Pages:
Jump to: