示例#1
0
        public async Task GetAuthenticationToken_ReturnsCorrectSignature(Int32 timestamp, String method, String request, String body, String signiture)
        {
            // Arrange
            var clock = Substitute.For <ISystemClock>();

            clock.UnixTimestamp.Returns(timestamp);

            var apiKey          = "thisisafakekeythisisafakekey1234";
            var apiPassphrase   = "thisisafake";
            var apiSecret       = "thisisafakesecretthisisafakesecretthisisafakesecretthisisafakesecretthisisafakesecret+==";
            var applicationName = "test-application";

            var credentials = new GdaxCredentials(apiKey, apiPassphrase, apiSecret, applicationName);
            var handler     = new GdaxAuthenticationHandler(credentials, clock)
            {
                InnerHandler = new NoopHandler()
            };

            var http = new HttpClient(handler);

            // Act
            var response = await http.SendAsync(new HttpRequestMessage
            {
                Method     = new HttpMethod(method),
                RequestUri = new Uri("https://test.com" + request),
                Content    = body == null ? null : new StringContent(body)
            });

            // Assert
            response.RequestMessage.Headers.GetValues("CB-ACCESS-KEY").Single().ShouldBe(apiKey);
            response.RequestMessage.Headers.GetValues("CB-ACCESS-SIGN").Single().ShouldBe(signiture);
            response.RequestMessage.Headers.GetValues("CB-ACCESS-TIMESTAMP").Single().ShouldBe(timestamp.ToString(CultureInfo.InvariantCulture));
            response.RequestMessage.Headers.GetValues("CB-ACCESS-PASSPHRASE").Single().ShouldBe(apiPassphrase);
            response.RequestMessage.Headers.GetValues("User-Agent").Single().ShouldBe(applicationName);
        }
示例#2
0
        public GdaxApiClient(GdaxCredentials credentials, ISerializer serializer = null, bool sandbox = false)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            this.Serializer = serializer ?? new Serializer();
            this.httpClient = new HttpClient(new GdaxAuthenticationHandler(credentials)
            {
                InnerHandler = new HttpClientHandler()
            });
            this.hasOwnershipOfHttpClient = true;
            this.BaseUri = sandbox ? BaseUriSandbox : BaseUriPublic;
        }
示例#3
0
 public GdaxApiClient(GdaxCredentials credentials, ISerializer serializer = null, bool sandbox = false)
     : this(new GdaxAuthenticationHandler(credentials) { InnerHandler = new HttpClientHandler() }, serializer, sandbox)
 {
 }