From 9741873f89db59d3f0dd578752e78b10d9057b60 Mon Sep 17 00:00:00 2001 From: JKorf Date: Mon, 22 Jul 2024 16:11:59 +0200 Subject: [PATCH] Added SpotApi.Account.GetCommissionRatesAsync --- .../BinanceRestIntegrationTests.cs | 1 + .../Account/GetAccountVipLevelAndStatus.txt | 8 ++ .../Spot/Account/GetCommissionRates.txt | 24 +++++ Binance.Net.UnitTests/RestRequestTests.cs | 2 + Binance.Net/Binance.Net.xml | 88 +++++++++++++++++++ .../BinanceRestClientSpotApiAccount.cs | 15 ++++ .../IBinanceRestClientSpotApiAccount.cs | 10 +++ .../Objects/Models/Spot/BinanceCommissions.cs | 88 +++++++++++++++++++ 8 files changed, 236 insertions(+) create mode 100644 Binance.Net.UnitTests/Endpoints/Spot/Account/GetAccountVipLevelAndStatus.txt create mode 100644 Binance.Net.UnitTests/Endpoints/Spot/Account/GetCommissionRates.txt create mode 100644 Binance.Net/Objects/Models/Spot/BinanceCommissions.cs diff --git a/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs b/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs index d5f0787d4..c000c2bc9 100644 --- a/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs +++ b/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs @@ -83,6 +83,7 @@ public async Task TestSpotAccount() await RunAndCheckResult(client => client.SpotApi.Account.GetIsolatedMarginFeeDataAsync(default, default, default, default), true); await RunAndCheckResult(client => client.SpotApi.Account.GetTradeFeeAsync(default, default, default), true); await RunAndCheckResult(client => client.SpotApi.Account.GetAccountVipLevelAndStatusAsync(default, default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetCommissionRatesAsync("ETHUSDT", default, default), true); // Not available without margin account //await RunAndCheckResult(client => client.SpotApi.Account.GetMarginTransferHistoryAsync(Enums.TransferDirection.RollOut, default, default, default, default, default, default, default), true); diff --git a/Binance.Net.UnitTests/Endpoints/Spot/Account/GetAccountVipLevelAndStatus.txt b/Binance.Net.UnitTests/Endpoints/Spot/Account/GetAccountVipLevelAndStatus.txt new file mode 100644 index 000000000..96ba551b6 --- /dev/null +++ b/Binance.Net.UnitTests/Endpoints/Spot/Account/GetAccountVipLevelAndStatus.txt @@ -0,0 +1,8 @@ +GET +/sapi/v1/account/info +true +{ + "vipLevel": 0, + "isMarginEnabled": true, + "isFutureEnabled": true +} \ No newline at end of file diff --git a/Binance.Net.UnitTests/Endpoints/Spot/Account/GetCommissionRates.txt b/Binance.Net.UnitTests/Endpoints/Spot/Account/GetCommissionRates.txt new file mode 100644 index 000000000..b03a951f2 --- /dev/null +++ b/Binance.Net.UnitTests/Endpoints/Spot/Account/GetCommissionRates.txt @@ -0,0 +1,24 @@ +GET +/api/v3/account/commission +true +{ + "symbol": "BTCUSDT", + "standardCommission": { + "maker": "0.00000010", + "taker": "0.00000020", + "buyer": "0.00000030", + "seller": "0.00000040" + }, + "taxCommission": { + "maker": "0.00000112", + "taker": "0.00000114", + "buyer": "0.00000118", + "seller": "0.00000116" + }, + "discount": { + "enabledForAccount": true, + "enabledForSymbol": true, + "discountAsset": "BNB", + "discount": "0.75000000" + } +} \ No newline at end of file diff --git a/Binance.Net.UnitTests/RestRequestTests.cs b/Binance.Net.UnitTests/RestRequestTests.cs index fba9582cb..162b671a1 100644 --- a/Binance.Net.UnitTests/RestRequestTests.cs +++ b/Binance.Net.UnitTests/RestRequestTests.cs @@ -94,6 +94,8 @@ public async Task ValidateSpotAccountCalls() await tester.ValidateAsync(client => client.SpotApi.Account.CrossMarginSmallLiabilityExchangeAsync(new[] { "ETH" }), "CrossMarginSmallLiabilityExchange"); await tester.ValidateAsync(client => client.SpotApi.Account.GetCrossMarginSmallLiabilityExchangeHistoryAsync(), "GetCrossMarginSmallLiabilityExchangeHistory"); await tester.ValidateAsync(client => client.SpotApi.Account.GetTradeFeeAsync(), "GetTradeFee"); + await tester.ValidateAsync(client => client.SpotApi.Account.GetAccountVipLevelAndStatusAsync(), "GetAccountVipLevelAndStatus"); + await tester.ValidateAsync(client => client.SpotApi.Account.GetCommissionRatesAsync("ETHUSDT"), "GetCommissionRates"); } [Test] diff --git a/Binance.Net/Binance.Net.xml b/Binance.Net/Binance.Net.xml index a694bebe4..f00312894 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -1316,6 +1316,9 @@ + + + @@ -8785,6 +8788,16 @@ Cancellation token + + + Get current account commission rates. + + + Symbol + The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + Cancellation token + + Binance Spot exchange data endpoints. Exchange data includes market data (tickers, order books, etc) and system status. @@ -14505,6 +14518,81 @@ Status + + + Binance commissions + + + + + Symbol name + + + + + Standard commission rates on trades from the order. + + + + + Tax commission rates for trades from the order. + + + + + Discount commission when paying in BNB + + + + + Commission info + + + + + Standard commission is reduced by this rate when paying commission in BNB. + + + + + Enabled for account + + + + + Enabled for symbol + + + + + Discount asset + + + + + Commission info + + + + + Maker fee + + + + + Taker fee + + + + + Buyer fee + + + + + Seller fee + + Spot symbol delist info diff --git a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiAccount.cs b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiAccount.cs index 49af0293a..810aa9646 100644 --- a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiAccount.cs +++ b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiAccount.cs @@ -1324,5 +1324,20 @@ public async Task> GetAccountVipLevelAnd } #endregion + + #region Get Trade Fee + + /// + public async Task> GetCommissionRatesAsync(string symbol, int? receiveWindow = null, CancellationToken ct = default) + { + var parameters = new ParameterCollection(); + parameters.Add("symbol", symbol); + parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); + + var request = _definitions.GetOrCreate(HttpMethod.Get, "api/v3/account/commission", BinanceExchange.RateLimiter.SpotRestIp, 20, true); + return await _baseClient.SendAsync(request, parameters, ct).ConfigureAwait(false); + } + + #endregion } } diff --git a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiAccount.cs b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiAccount.cs index 8ff8a908f..745e31dc9 100644 --- a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiAccount.cs +++ b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiAccount.cs @@ -863,5 +863,15 @@ Task> DisableIsolatedMarginAcco /// Cancellation token /// Task> GetAccountVipLevelAndStatusAsync(int? receiveWindow = null, CancellationToken ct = default); + + /// + /// Get current account commission rates. + /// + /// + /// Symbol + /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + /// Cancellation token + /// + Task> GetCommissionRatesAsync(string symbol, int? receiveWindow = null, CancellationToken ct = default); } } diff --git a/Binance.Net/Objects/Models/Spot/BinanceCommissions.cs b/Binance.Net/Objects/Models/Spot/BinanceCommissions.cs new file mode 100644 index 000000000..c911dc517 --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/BinanceCommissions.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Binance.Net.Objects.Models.Spot +{ + /// + /// Binance commissions + /// + public record BinanceCommissions + { + /// + /// Symbol name + /// + [JsonPropertyName("symbol")] + public string Symbol { get; set; } = string.Empty; + /// + /// Standard commission rates on trades from the order. + /// + [JsonPropertyName("standardCommission")] + public BinanceCommissionInfo StandardCommissions { get; set; } = null!; + /// + /// Tax commission rates for trades from the order. + /// + [JsonPropertyName("taxCommission")] + public BinanceCommissionInfo TaxCommissions { get; set; } = null!; + /// + /// Discount commission when paying in BNB + /// + [JsonPropertyName("discount")] + public BinanceDiscountInfo Discount { get; set; } = null!; + + } + + /// + /// Commission info + /// + public record BinanceDiscountInfo + { + /// + /// Standard commission is reduced by this rate when paying commission in BNB. + /// + [JsonPropertyName("discount")] + public decimal Discount { get; set; } + /// + /// Enabled for account + /// + [JsonPropertyName("enabledForAccount")] + public bool EnabledForAccount { get; set; } + /// + /// Enabled for symbol + /// + [JsonPropertyName("enabledForSymbol")] + public bool EnabledForSymbol { get; set; } + /// + /// Discount asset + /// + [JsonPropertyName("discountAsset")] + public string DiscountAsset { get; set; } = string.Empty; + } + + /// + /// Commission info + /// + public record BinanceCommissionInfo + { + /// + /// Maker fee + /// + [JsonPropertyName("maker")] + public decimal Maker { get; set; } + /// + /// Taker fee + /// + [JsonPropertyName("taker")] + public decimal Taker { get; set; } + /// + /// Buyer fee + /// + [JsonPropertyName("buyer")] + public decimal Buyer { get; set; } + /// + /// Seller fee + /// + [JsonPropertyName("seller")] + public decimal Sell { get; set; } + } +}