I'm having some trouble getting the NewOrder api to work
The Server Always Returns "Invalid" Api key , The Get Method Works !
https://hitbtc.com/api
post url: /api/1/trading/new_order?nonce=1395049771755&apikey=f6ab189hd7a20 07e01d95667de3c493d
post data: clientOrderId=11111112&symbol=BTCUSD&side=buy&pric e=0.1&quantity=100&type=limit&timeInForce=GTC
php example; https://gist.github.com/hitbtc-com/10885873
sorce
Code:
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 VARrequest = new RestRequest("/api/1/trading/new_order", Method.POST);
VARrequest.AddParameter("nonce", GetNonce());
VARrequest.AddParameter("apikey", apiKey);
string sign = CalculateSignature(client.BuildUri(VARrequest).PathAndQuery, secretKey);
VARrequest.AddHeader("X-Signature", sign);
VARrequest.RequestFormat = DataFormat.Json;
VARrequest.AddBody(new
{
clientOrderId = "58f32654-723a-4b60-ad6b",
symbol = "BTCUSD",
side = "buy",
quantity = "0.01",
type = "limit" ,
price = "788.56",
timeInForce = "GTC" });
var VARresponse = client.Execute(VARrequest);
Console.WriteLine(VARresponse.Content);
System.Threading.Thread.Sleep(5000);
}
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
}
}
}
}