Created
March 27, 2014 14:17
-
-
Save hitbtc-com/9808530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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