I am trying to write simple application for myself and when i try to call getInfo method i always get a error into the response. Key, sign, method or nonce is incorrect. I found a number of examples but i still can't find mistake in my code. Could anyone help me with it? My code:
const string key = "072BCC223A1ADBE86854A4B4A9468EAB";
const string secret = "4c962093fb943d418afb8fae14841c6b";
const string tapi = "
https://yobit.net/tapi";
public void GetInfo() {
int nonce = 1;
string parameters = $"method=getInfo&nonce=1";
string address = $"{tapi}?{parameters}";
var keyByte = Encoding.UTF8.GetBytes(secret);
string sign1 = string.Empty;
byte[] inputBytes = Encoding.UTF8.GetBytes(parameters);
using (var hmac = new HMACSHA512(keyByte))
{
byte[] hashValue = hmac.ComputeHash(inputBytes);
StringBuilder hex1 = new StringBuilder(hashValue.Length * 2);
foreach (byte b in hashValue)
{
hex1.AppendFormat("{0:x2}", b);
}
sign1 = hex1.ToString();
}
WebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(address);
if (webRequest != null)
{
webRequest.Method = "POST";
webRequest.Timeout = 20000;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Headers.Add("Key", key);
webRequest.Headers.Add("Sign", sign1);
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream())
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
{
var jsonResponse = sr.ReadToEnd();
Console.WriteLine(String.Format("Response: {0}", jsonResponse));
}
}
}
Log(nonce.ToString());
}
KeyAPI - InfoOnly, I specially hardcode nonce as 1 because i think that it will be easier to find a problem.