Example #1
0
        public async Task WaitsBetweenQueries()
        {
            var throttleDelayMs = 200;
            var queriesCount    = 5;

            var configuration = new CryptoCompareApiConfiguration
            {
                ApiKey          = new Secrets().ApiKey,
                ThrottleDelayMs = throttleDelayMs
            };
            var options = Options.Create(configuration);
            var client  = new CryptoCompareClient(options);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            await Task.WhenAll(Enumerable.Repeat("start", queriesCount)
                               .Select(async _ => await client.RateLimits.CurrentHourAsync()));


            stopWatch.Stop();

            var minExpectedElapsedTime = queriesCount * throttleDelayMs;

            Assert.True(stopWatch.ElapsedMilliseconds > minExpectedElapsedTime,
                        $"Elapsed time should have been greater than {minExpectedElapsedTime}ms, but was {stopWatch.ElapsedMilliseconds}ms.");
        }
        public CryptoCompareApiFixture()
        {
            var configuration = new CryptoCompareApiConfiguration {
                ApiKey = new Secrets().ApiKey
            };
            var options = Options.Create(configuration) !;

            CryptoCompareClient = new CryptoCompareClient(options);
        }
Example #3
0
        public static IServiceCollection AddCryptoCompareClient(
            this IServiceCollection services, CryptoCompareApiConfiguration configuration)
        {
            var options = Options.Create(configuration);

            services.AddSingleton(options);
            AddCommonDependencies(services);

            return(services);
        }
        public WebSocketClientIntegrationTests(ITestOutputHelper output)
        {
            _output = output;
            var streamer           = new WebSocketStreamer();
            var apiDetailsProvider = new CryptoCompareApiConfiguration {
                ApiKey = new Secrets().ApiKey
            };
            var clientWebSocket = new WrappedClientWebsocket();

            _client = new CryptoCompareWebSocketClient(clientWebSocket, Options.Create(apiDetailsProvider), streamer);
        }
        public WebSocketClientTests(ITestOutputHelper output)
        {
            _apiConfiguration = new CryptoCompareApiConfiguration
            {
                WebSocketBaseUrl = "wss://hello",
                ApiKey           = "abcdefg"
            };
            _innerClient       = Substitute.For <IClientWebsocket>();
            _webSocketStreamer = Substitute.For <IWebSocketStreamer>();

            _webSocketClient = new CryptoCompareWebSocketClient(_innerClient, Options.Create(_apiConfiguration), _webSocketStreamer);
        }
Example #6
0
        public void Services_should_be_built()
        {
            var configuration = new CryptoCompareApiConfiguration {
                ApiKey = ""
            };

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddCryptoCompareClient(configuration);

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var socketStreamer  = serviceProvider.GetRequiredService <IWebSocketStreamer>();
        }