Can't create Kucoin private token with C#

88 Views Asked by At

i try create a Kucoin private token, and always get response "Invalid KC-API-PASSPHRASE". What i'm doing wrong:

static string HmacSha256(string message, string secret)
{
 var msgBytes = Encoding.UTF8.GetBytes(message);
 var secretBytes = Encoding.UTF8.GetBytes(secret);
 var hmac = new HMACSHA256(secretBytes);

 var hash = hmac.ComputeHash(msgBytes);

  return Convert.ToBase64String(hash);
}

var path = "/api/v1/bullet-private";
var timestamp = DateTime.UtcNow.ConvertToUnixMilliseconds().ToString();
var payload = $"{timestamp}POST{path}";
var signature = HmacSha256(payload, _secretKey);
var request = new HttpRequestMessage(HttpMethod.Post, $"{_baseUrl}{path}")
{
  Headers =
  {
    { "KC-API-SIGN", signature },
    { "KC-API-TIMESTAMP", timestamp },
    { "KC-API-KEY", _apiKey },
    { "KC-API-PASSPHRASE", HmacSha256(_passPhrase, _secretKey) },
    { "KC-API-KEY-VERSION", "2" }
  }
};

For the KC-API-PASSPHRASE of the header:

For API key-V1.0, please pass requests in plaintext. For API key-V2.0, please Specify KC-API-KEY-VERSION as 2 --> Encrypt passphrase with HMAC-sha256 via API-Secret --> Encode contents by base64 before you pass the request."

0

There are 0 best solutions below