Bitcoin Forum
May 05, 2024, 12:40:52 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: mtGox Trading API down? [solved]  (Read 2307 times)
NYConsultant
Newbie
*
Offline Offline

Activity: 21
Merit: 0


View Profile
July 09, 2011, 05: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
1714912852
Hero Member
*
Offline Offline

Posts: 1714912852

View Profile Personal Message (Offline)

Ignore
1714912852
Reply with quote  #2

1714912852
Report to moderator
1714912852
Hero Member
*
Offline Offline

Posts: 1714912852

View Profile Personal Message (Offline)

Ignore
1714912852
Reply with quote  #2

1714912852
Report to moderator
1714912852
Hero Member
*
Offline Offline

Posts: 1714912852

View Profile Personal Message (Offline)

Ignore
1714912852
Reply with quote  #2

1714912852
Report to moderator
According to NIST and ECRYPT II, the cryptographic algorithms used in Bitcoin are expected to be strong until at least 2030. (After that, it will not be too difficult to transition to different algorithms.)
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714912852
Hero Member
*
Offline Offline

Posts: 1714912852

View Profile Personal Message (Offline)

Ignore
1714912852
Reply with quote  #2

1714912852
Report to moderator
1714912852
Hero Member
*
Offline Offline

Posts: 1714912852

View Profile Personal Message (Offline)

Ignore
1714912852
Reply with quote  #2

1714912852
Report to moderator
1714912852
Hero Member
*
Offline Offline

Posts: 1714912852

View Profile Personal Message (Offline)

Ignore
1714912852
Reply with quote  #2

1714912852
Report to moderator
txcoin
Newbie
*
Offline Offline

Activity: 32
Merit: 0


View Profile
July 09, 2011, 03:46:34 PM
 #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
txcoin
Newbie
*
Offline Offline

Activity: 32
Merit: 0


View Profile
July 09, 2011, 04:43:28 PM
 #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
itake (OP)
Newbie
*
Offline Offline

Activity: 40
Merit: 0


View Profile
July 09, 2011, 06: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:
<script type="text/javascript" language="javascript">
var token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

</script>


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]

txcoin
Newbie
*
Offline Offline

Activity: 32
Merit: 0


View Profile
July 10, 2011, 01:57:47 PM
 #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
Pages: « 1 [2]  All
  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!