Answer the question
In order to leave comments, you need to log in
How to get authorized on the site?
you need to log in to yobit. help me figure out what I'm writing wrong. Excerpt from there
Every Trade API request must be authenticated.
Authentication occurs by sending the following HTTP headers:
Key - API key, example: FAF816D16FFDFBD1D46EEF5D5B10D8A2
Sign - digital signature, POST parameters (?param0=val0 & ...& nonce=1) signed with a secret key using HMAC-SHA512
nonce parameter (minimum 1, maximum 2147483646) each new request must be greater than the value from the previous request.
To reset the nonce, you need to create a new key
, I write the following code:
public int nonce { get; set; }
string answer { get; set; }
public string youbit()
{
string api = "https://yobit.net/tapi/";
string key = "";
string secret= "";
nonce = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
string prarametrs = $"method=getInfo&nonce=" +
+nonce;
var keybol = Encoding.UTF8.GetBytes(secret);
var param = Encoding.UTF8.GetBytes(prarametrs);
using(HMACSHA512 hma=new HMACSHA512(keybol))
{
var inpo = hma.ComputeHash(param);
var hex1 = new StringBuilder(inpo.Length * 2);
foreach (var b in inpo) hex1.AppendFormat("{0:x2}", b);
string sign1 = hex1.ToString();
using (var ht=new HttpRequest())
{
ht.AddHeader("Key", key);
ht.AddHeader("Sign", inpo.ToString());
ht.AddHeader(HttpHeader.ContentType, "application/x-www-form-urlencoded");
ht.ConnectTimeout=20000;
answer = ht.Post(api).ToString() ;
}
}
return answer;
}
Answer the question
In order to leave comments, you need to log in
разобрался, надо добавлять параметры в запрос такие же как и в header.
пример:
public string youbit()
{
string api = "https://yobit.net/tapi/";
string key = "ВАШ АПИ КЛЮЧ";
string secret= "Секретный ключ";
nonce = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;// время, можете прибавлять +1 сами, кому как удобно. Главное что б новое число было больше другого.
string prarametrs = "method=getInfo&nonce=" + nonce.ToString();// параметры которые будут шифроваться в HMA512
var keybol = Encoding.UTF8.GetBytes(secret);//переводим в байты
var param = Encoding.UTF8.GetBytes(prarametrs);
using(HMACSHA512 hma=new HMACSHA512(keybol))//keybol-подпись
{
var inpo = hma.ComputeHash(param);
var hex1 = new StringBuilder(inpo.Length * 2);
foreach (var b in inpo) hex1.AppendFormat("{0:x2}", b);
string sign1 = hex1.ToString();// конвертация в string все то что зашифровалось.
using (var ht=new HttpRequest())
{
ht.AddHeader(HttpHeader.ContentType, "application/x-www-form-urlencoded");
ht.AddHeader("Key", key);//головы вашего запроса + ключ
ht.AddHeader("Sign", sign1);// зашифрованные данные
var bestie = new RequestParams();// параметры запроса
bestie["method"] = "getInfo";
bestie["nonce"] = nonce.ToString();
answer = ht.Post(api,bestie).ToString(); // метод POST
}
}
return answer;//возращает ответ
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question