From 92d7bc1e2e570387d3f628654cccb8bdcc21672f Mon Sep 17 00:00:00 2001 From: Jkorf Date: Thu, 28 Nov 2024 14:18:09 +0100 Subject: [PATCH] Added GetFeesAsync Shared REST client support, Added TimePeriodFilterSupport and MaxLimit properties to PaginatedEndpointOptions --- .../Interfaces/Rest/IFeeRestClient.cs | 26 ++++++++++++++++ .../Endpoints/GetClosedOrdersOptions.cs | 2 +- .../Options/Endpoints/GetDepositsOptions.cs | 2 +- .../Endpoints/GetFundingRateHistoryOptions.cs | 2 +- .../Options/Endpoints/GetKlinesOptions.cs | 14 +++------ .../Endpoints/GetPositionHistoryOptions.cs | 2 +- .../Endpoints/GetTradeHistoryOptions.cs | 2 +- .../Endpoints/GetWithdrawalsOptions.cs | 2 +- .../Endpoints/PaginatedEndpointOptions.cs | 19 ++++++++++-- .../SharedApis/Models/Rest/GetFeeRequest.cs | 21 +++++++++++++ .../SharedApis/ResponseModels/SharedFee.cs | 30 +++++++++++++++++++ .../Trackers/Klines/KlineTracker.cs | 2 +- 12 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 CryptoExchange.Net/SharedApis/Interfaces/Rest/IFeeRestClient.cs create mode 100644 CryptoExchange.Net/SharedApis/Models/Rest/GetFeeRequest.cs create mode 100644 CryptoExchange.Net/SharedApis/ResponseModels/SharedFee.cs diff --git a/CryptoExchange.Net/SharedApis/Interfaces/Rest/IFeeRestClient.cs b/CryptoExchange.Net/SharedApis/Interfaces/Rest/IFeeRestClient.cs new file mode 100644 index 0000000..3a012cb --- /dev/null +++ b/CryptoExchange.Net/SharedApis/Interfaces/Rest/IFeeRestClient.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.Threading; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Client for requesting user trading fees + /// + public interface IFeeRestClient : ISharedClient + { + /// + /// Fee request options + /// + EndpointOptions GetFeeOptions { get; } + + /// + /// Get trading fees for a symbol + /// + /// Request info + /// Cancellation token + Task> GetFeesAsync(GetFeeRequest request, CancellationToken ct = default); + } +} diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs index 78db2de..c567caa 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs @@ -16,7 +16,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public GetClosedOrdersOptions(SharedPaginationSupport paginationType, bool timeFilterSupported) : base(paginationType, true) + public GetClosedOrdersOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit) : base(paginationType, timeFilterSupported, maxLimit, true) { TimeFilterSupported = timeFilterSupported; } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs index 8ae8eeb..ec30c34 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs @@ -16,7 +16,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public GetDepositsOptions(SharedPaginationSupport paginationType, bool timeFilterSupported) : base(paginationType, true) + public GetDepositsOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit) : base(paginationType, timeFilterSupported, maxLimit, true) { TimeFilterSupported = timeFilterSupported; } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs index 07a0507..be857c2 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs @@ -8,7 +8,7 @@ /// /// ctor /// - public GetFundingRateHistoryOptions(SharedPaginationSupport paginationType, bool needsAuthentication) : base(paginationType, needsAuthentication) + public GetFundingRateHistoryOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit, bool needsAuthentication) : base(paginationType, timeFilterSupported, maxLimit, needsAuthentication) { } } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs index f3c8e91..703243c 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs @@ -20,10 +20,6 @@ namespace CryptoExchange.Net.SharedApis /// public int? MaxTotalDataPoints { get; set; } /// - /// Max number of data points which can be requested in a single request - /// - public int? MaxRequestDataPoints { get; set; } - /// /// The max age of the data that can be requested /// public TimeSpan? MaxAge { get; set; } @@ -31,7 +27,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public GetKlinesOptions(SharedPaginationSupport paginationType, bool needsAuthentication) : base(paginationType, needsAuthentication) + public GetKlinesOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit, bool needsAuthentication) : base(paginationType, timeFilterSupported, maxLimit, needsAuthentication) { SupportIntervals = new[] { @@ -47,7 +43,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public GetKlinesOptions(SharedPaginationSupport paginationType, bool needsAuthentication, params SharedKlineInterval[] intervals) : base(paginationType, needsAuthentication) + public GetKlinesOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals) : base(paginationType, timeFilterSupported, maxLimit, needsAuthentication) { SupportIntervals = intervals; } @@ -68,8 +64,8 @@ namespace CryptoExchange.Net.SharedApis if (MaxAge.HasValue && request.StartTime < DateTime.UtcNow.Add(-MaxAge.Value)) return new ArgumentError($"Only the most recent {MaxAge} klines are available"); - if (MaxRequestDataPoints.HasValue && request.Limit > MaxRequestDataPoints.Value) - return new ArgumentError($"Only {MaxRequestDataPoints} klines can be retrieved per request"); + if (request.Limit > MaxLimit) + return new ArgumentError($"Only {MaxLimit} klines can be retrieved per request"); if (MaxTotalDataPoints.HasValue) { @@ -95,8 +91,6 @@ namespace CryptoExchange.Net.SharedApis sb.AppendLine($"Max age of data: {MaxAge}"); if (MaxTotalDataPoints != null) sb.AppendLine($"Max total data points available: {MaxTotalDataPoints}"); - if (MaxRequestDataPoints != null) - sb.AppendLine($"Max data points per request: {MaxRequestDataPoints}"); return sb.ToString(); } } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs index f51c3a4..ffb0158 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs @@ -8,7 +8,7 @@ /// /// ctor /// - public GetPositionHistoryOptions(SharedPaginationSupport paginationType) : base(paginationType, true) + public GetPositionHistoryOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit) : base(paginationType, timeFilterSupported, maxLimit, true) { } } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs index 11fe755..018eccb 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs @@ -17,7 +17,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public GetTradeHistoryOptions(SharedPaginationSupport paginationType, bool needsAuthentication) : base(paginationType, needsAuthentication) + public GetTradeHistoryOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit, bool needsAuthentication) : base(paginationType, timeFilterSupported, maxLimit, needsAuthentication) { } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs index 3699090..1806c6a 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs @@ -16,7 +16,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public GetWithdrawalsOptions(SharedPaginationSupport paginationType, bool timeFilterSupported) : base(paginationType, true) + public GetWithdrawalsOptions(SharedPaginationSupport paginationType, bool timeFilterSupported, int maxLimit) : base(paginationType, timeFilterSupported, maxLimit, true) { TimeFilterSupported = timeFilterSupported; } diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/PaginatedEndpointOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/PaginatedEndpointOptions.cs index b30769f..572a9ef 100644 --- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/PaginatedEndpointOptions.cs +++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/PaginatedEndpointOptions.cs @@ -1,4 +1,5 @@ -using System.Text; +using CryptoExchange.Net.Objects; +using System.Text; namespace CryptoExchange.Net.SharedApis { @@ -13,12 +14,24 @@ namespace CryptoExchange.Net.SharedApis /// public SharedPaginationSupport PaginationSupport { get; } + /// + /// Whether filtering based on start/end time is supported + /// + public bool TimePeriodFilterSupport { get; } + + /// + /// Max amount of results that can be requested + /// + public int MaxLimit { get; set; } + /// /// ctor /// - public PaginatedEndpointOptions(SharedPaginationSupport paginationType, bool needsAuthentication) : base(needsAuthentication) + public PaginatedEndpointOptions(SharedPaginationSupport paginationType, bool timePeriodSupport, int maxLimit, bool needsAuthentication) : base(needsAuthentication) { PaginationSupport = paginationType; + TimePeriodFilterSupport = timePeriodSupport; + MaxLimit = maxLimit; } /// @@ -26,6 +39,8 @@ namespace CryptoExchange.Net.SharedApis { var sb = new StringBuilder(base.ToString(exchange)); sb.AppendLine($"Pagination type: {PaginationSupport}"); + sb.AppendLine($"Time period filter support: {TimePeriodFilterSupport}"); + sb.AppendLine($"Max limit: {MaxLimit}"); return sb.ToString(); } } diff --git a/CryptoExchange.Net/SharedApis/Models/Rest/GetFeeRequest.cs b/CryptoExchange.Net/SharedApis/Models/Rest/GetFeeRequest.cs new file mode 100644 index 0000000..429e258 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/Models/Rest/GetFeeRequest.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Request to retrieve trading fees + /// + public record GetFeeRequest : SharedSymbolRequest + { + /// + /// ctor + /// + /// Symbol to retrieve fees for + /// Exchange specific parameters + public GetFeeRequest(SharedSymbol symbol, ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters) + { + } + } +} diff --git a/CryptoExchange.Net/SharedApis/ResponseModels/SharedFee.cs b/CryptoExchange.Net/SharedApis/ResponseModels/SharedFee.cs new file mode 100644 index 0000000..528ed6d --- /dev/null +++ b/CryptoExchange.Net/SharedApis/ResponseModels/SharedFee.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Trading fee info + /// + public record SharedFee + { + /// + /// Taker fee percentage + /// + public decimal TakerFee { get; set; } + /// + /// Maker fee percentage + /// + public decimal MakerFee { get; set; } + + /// + /// ctor + /// + public SharedFee(decimal makerFee, decimal takerFee) + { + MakerFee = makerFee; + TakerFee = takerFee; + } + } +} diff --git a/CryptoExchange.Net/Trackers/Klines/KlineTracker.cs b/CryptoExchange.Net/Trackers/Klines/KlineTracker.cs index 9ed47b4..cb16c55 100644 --- a/CryptoExchange.Net/Trackers/Klines/KlineTracker.cs +++ b/CryptoExchange.Net/Trackers/Klines/KlineTracker.cs @@ -229,7 +229,7 @@ namespace CryptoExchange.Net.Trackers.Klines if (_restClient.GetKlinesOptions.MaxAge != null && DateTime.UtcNow.Add(-_restClient.GetKlinesOptions.MaxAge.Value) > startTime) startTime = DateTime.UtcNow.Add(-_restClient.GetKlinesOptions.MaxAge.Value); - var limit = Math.Min(_restClient.GetKlinesOptions.MaxRequestDataPoints ?? _restClient.GetKlinesOptions.MaxTotalDataPoints ?? 100, Limit ?? 100); + var limit = Math.Min(_restClient.GetKlinesOptions.MaxLimit, Limit ?? 100); var request = new GetKlinesRequest(Symbol, _interval, startTime, DateTime.UtcNow, limit: limit); var data = new List();