Beispiel #1
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="name">The name of the API this client is for</param>
        /// <param name="options">The options for this client</param>
        protected BaseClient(string name, BaseClientOptions options)
        {
            log = new Log(name);
            log.UpdateWriters(options.LogWriters);
            log.Level = options.LogLevel;

            ClientOptions = options;

            Name = name;

            log.Write(LogLevel.Trace, $"Client configuration: {options}, CryptoExchange.Net: v{typeof(BaseClient).Assembly.GetName().Version}, {name}.Net: v{GetType().Assembly.GetName().Version}");
        }
Beispiel #2
0
        protected BaseClient(HttpClient httpClient, BaseClientOptions options)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrWhiteSpace(options.BaseUrl))
            {
                throw new ArgumentNullException(nameof(options.BaseUrl));
            }
            if (options.Serializer == null)
            {
                throw new ArgumentNullException(nameof(options.Serializer));
            }

            _serializer = options.Serializer;
            _httpClient = httpClient;

            _httpClient.BaseAddress = new Uri(options.BaseUrl);
            _httpClient.Timeout     = options.Timeout;

            _httpClient.DefaultRequestHeaders.Accept.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue(_serializer.MediaType.MediaType)
                );

            if (string.IsNullOrWhiteSpace(_serializer.MediaType.CharSet) == false)
            {
                _httpClient.DefaultRequestHeaders.AcceptCharset.Clear();
                _httpClient.DefaultRequestHeaders.AcceptCharset.Add(
                    new StringWithQualityHeaderValue(_serializer.MediaType.CharSet)
                    );
            }

            _exceptionsTypesByStatusCodes = new Dictionary <HttpStatusCode, Type>
            {
                { HttpStatusCode.NotFound, typeof(NotFoundException) },
                { HttpStatusCode.Unauthorized, typeof(UnauthorizedException) },
                { HttpStatusCode.BadRequest, typeof(BadRequestException) }
            };
        }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="options">The base client options</param>
 /// <param name="apiOptions">The Api client options</param>
 public SocketApiClient(BaseClientOptions options, ApiClientOptions apiOptions) : base(options, apiOptions)
 {
 }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="options">Client options</param>
 /// <param name="apiOptions">Api client options</param>
 protected BaseApiClient(BaseClientOptions options, ApiClientOptions apiOptions)
 {
     Options         = apiOptions;
     _apiCredentials = apiOptions.ApiCredentials?.Copy() ?? options.ApiCredentials?.Copy();
     BaseAddress     = apiOptions.BaseAddress;
 }
 public FakeClient(HttpClient httpClient, BaseClientOptions options) : base(httpClient, options)
 {
 }
Beispiel #6
0
        static void ShowResults(BaseClientOptions options, ClientHandler[] clientHandlers)
        {
            Console.WriteLine($"Test running with {options.Clients} clients and MessageSize={options.MessageSize}");
            Console.WriteLine(options.UseSsl ? "Using SSL" : "Using raw sockets (no SSL)");

            int countAfterWarmup = 0;

            if (options.WarmupTime != 0)
            {
                Console.WriteLine($"Waiting {options.WarmupTime} seconds for warmup");
                Thread.Sleep(options.WarmupTime * 1000);
                Console.WriteLine("Warmup complete");
                countAfterWarmup = GetCurrentRequestCount(clientHandlers);
            }

            Stopwatch timer             = new Stopwatch();
            long      elapsed           = 0; // time in milliseconds
            long      previousElapsed   = 0;
            int       previousCount     = countAfterWarmup;
            int       reportingInterval = options.ReportingInterval > 0 ? options.ReportingInterval :
                                          options.DurationTime > 0 ? options.DurationTime : 1;
            double currentRPS;
            double averageRPS         = 0;
            double previousAverageRPS = 0;
            double drift;

            timer.Start();
            while (true)
            {
                Thread.Sleep(reportingInterval * 1000);

                elapsed = timer.ElapsedMilliseconds;

                int currentCount = GetCurrentRequestCount(clientHandlers);

                currentRPS         = (currentCount - previousCount) / ((elapsed - previousElapsed) / 1000);
                previousAverageRPS = averageRPS;
                averageRPS         = (currentCount - countAfterWarmup) / ((double)elapsed / 1000);

                drift = averageRPS - previousAverageRPS;

                if (options.ReportingInterval > 0)
                {
                    Console.WriteLine($"Elapsed time: {TimeSpan.FromSeconds(elapsed/1000)}    Current RPS: {currentRPS,10:####.0}    Average RPS: {averageRPS,10:####.0} Drift: {drift/averageRPS*100,8:0.00}%");
                }

                previousCount   = currentCount;
                previousElapsed = elapsed;

                if (options.NumberOfRequests > 0 && options.NumberOfRequests <= currentCount)
                {
                    break;
                }
                if (options.DurationTime > 0 && (options.DurationTime * 1000) <= elapsed)
                {
                    break;
                }
            }
            timer.Stop();
            // write out final stats if we are asked not to do it interactively.
            Console.WriteLine($"Total elapsed time: {timer.Elapsed}    Average RPS: {averageRPS:0.0} Total requests: {GetCurrentRequestCount(clientHandlers)}");
        }
 public TestSubSocketClient(BaseClientOptions options, ApiClientOptions apiOptions) : base(options, apiOptions)
 {
 }