Advertisement
Guest User

mtgox signin c#

a guest
Mar 22nd, 2013
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1.  public void getBalanceV2()
  2.         {
  3.             RestRequest req = signRequestV2(new RestRequest("money/info", Method.POST));
  4.             var resp = rc2.Execute<dynamic>(req);
  5.         }
  6.  
  7.         public RestRequest signRequestV2(RestRequest req)
  8.         {
  9.             String apiKey = ConfigurationManager.AppSettings["MtGoxAPIKey"];
  10.             String apiSecret = ConfigurationManager.AppSettings["MtGoxApiSecret"];
  11.  
  12.             TimeSpan span = DateTime.Now - UnixEpoch;
  13.             double seconds = span.TotalSeconds * 10000;
  14.             Int64 nonce = (Int64)seconds;
  15.  
  16.             string endpoint = req.Resource.ToString();
  17.             string post = "nonce=" + nonce;
  18.             string prefix = endpoint;
  19.  
  20.             string sign = getHash(Convert.FromBase64String(apiSecret), prefix + Convert.ToChar(0) + post);
  21.             req.AddHeader("Rest-Key", apiKey);
  22.             req.AddHeader("Rest-Sign", sign);
  23.             req.AddParameter("nonce", nonce);
  24.  
  25.             return req;
  26.         }
  27.  
  28.         public string getHash(byte[] keyByte, String message)
  29.         {
  30.             var hmacsha512 = new HMACSHA512(keyByte);
  31.             var messageBytes = encoding.GetBytes(message);
  32.             return Convert.ToBase64String(hmacsha512.ComputeHash(messageBytes));
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement