using CryptoExchange.Net.RateLimiting.Interfaces; using System.Net.Http; namespace CryptoExchange.Net.Objects { /// /// The definition of a rest request /// public class RequestDefinition { private string? _stringRep; private string? _fullUrl; // Basics /// /// Base address of the request /// public string BaseAddress { get; set; } /// /// Path of the request /// public string Path { get; set; } /// /// Http method of the request /// public HttpMethod Method { get; set; } /// /// Is the request authenticated /// public bool Authenticated { get; set; } // Formatting /// /// The body format for this request /// public RequestBodyFormat? RequestBodyFormat { get; set; } /// /// The position of parameters for this request /// public HttpMethodParameterPosition? ParameterPosition { get; set; } /// /// The array serialization type for this request /// public ArrayParametersSerialization? ArraySerialization { get; set; } // Rate limiting /// /// Request weight /// public int Weight { get; set; } = 1; /// /// Rate limit gate to use /// public IRateLimitGate? RateLimitGate { get; set; } /// /// Individual endpoint rate limit guard to use /// public IRateLimitGuard? LimitGuard { get; set; } /// /// Whether this request should never be cached /// public bool PreventCaching { get; set; } /// /// Whether the response to this requests should attempted to be parsed even when the status indicates failure /// public bool TryParseOnNonSuccess { get; set; } /// /// Connection id /// public int? ConnectionId { get; set; } /// /// Whether the endpoint path should always include the trailing `/` /// public bool? ForcePathEndWithSlash { get; set; } /// /// Full url, host + path /// public string FullUrl { get { if (_fullUrl != null) return _fullUrl; var result = BaseAddress.AppendPath(Path); if (ForcePathEndWithSlash == true && !result.EndsWith("/")) result += "/"; _fullUrl = result; return _fullUrl; } } /// /// Whether concurrent identical requests should be prevented from sharing the same request/response /// public bool PreventRequestCoalescing { get; set; } /// /// ctor /// public RequestDefinition(string baseAddress, string path, HttpMethod method) { BaseAddress = baseAddress; Path = path; Method = method; if (!Path.StartsWith("/")) Path = $"/{Path}"; } /// public override string ToString() { return _stringRep ??= $"{Method} {Path}{(Authenticated ? " authenticated" : "")}"; } } }