1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-07-26 11:17:09 +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

View File

@ -633,13 +633,12 @@
<param name="uri"></param> <param name="uri"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:CryptoExchange.Net.Interfaces.IRequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy,System.Boolean)"> <member name="M:CryptoExchange.Net.Interfaces.IRequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy)">
<summary> <summary>
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>
</member> </member>
<member name="T:CryptoExchange.Net.Interfaces.IResponse"> <member name="T:CryptoExchange.Net.Interfaces.IResponse">
<summary> <summary>
@ -2031,13 +2030,12 @@
Request object Request object
</summary> </summary>
</member> </member>
<member name="M:CryptoExchange.Net.Requests.Request.#ctor(System.Net.Http.HttpRequestMessage,System.Net.Http.HttpClient,System.Boolean)"> <member name="M:CryptoExchange.Net.Requests.Request.#ctor(System.Net.Http.HttpRequestMessage,System.Net.Http.HttpClient)">
<summary> <summary>
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>
</member> </member>
<member name="P:CryptoExchange.Net.Requests.Request.Content"> <member name="P:CryptoExchange.Net.Requests.Request.Content">
<inheritdoc /> <inheritdoc />
@ -2071,7 +2069,7 @@
WebRequest factory WebRequest factory
</summary> </summary>
</member> </member>
<member name="M:CryptoExchange.Net.Requests.RequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy,System.Boolean)"> <member name="M:CryptoExchange.Net.Requests.RequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy)">
<inheritdoc /> <inheritdoc />
</member> </member>
<member name="M:CryptoExchange.Net.Requests.RequestFactory.Create(System.Net.Http.HttpMethod,System.String)"> <member name="M:CryptoExchange.Net.Requests.RequestFactory.Create(System.Net.Http.HttpMethod,System.String)">
@ -2959,39 +2957,9 @@
<member name="M:CryptoExchange.Net.Sockets.WebsocketFactory.CreateWebsocket(CryptoExchange.Net.Logging.Log,System.String,System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IDictionary{System.String,System.String})"> <member name="M:CryptoExchange.Net.Sockets.WebsocketFactory.CreateWebsocket(CryptoExchange.Net.Logging.Log,System.String,System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IDictionary{System.String,System.String})">
<inheritdoc /> <inheritdoc />
</member> </member>
<member name="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute"> </members>
<summary> </doc>
Specifies that <see langword="null"/> is allowed as an input even if the ember name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute">
corresponding type disallows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.AllowNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute">
<summary>
Specifies that <see langword="null"/> is disallowed as an input even if the
corresponding type allows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DisallowNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute">
<summary>
Specifies that a method that will never return under any circumstance.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute">
<summary> <summary>
Specifies that the method will not return if the associated <see cref="T:System.Boolean"/> Specifies that the method will not return if the associated <see cref="T:System.Boolean"/>
parameter is passed the specified value. parameter is passed the specified value.

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

@ -22,7 +22,6 @@ namespace CryptoExchange.Net.Interfaces
/// </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

@ -22,15 +22,11 @@ namespace CryptoExchange.Net.Requests
/// </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);