Я пытаюсь получить хотя бы сводку учетной записи, но у меня ничего не получается.
Можем ли мы попытаться получить нужные функции, чтобы каждый мог их использовать?
Вот ссылка на документ
В основном только 2 функции, как показано ниже, классы удалены для упрощения:
Код: Выделить всё
using Newtonsoft.Json;
using RestSharp;
using System.Security.Cryptography;
using System.Text;
namespace Crypto.Account
{
internal class AccountSummary
{
private readonly string apiKey = "xxxxxx";
private readonly string apiSecret = "xxxxx";
private readonly string apiUrl = "https://api.crypto.com/v2/private/get-account-summary";
public AccountResponse GetAccountSummary()
{
var client = new RestClient();
var request = new RestRequest(apiUrl, Method.Post);
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
string sign = GetSignature(timestamp);
var requestBody = new
{
id = 1,
method = "private/get-account-summary",
@params = new { },
nonce = timestamp,
api_key = apiKey,
sig = sign
};
request.AddJsonBody(requestBody);
var response = client.Execute(request);
if (response.IsSuccessful)
{
//return JsonConvert.DeserializeObject(response.Content);
return "hooray";
}
else
{
throw new Exception($"Error: {response.StatusCode}, {response.Content}");
}
}
private string GetSignature(long timestamp)
{
string sigPayload = $"{apiKey}{timestamp}private/get-account-summary";
using (var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(apiSecret)))
{
var hash = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(sigPayload));
return BitConverter.ToString(hash).Replace("-", "").ToLower();
}
}
}
}
10002 401 НЕСАНКЦИОНИРОВАНО Не проверено, или ключ/подпись неверны
или это
10003 401 IP_ILLEGAL IP-адрес не внесен в белый список
Что нужно исправить? Есть предложения?
Подробнее здесь: https://stackoverflow.com/questions/786 ... api-how-to
Мобильная версия