Skip to content

Instantly share code, notes, and snippets.

@hitbtc-com
Created March 27, 2014 14:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hitbtc-com/9808530 to your computer and use it in GitHub Desktop.
Save hitbtc-com/9808530 to your computer and use it in GitHub Desktop.
using RestSharp;
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Hitbtc.Api.Demo
{
class Program
{
static void Main(string[] args)
{
const string apiKey = "xxx";
const string secretKey = "yyy";
var client = new RestClient("https://api.hitbtc.com");
var request = new RestRequest("/api/1/trading/balance", Method.GET);
request.AddParameter("nonce", GetNonce());
request.AddParameter("apikey", apiKey);
string sign = CalculateSignature(client.BuildUri(request).PathAndQuery, secretKey);
request.AddHeader("X-Signature", sign);
var response = client.Execute(request);
Console.WriteLine(response.Content);
}
private static long GetNonce()
{
return DateTime.Now.Ticks * 10 / TimeSpan.TicksPerMillisecond; // use millisecond timestamp or whatever you want
}
public static string CalculateSignature(string text, string secretKey)
{
using (var hmacsha512 = new HMACSHA512(Encoding.UTF8.GetBytes(secretKey)))
{
hmacsha512.ComputeHash(Encoding.UTF8.GetBytes(text));
return string.Concat(hmacsha512.Hash.Select(b => b.ToString("x2")).ToArray()); // minimalistic hex-encoding and lower case
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment