diff --git a/Binance.Net.UnitTests/BinanceClientTests.cs b/Binance.Net.UnitTests/BinanceClientTests.cs index 3c1984148..3479057ef 100644 --- a/Binance.Net.UnitTests/BinanceClientTests.cs +++ b/Binance.Net.UnitTests/BinanceClientTests.cs @@ -143,7 +143,7 @@ public void ProvidingApiCredentials_Should_SaveApiCredentials() var authProvider = new BinanceAuthenticationProvider(new ApiCredentials("TestKey", "TestSecret")); // assert - Assert.That(authProvider.GetApiKey() == "TestKey"); + Assert.That(authProvider.ApiKey == "TestKey"); } [Test] @@ -156,13 +156,15 @@ public void AddingAuthToRequest_Should_AddApiKeyHeader() // act var headers = new Dictionary(); + IDictionary uriParams = null; + IDictionary bodyParams = null; authProvider.AuthenticateRequest( new BinanceRestApiClient(new TraceLogger(), new BinanceRestOptions(), new BinanceRestOptions().SpotOptions), request.Uri, HttpMethod.Get, - new SortedDictionary(), - new SortedDictionary(), - headers, + ref uriParams, + ref bodyParams, + ref headers, true, ArrayParametersSerialization.MultipleValues, HttpMethodParameterPosition.InUri, RequestBodyFormat.Json); diff --git a/Binance.Net.UnitTests/RestRequestTests.cs b/Binance.Net.UnitTests/RestRequestTests.cs index b175de2d8..1702952e6 100644 --- a/Binance.Net.UnitTests/RestRequestTests.cs +++ b/Binance.Net.UnitTests/RestRequestTests.cs @@ -108,7 +108,7 @@ public async Task ValidateSpotExchangeDataCalls() }); var tester = new RestRequestValidator(client, "Endpoints/Spot/ExchangeData", "https://api.binance.com", IsAuthenticated, stjCompare: true); await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetServerTimeAsync(), "GetServerTime", "serverTime"); - await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetExchangeInfoAsync(), "GetExchangeInfo", ignoreProperties: new List { "orderTypes", "timeInForce" }); + await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetExchangeInfoAsync(), "GetExchangeInfo", ignoreProperties: new List { "orderTypes", "timeInForce", "quoteAssetPrecision" }); await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetSystemStatusAsync(), "GetSystemStatus"); await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetAssetDetailsAsync(), "GetAssetDetails"); await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetRecentTradesAsync("ETHUSDT"), "GetRecentTrades"); @@ -339,7 +339,7 @@ public async Task ValidateCoinFuturesAccountCalls() await tester.ValidateAsync(client => client.CoinFuturesApi.Account.StopUserStreamAsync("123"), "StopUserStream"); await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetAccountInfoAsync(), "GetAccountInfo"); await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetBalancesAsync(), "GetBalances"); - await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetPositionInformationAsync(), "GetPositionInformation", ignoreProperties: new List { "unRealizedProfit" }); + await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetPositionInformationAsync(), "GetPositionInformation"); await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetUserCommissionRateAsync("ETHUSDT"), "GetUserCommissionRate"); await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetDownloadIdForTransactionHistoryAsync(DateTime.UtcNow, DateTime.UtcNow), "GetDownloadIdForTransactionHistory"); await tester.ValidateAsync(client => client.CoinFuturesApi.Account.GetDownloadLinkForTransactionHistoryAsync("123"), "GetDownloadLinkForTransactionHistory", ignoreProperties: new List { "notified" }); diff --git a/Binance.Net/Binance.Net.csproj b/Binance.Net/Binance.Net.csproj index e4d09296c..2cfd106e3 100644 --- a/Binance.Net/Binance.Net.csproj +++ b/Binance.Net/Binance.Net.csproj @@ -48,7 +48,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Binance.Net/BinanceAuthenticationProvider.cs b/Binance.Net/BinanceAuthenticationProvider.cs index ced804542..947e19473 100644 --- a/Binance.Net/BinanceAuthenticationProvider.cs +++ b/Binance.Net/BinanceAuthenticationProvider.cs @@ -5,8 +5,6 @@ namespace Binance.Net { internal class BinanceAuthenticationProvider : AuthenticationProvider { - public string GetApiKey() => _credentials.Key!.GetString(); - public BinanceAuthenticationProvider(ApiCredentials credentials) : base(credentials) { } @@ -15,26 +13,39 @@ public override void AuthenticateRequest( RestApiClient apiClient, Uri uri, HttpMethod method, - IDictionary uriParameters, - IDictionary bodyParameters, - Dictionary headers, + ref IDictionary? uriParameters, + ref IDictionary? bodyParameters, + ref Dictionary? headers, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, RequestBodyFormat requestBodyFormat) { - headers.Add("X-MBX-APIKEY", _credentials.Key!.GetString()); + headers ??= new Dictionary(); + headers.Add("X-MBX-APIKEY", _credentials.Key); if (!auth) return; - var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParameters : bodyParameters; + IDictionary parameters; + if (parameterPosition == HttpMethodParameterPosition.InUri) + { + uriParameters ??= new Dictionary(); + parameters = uriParameters; + } + else + { + bodyParameters ??= new Dictionary(); + parameters = bodyParameters; + } + var timestamp = GetMillisecondTimestamp(apiClient); parameters.Add("timestamp", timestamp); if (_credentials.CredentialType == ApiCredentialsType.Hmac) { - uri = uri.SetParameters(uriParameters, arraySerialization); + if (uriParameters != null) + uri = uri.SetParameters(uriParameters, arraySerialization); parameters.Add("signature", SignHMACSHA256(parameterPosition == HttpMethodParameterPosition.InUri ? uri.Query.Replace("?", "") : parameters.ToFormData())); } else @@ -49,7 +60,7 @@ public Dictionary AuthenticateSocketParameters(Dictionary(providedParameters) { - { "apiKey", _credentials.Key!.GetString() }, + { "apiKey", _credentials.Key }, { "timestamp", DateTimeConverter.ConvertToMilliseconds(DateTime.UtcNow) } }; var paramString = string.Join("&", sortedParameters.Select(p => p.Key + "=" + Convert.ToString(p.Value, CultureInfo.InvariantCulture))); diff --git a/Binance.Net/Clients/SpotApi/BinanceSocketClientSpotApi.cs b/Binance.Net/Clients/SpotApi/BinanceSocketClientSpotApi.cs index 59bb33d1e..679c57681 100644 --- a/Binance.Net/Clients/SpotApi/BinanceSocketClientSpotApi.cs +++ b/Binance.Net/Clients/SpotApi/BinanceSocketClientSpotApi.cs @@ -105,7 +105,7 @@ internal async Task>> QueryAsync(string url, st } else { - parameters.Add("apiKey", authProvider.GetApiKey()); + parameters.Add("apiKey", authProvider.ApiKey); } } diff --git a/Binance.Net/Objects/Models/Futures/BinanceFuturesAccountAsset.cs b/Binance.Net/Objects/Models/Futures/BinanceFuturesAccountAsset.cs index d0e1f532c..da56f6d1a 100644 --- a/Binance.Net/Objects/Models/Futures/BinanceFuturesAccountAsset.cs +++ b/Binance.Net/Objects/Models/Futures/BinanceFuturesAccountAsset.cs @@ -20,7 +20,7 @@ public record BinanceFuturesAccountAsset /// /// Maint Margin /// - [JsonPropertyName("mainMargin")] + [JsonPropertyName("maintMargin")] public decimal MaintMargin { get; set; } /// diff --git a/Binance.Net/Objects/Models/Futures/BinancePosition.cs b/Binance.Net/Objects/Models/Futures/BinancePosition.cs index 9c05f240a..8b829106d 100644 --- a/Binance.Net/Objects/Models/Futures/BinancePosition.cs +++ b/Binance.Net/Objects/Models/Futures/BinancePosition.cs @@ -29,6 +29,8 @@ public record BinancePositionBase /// [JsonPropertyName("unrealizedProfit")] public decimal UnrealizedPnl { get; set; } + [JsonPropertyName("unRealizedProfit")] + internal decimal UnRealizedPnl { set => UnrealizedPnl = value; } /// /// Position side @@ -51,7 +53,7 @@ public record BinancePositionInfoBase: BinancePositionBase /// /// Maint margin /// - [JsonPropertyName("mainMargin")] + [JsonPropertyName("maintMargin")] public decimal MaintMargin { get; set; } ///