mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
Merge branch 'master' into pr/4
This commit is contained in:
commit
c3ce0de12a
@ -588,6 +588,11 @@
|
||||
Uri
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:CryptoExchange.Net.Interfaces.IRequest.RequestId">
|
||||
<summary>
|
||||
internal request id for tracing
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.Interfaces.IRequest.SetContent(System.Byte[])">
|
||||
<summary>
|
||||
Set byte content
|
||||
@ -628,12 +633,13 @@
|
||||
<param name="uri"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.Interfaces.IRequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy)">
|
||||
<member name="M:CryptoExchange.Net.Interfaces.IRequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy,System.Boolean)">
|
||||
<summary>
|
||||
Configure the requests created by this factory
|
||||
</summary>
|
||||
<param name="requestTimeout">Request timeout to use</param>
|
||||
<param name="proxy">Proxy settings to use</param>
|
||||
<param name="isTracingEnabled">Should generate unique id for requests</param>
|
||||
</member>
|
||||
<member name="T:CryptoExchange.Net.Interfaces.IResponse">
|
||||
<summary>
|
||||
@ -2024,12 +2030,13 @@
|
||||
Request object
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.Requests.Request.#ctor(System.Net.Http.HttpRequestMessage,System.Net.Http.HttpClient)">
|
||||
<member name="M:CryptoExchange.Net.Requests.Request.#ctor(System.Net.Http.HttpRequestMessage,System.Net.Http.HttpClient,System.Boolean)">
|
||||
<summary>
|
||||
Create request object for web request
|
||||
</summary>
|
||||
<param name="request"></param>
|
||||
<param name="client"></param>
|
||||
<param name="isTracingEnabled">if true, should assign unique id for request</param>
|
||||
</member>
|
||||
<member name="P:CryptoExchange.Net.Requests.Request.Content">
|
||||
<inheritdoc />
|
||||
@ -2043,6 +2050,9 @@
|
||||
<member name="P:CryptoExchange.Net.Requests.Request.Uri">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="P:CryptoExchange.Net.Requests.Request.RequestId">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.Requests.Request.SetContent(System.String,System.String)">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
@ -2060,7 +2070,7 @@
|
||||
WebRequest factory
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.Requests.RequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy)">
|
||||
<member name="M:CryptoExchange.Net.Requests.RequestFactory.Configure(System.TimeSpan,CryptoExchange.Net.Objects.ApiProxy,System.Boolean)">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="M:CryptoExchange.Net.Requests.RequestFactory.Create(System.Net.Http.HttpMethod,System.String)">
|
||||
|
@ -27,6 +27,10 @@ namespace CryptoExchange.Net.Interfaces
|
||||
/// </summary>
|
||||
Uri Uri { get; }
|
||||
/// <summary>
|
||||
/// internal request id for tracing
|
||||
/// </summary>
|
||||
string? RequestId { get; }
|
||||
/// <summary>
|
||||
/// Set byte content
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
|
@ -22,6 +22,7 @@ namespace CryptoExchange.Net.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="requestTimeout">Request timeout to use</param>
|
||||
/// <param name="proxy">Proxy settings to use</param>
|
||||
void Configure(TimeSpan requestTimeout, ApiProxy? proxy);
|
||||
/// <param name="isTracingEnabled">Should generate unique id for requests</param>
|
||||
void Configure(TimeSpan requestTimeout, ApiProxy? proxy, bool isTracingEnabled=false);
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// The time the server has to respond to a request before timing out
|
||||
/// </summary>
|
||||
public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);
|
||||
|
||||
public bool IsRequestsTracingEnabled { get; set; } = false;
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
@ -21,10 +22,15 @@ namespace CryptoExchange.Net.Requests
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="client"></param>
|
||||
public Request(HttpRequestMessage request, HttpClient client)
|
||||
/// <param name="isTracingEnabled">if true, should assign unique id for request</param>
|
||||
public Request(HttpRequestMessage request, HttpClient client, bool isTracingEnabled=false)
|
||||
{
|
||||
httpClient = client;
|
||||
this.request = request;
|
||||
if (isTracingEnabled)
|
||||
{
|
||||
RequestId = Path.GetRandomFileName();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -45,6 +51,8 @@ namespace CryptoExchange.Net.Requests
|
||||
|
||||
/// <inheritdoc />
|
||||
public Uri Uri => request.RequestUri;
|
||||
/// <inheritdoc />
|
||||
public string? RequestId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetContent(string data, string contentType)
|
||||
|
@ -12,10 +12,11 @@ namespace CryptoExchange.Net.Requests
|
||||
public class RequestFactory : IRequestFactory
|
||||
{
|
||||
private HttpClient? httpClient;
|
||||
|
||||
private bool isTracingEnabled;
|
||||
/// <inheritdoc />
|
||||
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy)
|
||||
public void Configure(TimeSpan requestTimeout, ApiProxy? proxy, bool isTracingEnabled = false)
|
||||
{
|
||||
this.isTracingEnabled = isTracingEnabled;
|
||||
HttpMessageHandler handler = new HttpClientHandler()
|
||||
{
|
||||
Proxy = proxy == null ? null : new WebProxy
|
||||
@ -34,7 +35,7 @@ namespace CryptoExchange.Net.Requests
|
||||
if (httpClient == null)
|
||||
throw new InvalidOperationException("Cant create request before configuring http client");
|
||||
|
||||
return new Request(new HttpRequestMessage(method, uri), httpClient);
|
||||
return new Request(new HttpRequestMessage(method, uri), httpClient, isTracingEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace CryptoExchange.Net
|
||||
throw new ArgumentNullException(nameof(exchangeOptions));
|
||||
|
||||
RequestTimeout = exchangeOptions.RequestTimeout;
|
||||
RequestFactory.Configure(exchangeOptions.RequestTimeout, exchangeOptions.Proxy);
|
||||
RequestFactory.Configure(exchangeOptions.RequestTimeout, exchangeOptions.Proxy,exchangeOptions.IsRequestsTracingEnabled);
|
||||
RateLimitBehaviour = exchangeOptions.RateLimitingBehaviour;
|
||||
var rateLimiters = new List<IRateLimiter>();
|
||||
foreach (var rateLimiter in exchangeOptions.RateLimiters)
|
||||
@ -190,14 +190,14 @@ namespace CryptoExchange.Net
|
||||
}
|
||||
|
||||
if (limitResult.Data > 0)
|
||||
log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} was limited by {limitResult.Data}ms by {limiter.GetType().Name}");
|
||||
log.Write(LogVerbosity.Debug, $"Request {request.RequestId} {uri.AbsolutePath} was limited by {limitResult.Data}ms by {limiter.GetType().Name}");
|
||||
}
|
||||
|
||||
string? paramString = null;
|
||||
if (method == HttpMethod.Post)
|
||||
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}")}");
|
||||
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}")}");
|
||||
return await GetResponse<T>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ namespace CryptoExchange.Net
|
||||
var data = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||
responseStream.Close();
|
||||
response.Close();
|
||||
log.Write(LogVerbosity.Debug, $"Data received: {data}");
|
||||
log.Write(LogVerbosity.Debug, $"Data {(request.RequestId==null?"":$"for request {request.RequestId} ")}received: {data}");
|
||||
|
||||
var parseResult = ValidateJson(data);
|
||||
if (!parseResult.Success)
|
||||
@ -249,7 +249,7 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
using var reader = new StreamReader(responseStream);
|
||||
var data = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||
log.Write(LogVerbosity.Debug, $"Error received: {data}");
|
||||
log.Write(LogVerbosity.Debug, $"Error {(request.RequestId == null ? "" : $"for request {request.RequestId} ")}received: {data}");
|
||||
responseStream.Close();
|
||||
response.Close();
|
||||
var parseResult = ValidateJson(data);
|
||||
@ -258,7 +258,7 @@ namespace CryptoExchange.Net
|
||||
}
|
||||
catch (HttpRequestException requestException)
|
||||
{
|
||||
log.Write(LogVerbosity.Warning, "Request exception: " + requestException.Message);
|
||||
log.Write(LogVerbosity.Warning, $"Request {request.RequestId} exception: " + requestException.Message);
|
||||
return new WebCallResult<T>(null, null, default, new ServerError(requestException.Message));
|
||||
}
|
||||
catch (TaskCanceledException canceledException)
|
||||
@ -266,14 +266,14 @@ namespace CryptoExchange.Net
|
||||
if(canceledException.CancellationToken == cancellationToken)
|
||||
{
|
||||
// Cancellation token cancelled
|
||||
log.Write(LogVerbosity.Warning, "Request cancel requested");
|
||||
log.Write(LogVerbosity.Warning, $"Request {request.RequestId} cancel requested");
|
||||
return new WebCallResult<T>(null, null, default, new CancellationRequestedError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Request timed out
|
||||
log.Write(LogVerbosity.Warning, "Request timed out");
|
||||
return new WebCallResult<T>(null, null, default, new WebError("Request timed out"));
|
||||
log.Write(LogVerbosity.Warning, $"Request {request.RequestId} timed out");
|
||||
return new WebCallResult<T>(null, null, default, new WebError($"Request {request.RequestId} timed out"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user