diff --git a/Binance.Net.UnitTests/Binance.Net.UnitTests.csproj b/Binance.Net.UnitTests/Binance.Net.UnitTests.csproj index f37f062b..f505eb1c 100644 --- a/Binance.Net.UnitTests/Binance.Net.UnitTests.csproj +++ b/Binance.Net.UnitTests/Binance.Net.UnitTests.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/Binance.Net/Binance.Net.csproj b/Binance.Net/Binance.Net.csproj index 7f75e902..b480fb1c 100644 --- a/Binance.Net/Binance.Net.csproj +++ b/Binance.Net/Binance.Net.csproj @@ -48,8 +48,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Binance.Net/Binance.Net.xml b/Binance.Net/Binance.Net.xml index 00ede153..9c113eee 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -29332,31 +29332,6 @@ Binance options - - - Rest client options - - - - - Socket client options - - - - - Trade environment. Contains info about URL's to use to connect to the API. Use `BinanceEnvironment` to swap environment, for example `Environment = BinanceEnvironment.Live` - - - - - The api credentials used for signing requests. - - - - - The DI service lifetime for the IBinanceSocketClient - - Options for the Binance SymbolOrderBook diff --git a/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiShared.cs b/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiShared.cs index cb81420c..49254eb9 100644 --- a/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiShared.cs +++ b/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiShared.cs @@ -16,10 +16,7 @@ internal partial class BinanceRestClientCoinFuturesApi : IBinanceRestClientCoinF #region Klines client - GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1500, false); async Task>> IKlineRestClient.GetKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -305,7 +302,7 @@ async Task>> IFuturesOrderRest }).ToArray()); } - PaginatedEndpointOptions IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true); + PaginatedEndpointOptions IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true, 100, true); async Task>> IFuturesOrderRestClient.GetClosedFuturesOrdersAsync(GetClosedOrdersRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((IFuturesOrderRestClient)this).GetClosedFuturesOrdersOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); @@ -383,7 +380,7 @@ async Task>> IFuturesOrderRestCli }).ToArray()); } - PaginatedEndpointOptions IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true); + PaginatedEndpointOptions IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true, 1000, true); async Task>> IFuturesOrderRestClient.GetFuturesUserTradesAsync(GetUserTradesRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((IFuturesOrderRestClient)this).GetFuturesUserTradesOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); @@ -578,10 +575,7 @@ async Task> ILeverageRestClient.SetLeverageAsy #region Mark Klines client - GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false); async Task>> IMarkPriceKlineRestClient.GetMarkPriceKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -656,7 +650,7 @@ async Task> IOrderBookRestClient.GetOrderBook #endregion #region Trade History client - GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, false); + GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false); async Task>> ITradeHistoryRestClient.GetTradeHistoryAsync(GetTradeHistoryRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -693,10 +687,7 @@ async Task>> ITradeHistoryRestClient. #region Index Klines client - GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false); async Task>> IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -769,7 +760,7 @@ async Task> IOpenInterestRestClient.GetOpe #endregion #region Funding Rate client - GetFundingRateHistoryOptions IFundingRateRestClient.GetFundingRateHistoryOptions { get; } = new GetFundingRateHistoryOptions(SharedPaginationSupport.Ascending, false); + GetFundingRateHistoryOptions IFundingRateRestClient.GetFundingRateHistoryOptions { get; } = new GetFundingRateHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false); async Task>> IFundingRateRestClient.GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -897,5 +888,26 @@ async Task> IListenKeyRestClient.StopListenKeyAsync(St return result.AsExchangeResult(Exchange, SupportedTradingModes, request.ListenKey); } #endregion + + #region Fee Client + EndpointOptions IFeeRestClient.GetFeeOptions { get; } = new EndpointOptions(true); + + async Task> IFeeRestClient.GetFeesAsync(GetFeeRequest request, CancellationToken ct) + { + var validationError = ((IFeeRestClient)this).GetFeeOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); + if (validationError != null) + return new ExchangeWebResult(Exchange, validationError); + + // Get data + var result = await Account.GetUserCommissionRateAsync( + request.Symbol.GetSymbol(FormatSymbol), + ct: ct).ConfigureAwait(false); + if (!result) + return result.AsExchangeResult(Exchange, null, default); + + // Return + return result.AsExchangeResult(Exchange, TradingMode.Spot, new SharedFee(result.Data.MakerCommissionRate * 100, result.Data.TakerCommissionRate * 100)); + } + #endregion } } diff --git a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiShared.cs b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiShared.cs index 9c503c75..c87be082 100644 --- a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiShared.cs +++ b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiShared.cs @@ -14,10 +14,7 @@ internal partial class BinanceRestClientSpotApi : IBinanceRestClientSpotApiShare #region Klines Client - GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false); async Task>> IKlineRestClient.GetKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -155,7 +152,7 @@ async Task>> IRecentTradeRestClient.G #endregion #region Trade History client - GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, false); + GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false); async Task>> ITradeHistoryRestClient.GetTradeHistoryAsync(GetTradeHistoryRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -338,7 +335,7 @@ async Task>> ISpotOrderRestClient }).ToArray()); } - PaginatedEndpointOptions ISpotOrderRestClient.GetClosedSpotOrdersOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Ascending, true); + PaginatedEndpointOptions ISpotOrderRestClient.GetClosedSpotOrdersOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Ascending, true, 1000, true); async Task>> ISpotOrderRestClient.GetClosedSpotOrdersAsync(GetClosedOrdersRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((ISpotOrderRestClient)this).GetClosedSpotOrdersOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); @@ -413,7 +410,7 @@ async Task>> ISpotOrderRestClient }).ToArray()); } - PaginatedEndpointOptions ISpotOrderRestClient.GetSpotUserTradesOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true); + PaginatedEndpointOptions ISpotOrderRestClient.GetSpotUserTradesOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true, 1000, true); async Task>> ISpotOrderRestClient.GetSpotUserTradesAsync(GetUserTradesRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((ISpotOrderRestClient)this).GetSpotUserTradesOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); @@ -591,7 +588,7 @@ async Task>> IDepositRestCli }); } - GetDepositsOptions IDepositRestClient.GetDepositsOptions { get; } = new GetDepositsOptions(SharedPaginationSupport.Descending, true); + GetDepositsOptions IDepositRestClient.GetDepositsOptions { get; } = new GetDepositsOptions(SharedPaginationSupport.Descending, true, 1000); async Task>> IDepositRestClient.GetDepositsAsync(GetDepositsRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((IDepositRestClient)this).GetDepositsOptions.ValidateRequest(Exchange, request, TradingMode.Spot, SupportedTradingModes); @@ -633,7 +630,7 @@ async Task>> IDepositRestClient.Get #region Withdrawal client - GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, true); + GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, true, 1000); async Task>> IWithdrawalRestClient.GetWithdrawalsAsync(GetWithdrawalsRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((IWithdrawalRestClient)this).GetWithdrawalsOptions.ValidateRequest(Exchange, request, TradingMode.Spot, SupportedTradingModes); @@ -745,5 +742,30 @@ async Task> IListenKeyRestClient.StopListenKeyAsync(St return result.AsExchangeResult(Exchange, TradingMode.Spot, request.ListenKey); } #endregion + + #region Fee Client + EndpointOptions IFeeRestClient.GetFeeOptions { get; } = new EndpointOptions(true); + + async Task> IFeeRestClient.GetFeesAsync(GetFeeRequest request, CancellationToken ct) + { + var validationError = ((IFeeRestClient)this).GetFeeOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); + if (validationError != null) + return new ExchangeWebResult(Exchange, validationError); + + // Get data + var result = await Account.GetTradeFeeAsync( + request.Symbol.GetSymbol(FormatSymbol), + ct: ct).ConfigureAwait(false); + if (!result) + return result.AsExchangeResult(Exchange, null, default); + + var symbol = result.Data.SingleOrDefault(); + if (symbol == null) + return result.AsExchangeError(Exchange, new ServerError("Not found")); + + // Return + return result.AsExchangeResult(Exchange, TradingMode.Spot, new SharedFee(symbol.MakerFee * 100, symbol.TakerFee * 100)); + } + #endregion } } diff --git a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiShared.cs b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiShared.cs index 715f5dfe..68f850d4 100644 --- a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiShared.cs +++ b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiShared.cs @@ -14,10 +14,7 @@ internal partial class BinanceRestClientUsdFuturesApi : IBinanceRestClientUsdFut #region Klines client - GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false); async Task>> IKlineRestClient.GetKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -73,10 +70,7 @@ async Task>> IKlineRestClient.GetKlin #region Mark Klines client - GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false); async Task>> IMarkPriceKlineRestClient.GetMarkPriceKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -358,7 +352,7 @@ async Task>> IFuturesOrderRest }).ToArray()); } - PaginatedEndpointOptions IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true); + PaginatedEndpointOptions IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true, 1000, true); async Task>> IFuturesOrderRestClient.GetClosedFuturesOrdersAsync(GetClosedOrdersRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((IFuturesOrderRestClient)this).GetClosedFuturesOrdersOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); @@ -436,7 +430,7 @@ async Task>> IFuturesOrderRestCli }).ToArray()); } - PaginatedEndpointOptions IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true); + PaginatedEndpointOptions IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions(SharedPaginationSupport.Descending, true, 1000, true); async Task>> IFuturesOrderRestClient.GetFuturesUserTradesAsync(GetUserTradesRequest request, INextPageToken? pageToken, CancellationToken ct) { var validationError = ((IFuturesOrderRestClient)this).GetFuturesUserTradesOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); @@ -652,7 +646,7 @@ async Task> IOrderBookRestClient.GetOrderBook #endregion #region Trade History client - GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, false); + GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false); async Task>> ITradeHistoryRestClient.GetTradeHistoryAsync(GetTradeHistoryRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -689,10 +683,7 @@ async Task>> ITradeHistoryRestClient. #region Index Klines client - GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false) - { - MaxRequestDataPoints = 1000 - }; + GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false); async Task>> IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -765,7 +756,7 @@ async Task> IOpenInterestRestClient.GetOpe #endregion #region Funding Rate client - GetFundingRateHistoryOptions IFundingRateRestClient.GetFundingRateHistoryOptions { get; } = new GetFundingRateHistoryOptions(SharedPaginationSupport.Ascending, false); + GetFundingRateHistoryOptions IFundingRateRestClient.GetFundingRateHistoryOptions { get; } = new GetFundingRateHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false); async Task>> IFundingRateRestClient.GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, INextPageToken? pageToken, CancellationToken ct) { @@ -892,5 +883,26 @@ async Task> IListenKeyRestClient.StopListenKeyAsync(St return result.AsExchangeResult(Exchange, SupportedTradingModes, request.ListenKey); } #endregion + + #region Fee Client + EndpointOptions IFeeRestClient.GetFeeOptions { get; } = new EndpointOptions(true); + + async Task> IFeeRestClient.GetFeesAsync(GetFeeRequest request, CancellationToken ct) + { + var validationError = ((IFeeRestClient)this).GetFeeOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes); + if (validationError != null) + return new ExchangeWebResult(Exchange, validationError); + + // Get data + var result = await Account.GetUserCommissionRateAsync( + request.Symbol.GetSymbol(FormatSymbol), + ct: ct).ConfigureAwait(false); + if (!result) + return result.AsExchangeResult(Exchange, null, default); + + // Return + return result.AsExchangeResult(Exchange, TradingMode.Spot, new SharedFee(result.Data.MakerCommissionRate * 100, result.Data.TakerCommissionRate * 100)); + } + #endregion } } diff --git a/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiShared.cs b/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiShared.cs index e0816db1..a09af154 100644 --- a/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiShared.cs +++ b/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiShared.cs @@ -20,7 +20,8 @@ public interface IBinanceRestClientCoinFuturesApiShared : IFundingRateRestClient, IBalanceRestClient, IPositionModeRestClient, - IListenKeyRestClient + IListenKeyRestClient, + IFeeRestClient { } } diff --git a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiShared.cs b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiShared.cs index 941b9d5f..ca8e70e7 100644 --- a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiShared.cs +++ b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiShared.cs @@ -18,7 +18,8 @@ public interface IBinanceRestClientSpotApiShared: ITradeHistoryRestClient, IWithdrawalRestClient, IWithdrawRestClient, - IListenKeyRestClient + IListenKeyRestClient, + IFeeRestClient { } } diff --git a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiShared.cs b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiShared.cs index 00f53974..f947720a 100644 --- a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiShared.cs +++ b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiShared.cs @@ -20,7 +20,8 @@ public interface IBinanceRestClientUsdFuturesApiShared : IOpenInterestRestClient, IFundingRateRestClient, IPositionModeRestClient, - IListenKeyRestClient + IListenKeyRestClient, + IFeeRestClient { } } diff --git a/Binance.Net/Objects/Options/BinanceOptions.cs b/Binance.Net/Objects/Options/BinanceOptions.cs index a7339ab0..9e2105fa 100644 --- a/Binance.Net/Objects/Options/BinanceOptions.cs +++ b/Binance.Net/Objects/Options/BinanceOptions.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using CryptoExchange.Net.Objects.Options; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Text; @@ -8,31 +9,7 @@ namespace Binance.Net.Objects.Options /// /// Binance options /// - public class BinanceOptions + public class BinanceOptions : LibraryOptions { - /// - /// Rest client options - /// - public BinanceRestOptions Rest { get; set; } = new BinanceRestOptions(); - - /// - /// Socket client options - /// - public BinanceSocketOptions Socket { get; set; } = new BinanceSocketOptions(); - - /// - /// Trade environment. Contains info about URL's to use to connect to the API. Use `BinanceEnvironment` to swap environment, for example `Environment = BinanceEnvironment.Live` - /// - public BinanceEnvironment? Environment { get; set; } - - /// - /// The api credentials used for signing requests. - /// - public ApiCredentials? ApiCredentials { get; set; } - - /// - /// The DI service lifetime for the IBinanceSocketClient - /// - public ServiceLifetime? SocketClientLifeTime { get; set; } } }