I cannot get data from the BitStamp API. What am I doing wrong here? My content generates an error response result:
{"error": "Missing key, signature and nonce parameters"} public ActionResult Index() { const string BaseUrl = "https://www.bitstamp.net/api/balance/"; var client = new RestClient(); var request = new RestRequest(); client.BaseUrl = BaseUrl; AddApiAuthentication(request); var response = client.Execute(request); var foo = response.Content; //{"error": "Missing key, signature and nonce parameters"} return View(); } public void AddApiAuthentication(RestRequest restRequest) { var nonce = DateTime.Now.Ticks; var signature = GetSignature(nonce, apiKey, apiSecret, clientId); restRequest.AddParameter("key", apiKey); restRequest.AddParameter("signature", signature); restRequest.AddParameter("nonce", nonce); } private string GetSignature(long nonce, string key, string secret, string clientId) { string msg = string.Format("{0}{1}{2}", nonce, clientId, key); return ByteArrayToString(SignHMACSHA256(secret, StrinToByteArray(msg))).ToUpper(); } public static byte[] SignHMACSHA256(String key, byte[] data) { HMACSHA256 hashMaker = new HMACSHA256(Encoding.ASCII.GetBytes(key)); return hashMaker.ComputeHash(data); } public static byte[] StrinToByteArray(string str) { return System.Text.Encoding.ASCII.GetBytes(str); } public static string ByteArrayToString(byte[] hash) { return BitConverter.ToString(hash).Replace("-", "").ToLower(); }
API authentication seems to work for the user in this post . Do I execute the request correctly?
c # api bitcoin restsharp
Freddy
source share