hello experts
i am trying to use this project
https://bitbucket.org/pipe2grep/cryptocoinxchange/overview (linked from
https://en.bitcoin.it/wiki/MtGox/API/HTTP/v2) to access mtGox api.
- commands requiring authentication work (GetAccountInfo etc.)
- commands for trading do not work
I am getting the following error
"Response contained error: {"result":"error","error":"Identification required to access private API","token":"login_error_invalid_rest_sign"}"Does anyone here by chance know what the problem might be?
- i have "Trade" checked among the rights for the api key i am using in the mtGox security center
- i have checked the implementation (attached) against the best specification I could find (
https://bitbucket.org/nitrous/mtgox-api/overview#markdown-header-security) and seems to be OK
protected override RestRequest CCXRestSharpAuthenticate(RestRequest req, object parameters, AccessType accessType)
{
if (accessType == AccessType.Public) return req;
if(TestedApi && !ValidApiKey)
throw new MissingFieldException("You must configure your API Key");
Int64 nonce = DateTime.Now.Ticks;
string endpoint = req.Resource;
string post = "nonce=" + nonce;
NameValueCollection nvc = parameters as NameValueCollection;
if (nvc != null)
{
post += ToQueryString(nvc);
foreach (string s in nvc.Keys)
{
req.AddParameter(s, nvc[s]);
}
}
string prefix = endpoint;
string sign = getHash(Convert.FromBase64String(APISecret), prefix + Convert.ToChar(0) + post);
req.AddHeader("Rest-Key", APIKey);
req.AddHeader("Rest-Sign", sign);
req.AddParameter("nonce", nonce);
return req;
}
private string getHash(byte[] keyByte, String message)
{
var hmacsha512 = new HMACSHA512(keyByte);
var messageBytes = Encoding.UTF8.GetBytes(message);
return Convert.ToBase64String(hmacsha512.ComputeHash(messageBytes));
}
public string ToQueryString(NameValueCollection parameters)
{
if (parameters != null)
{
return "&" + string.Join("&", Array.ConvertAll(parameters.AllKeys, key => string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(parameters[key]))));
}
return "";
}