MTGox HTTP API v2 の呼び出しに問題があります。通常、すべてのリクエストを処理する sendrequest 関数を作成しました。MONEY/INFO または MONEY/ORDERS ではうまく機能しますが、メソッド MONEY/ORDER/QUOTE または MONEY/ORDER/ADD を試すと 500 内部サーバー エラーが発生します。
post_data にナンス以外のものが含まれていると、うまくいかないようです。これを解決するにはどうすればよいですか?
sendrequest 関数:
private string sendRequest(string action, NameValueCollection query)
{
NameValueCollection nvc = new NameValueCollection();
nvc.Add("nonce", DateTime.Now.Ticks.ToString());
nvc.Add(query);
String post_data = "";
for (int i = 0; i < nvc.Count; i++)
{
post_data += "&";
post_data += nvc.Keys[i];
post_data += "=";
post_data += nvc[i];
}
post_data = post_data.Substring(1);
action = "BTCEUR/money/" + action;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sBasePath + action);
action += "\0"+post_data;
req.Method = "POST";
HMACSHA512 hmac = new HMACSHA512(GetBytes(action));
hmac.Key = Convert.FromBase64String(secret);
String sign = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(action)), Base64FormattingOptions.None);
req.Headers.Add("Rest-Key", apikey);
req.Headers.Add("Rest-Sign", sign);
req.UserAgent = "Mozilla/4.0 (compatible; MtGoxTradeCLI)";
req.ContentType = "application/x-www-form-urlencoded";
StreamWriter reqStream = new StreamWriter(req.GetRequestStream());
reqStream.Write(post_data);
reqStream.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader respStream = new StreamReader(resp.GetResponseStream());
String response = respStream.ReadToEnd();
respStream.Close();
return response;
}