Esempio n. 1
0
        private String ComputeSignature(GdaxRequest request)
        {
            var data    = Convert.FromBase64String(this.secret);
            var prehash = request.Timestamp + request.HttpMethod.ToString().ToUpper() + request.RequestUrl + request.RequestBody;

            return(HashString(prehash, data));
        }
Esempio n. 2
0
        public AuthenticationToken GetAuthenticationToken(GdaxRequest request)
        {
            var timestamp = (request.Timestamp).ToString(CultureInfo.InvariantCulture);
            var signature = ComputeSignature(request);

            return(new AuthenticationToken(this.apiKey, signature, timestamp, this.passphrase));
        }
Esempio n. 3
0
        public async Task <HttpResponseMessage> GetResponseAsync(GdaxRequest request)
        {
            var httpRequest = this.BuildRequestMessagee(request);

            httpRequest.Headers.Add("User-Agent", @"gdax-dotnet");

            return(await this.http.SendAsync(httpRequest).ConfigureAwait(false));
        }
Esempio n. 4
0
        public async Task <GdaxResponse <TResponse> > GetResponseAsync <TResponse>(GdaxRequest request)
        {
            var httpResponse = await this.GetResponseAsync(request).ConfigureAwait(false);

            var contentBody = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(new GdaxResponse <TResponse>(
                       httpResponse.Headers.ToArray(),
                       httpResponse.StatusCode,
                       contentBody,
                       this.serialzer.Deserialize <TResponse>(contentBody)
                       ));
        }
Esempio n. 5
0
        public GdaxRequest Build()
        {
            var uriBuilder       = new StringBuilder(this.relativePath);
            var isFirstParameter = true;

            void AppendParameter(String key, String value)
            {
                if (isFirstParameter)
                {
                    uriBuilder.Append("?");
                    isFirstParameter = false;
                }
                else
                {
                    uriBuilder.Append("&");
                }

                uriBuilder.Append(WebUtility.UrlEncode(key));
                uriBuilder.Append("=");
                Debug.WriteLine(value);
                uriBuilder.Append(value);
                //uriBuilder.Append(WebUtility.UrlEncode(value));
            }

            void AppendParameters(IDictionary <String, String> parameters)
            {
                foreach (var parameter in parameters)
                {
                    AppendParameter(parameter.Key, parameter.Value);
                }
            }

            AppendParameters(this.queryParameters);

            var additionalParameters = this.GetAdditionalParameters();

            if (additionalParameters != null)
            {
                AppendParameters(additionalParameters);
            }

            var request = new GdaxRequest(this.method, uriBuilder.ToString());

            if (this.body != null)
            {
                request.RequestBody = this.body;
            }

            return(request);
        }
Esempio n. 6
0
        private HttpRequestMessage BuildRequestMessagee(GdaxRequest request)
        {
            var requestMessage = new HttpRequestMessage
            {
                RequestUri = new Uri(this.BaseUri, request.RequestUrl),
                Method     = request.HttpMethod
            };

            if (request.RequestBody != null)
            {
                requestMessage.Content = new StringContent(request.RequestBody, Encoding.UTF8, "application/json");
            }

            return(requestMessage);
        }
Esempio n. 7
0
        public async Task <HttpResponseMessage> GetResponse(GdaxRequest request)
        {
            var httpRequest = this.BuildRequestMessagee(request);

            var response = await this.http.SendAsync(httpRequest).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var error = this.serialzer.Deserialize <GdaxErrorMessage>(body);

                throw new GdaxException(error.Message);
            }

            return(response);
        }
Esempio n. 8
0
        private HttpRequestMessage BuildRequestMessagee(GdaxRequest request)
        {
            var requestMessage = new HttpRequestMessage
            {
                RequestUri = new Uri(this.BaseUri, request.RequestUrl),
                Method     = request.HttpMethod
            };

            if (request.RequestBody != null)
            {
                requestMessage.Content = new StringContent(request.RequestBody, Encoding.UTF8, "application/json");
            }

            var token = this.authenticator.GetAuthenticationToken(request);

            SetHttpRequestHeaders(requestMessage, token);

            return(requestMessage);
        }