1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-07-26 03:07:24 +00:00
This commit is contained in:
Artem Kurianov 2020-08-17 08:44:30 +00:00
parent 9b8950747f
commit fb61b6931b
7 changed files with 3089 additions and 3127 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ namespace CryptoExchange.Net.Interfaces
/// <summary> /// <summary>
/// internal request id for tracing /// internal request id for tracing
/// </summary> /// </summary>
string? RequestId { get; } string RequestId { get; }
/// <summary> /// <summary>
/// Set byte content /// Set byte content
/// </summary> /// </summary>

View File

@ -21,8 +21,7 @@ namespace CryptoExchange.Net.Interfaces
/// Configure the requests created by this factory /// Configure the requests created by this factory
/// </summary> /// </summary>
/// <param name="requestTimeout">Request timeout to use</param> /// <param name="requestTimeout">Request timeout to use</param>
/// <param name="proxy">Proxy settings to use</param> /// <param name="proxy">Proxy settings to use</param>
/// <param name="isTracingEnabled">Should generate unique id for requests</param> void Configure(TimeSpan requestTimeout, ApiProxy? proxy);
void Configure(TimeSpan requestTimeout, ApiProxy? proxy, bool isTracingEnabled=false);
} }
} }

View File

@ -127,7 +127,7 @@ namespace CryptoExchange.Net.Objects
/// The time the server has to respond to a request before timing out /// The time the server has to respond to a request before timing out
/// </summary> /// </summary>
public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30); public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);
public bool IsRequestsTracingEnabled { get; set; } = false;
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>

View File

@ -21,16 +21,12 @@ namespace CryptoExchange.Net.Requests
/// Create request object for web request /// Create request object for web request
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <param name="client"></param> /// <param name="client"></param>
/// <param name="isTracingEnabled">if true, should assign unique id for request</param> public Request(HttpRequestMessage request, HttpClient client)
public Request(HttpRequestMessage request, HttpClient client, bool isTracingEnabled=false)
{ {
httpClient = client; httpClient = client;
this.request = request; this.request = request;
if (isTracingEnabled) RequestId = Path.GetRandomFileName();
{
RequestId = Path.GetRandomFileName();
}
} }
/// <inheritdoc /> /// <inheritdoc />
@ -52,7 +48,7 @@ namespace CryptoExchange.Net.Requests
/// <inheritdoc /> /// <inheritdoc />
public Uri Uri => request.RequestUri; public Uri Uri => request.RequestUri;
/// <inheritdoc /> /// <inheritdoc />
public string? RequestId { get; } public string RequestId { get; }
/// <inheritdoc /> /// <inheritdoc />
public void SetContent(string data, string contentType) public void SetContent(string data, string contentType)

View File

@ -14,9 +14,8 @@ namespace CryptoExchange.Net.Requests
private HttpClient? httpClient; private HttpClient? httpClient;
private bool isTracingEnabled; private bool isTracingEnabled;
/// <inheritdoc /> /// <inheritdoc />
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy, bool isTracingEnabled = false) public void Configure(TimeSpan requestTimeout, ApiProxy? proxy)
{ {
this.isTracingEnabled = isTracingEnabled;
HttpMessageHandler handler = new HttpClientHandler() HttpMessageHandler handler = new HttpClientHandler()
{ {
Proxy = proxy == null ? null : new WebProxy Proxy = proxy == null ? null : new WebProxy
@ -35,7 +34,7 @@ namespace CryptoExchange.Net.Requests
if (httpClient == null) if (httpClient == null)
throw new InvalidOperationException("Cant create request before configuring http client"); throw new InvalidOperationException("Cant create request before configuring http client");
return new Request(new HttpRequestMessage(method, uri), httpClient, isTracingEnabled); return new Request(new HttpRequestMessage(method, uri), httpClient);
} }
} }
} }

View File

@ -83,7 +83,7 @@ namespace CryptoExchange.Net
throw new ArgumentNullException(nameof(exchangeOptions)); throw new ArgumentNullException(nameof(exchangeOptions));
RequestTimeout = exchangeOptions.RequestTimeout; RequestTimeout = exchangeOptions.RequestTimeout;
RequestFactory.Configure(exchangeOptions.RequestTimeout, exchangeOptions.Proxy,exchangeOptions.IsRequestsTracingEnabled); RequestFactory.Configure(exchangeOptions.RequestTimeout, exchangeOptions.Proxy);
RateLimitBehaviour = exchangeOptions.RateLimitingBehaviour; RateLimitBehaviour = exchangeOptions.RateLimitingBehaviour;
var rateLimiters = new List<IRateLimiter>(); var rateLimiters = new List<IRateLimiter>();
foreach (var rateLimiter in exchangeOptions.RateLimiters) foreach (var rateLimiter in exchangeOptions.RateLimiters)
@ -197,7 +197,7 @@ namespace CryptoExchange.Net
if (method == HttpMethod.Post) if (method == HttpMethod.Post)
paramString = " with request body " + request.Content; paramString = " with request body " + request.Content;
log.Write(LogVerbosity.Debug, $"Sending {method}{(signed ? " signed" : "")} request to {request.Uri}{paramString ?? " "}{(apiProxy == null? "": $" via proxy {apiProxy.Host}")} {(request.RequestId==null?"":$" with id {request.RequestId}")}"); log.Write(LogVerbosity.Debug, $"Sending {method}{(signed ? " signed" : "")} request to {request.Uri}{paramString ?? " "}{(apiProxy == null? "": $" via proxy {apiProxy.Host}")} with id {request.RequestId}");
return await GetResponse<T>(request, cancellationToken).ConfigureAwait(false); return await GetResponse<T>(request, cancellationToken).ConfigureAwait(false);
} }
@ -224,7 +224,7 @@ namespace CryptoExchange.Net
var data = await reader.ReadToEndAsync().ConfigureAwait(false); var data = await reader.ReadToEndAsync().ConfigureAwait(false);
responseStream.Close(); responseStream.Close();
response.Close(); response.Close();
log.Write(LogVerbosity.Debug, $"Data {(request.RequestId==null?"":$"for request {request.RequestId} ")}received: {data}"); log.Write(LogVerbosity.Debug, $"Data for request {request.RequestId} received: {data}");
var parseResult = ValidateJson(data); var parseResult = ValidateJson(data);
if (!parseResult.Success) if (!parseResult.Success)
@ -249,7 +249,7 @@ namespace CryptoExchange.Net
{ {
using var reader = new StreamReader(responseStream); using var reader = new StreamReader(responseStream);
var data = await reader.ReadToEndAsync().ConfigureAwait(false); var data = await reader.ReadToEndAsync().ConfigureAwait(false);
log.Write(LogVerbosity.Debug, $"Error {(request.RequestId == null ? "" : $"for request {request.RequestId} ")}received: {data}"); log.Write(LogVerbosity.Debug, $"Error for request {request.RequestId} received: {data}");
responseStream.Close(); responseStream.Close();
response.Close(); response.Close();
var parseResult = ValidateJson(data); var parseResult = ValidateJson(data);