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)) { // ensure nonce is the last parameter string nonce = payload["nonce"].ToStringInvariant(); payload.Remove("nonce"); var msg = CryptoUtility.GetFormForPayload(payload) + "&nonce=" + nonce; var sig = CryptoUtility.SHA512Sign(msg, CryptoUtility.ToBytes(PrivateApiKey)).ToLower(); request.Headers.Add("Sign", sig); request.Headers.Add("Key", PublicApiKey.ToUnsecureString()); using (Stream stream = await request.GetRequestStreamAsync()) { byte[] content = Encoding.UTF8.GetBytes(msg); stream.Write(content, 0, content.Length); } } }