Bitcoin Forum
December 09, 2016, 09:22:25 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: « 1 [2]  All
  Print  
Author Topic: mtGox Trading API down? [solved]  (Read 2071 times)
NYConsultant
Newbie
*
Offline Offline

Activity: 21


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
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
txcoin
Jr. Member
*
Offline Offline

Activity: 32


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

1AcwaWn5Xu1LjWBts6YjQyumWaEg6Mh9jb
txcoin
Jr. Member
*
Offline Offline

Activity: 32


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

1AcwaWn5Xu1LjWBts6YjQyumWaEg6Mh9jb
itake
Jr. Member
*
Offline Offline

Activity: 39


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

Activity: 32


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

1AcwaWn5Xu1LjWBts6YjQyumWaEg6Mh9jb
Pages: « 1 [2]  All
  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!