protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (CanMakeAuthenticatedRequest(payload)) { string payloadForm = CryptoUtility.GetFormForPayload(payload, false); request.Headers["API-Key"] = PublicApiKey.ToUnsecureString(); request.Headers["Sign"] = CryptoUtility.SHA256Sign(payloadForm, PrivateApiKey.ToBytes()).ToUpperInvariant(); await request.WriteToRequestAsync(payloadForm); } }
protected override Uri ProcessRequestUrl(UriBuilder url, Dictionary <string, object> payload, string method) { if (CanMakeAuthenticatedRequest(payload)) { // payload is ignored, except for the nonce which is added to the url query - bittrex puts all the "post" parameters in the url query instead of the request body var query = HttpUtility.ParseQueryString(url.Query); string newQuery = "timestamp=" + payload["nonce"].ToStringInvariant() + (query.Count == 0 ? string.Empty : "&" + query.ToString()) + (payload.Count > 1 ? "&" + CryptoUtility.GetFormForPayload(payload, false) : string.Empty); string signature = CryptoUtility.SHA256Sign(newQuery, CryptoUtility.ToBytes(PrivateApiKey)); newQuery += "&signature=" + signature; url.Query = newQuery; return(url.Uri); } return(base.ProcessRequestUrl(url, payload, method)); }
protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (CanMakeAuthenticatedRequest(payload)) { if (string.IsNullOrWhiteSpace(CustomerId)) { throw new APIException("Customer ID is not set for Bitstamp"); } // messageToSign = nonce + customer_id + api_key string apiKey = PublicApiKey.ToUnsecureString(); string messageToSign = payload["nonce"].ToStringInvariant() + CustomerId + apiKey; string signature = CryptoUtility.SHA256Sign(messageToSign, PrivateApiKey.ToUnsecureString()).ToUpperInvariant(); payload["signature"] = signature; payload["key"] = apiKey; await CryptoUtility.WritePayloadFormToRequestAsync(request, payload); } }
protected override async Task ProcessRequestAsync(HttpWebRequest request, Dictionary <string, object> payload) { if (CanMakeAuthenticatedRequest(payload)) { request.Headers.Add("KC-API-KEY", PublicApiKey.ToUnsecureString()); request.Headers.Add("KC-API-NONCE", payload["nonce"].ToStringInvariant()); var endpoint = request.RequestUri.AbsolutePath; var message = string.Format("{0}/{1}/{2}", endpoint, payload["nonce"], CryptoUtility.GetFormForPayload(payload, false)); var sig = CryptoUtility.SHA256Sign(Convert.ToBase64String(Encoding.UTF8.GetBytes(message)), PrivateApiKey.ToUnsecureString()); request.Headers.Add("KC-API-SIGNATURE", sig); if (request.Method == "POST") { string msg = CryptoUtility.GetFormForPayload(payload, false); using (Stream stream = await request.GetRequestStreamAsync()) { byte[] content = Encoding.UTF8.GetBytes(msg); stream.Write(content, 0, content.Length); } } } }