Skip to content

Commit

Permalink
CryptoExchange V7.11.0 (#1401)
Browse files Browse the repository at this point in the history
Updated CryptoExchange.Net to V7.11.0
Fixed BinanceFuturesAccountAsset MaintMargin deserialization
Fixed BinancePosition MaintMargin deserialization
Fixed BinancePosition UnrealizedProfit deserialization for Coin-M futures
  • Loading branch information
JKorf authored Aug 7, 2024
1 parent ed9d544 commit 1507195
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
10 changes: 6 additions & 4 deletions Binance.Net.UnitTests/BinanceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -156,13 +156,15 @@ public void AddingAuthToRequest_Should_AddApiKeyHeader()

// act
var headers = new Dictionary<string, string>();
IDictionary<string, object> uriParams = null;
IDictionary<string, object> bodyParams = null;
authProvider.AuthenticateRequest(
new BinanceRestApiClient(new TraceLogger(), new BinanceRestOptions(), new BinanceRestOptions().SpotOptions),
request.Uri,
HttpMethod.Get,
new SortedDictionary<string, object>(),
new SortedDictionary<string, object>(),
headers,
ref uriParams,
ref bodyParams,
ref headers,
true, ArrayParametersSerialization.MultipleValues,
HttpMethodParameterPosition.InUri,
RequestBodyFormat.Json);
Expand Down
4 changes: 2 additions & 2 deletions Binance.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task ValidateSpotExchangeDataCalls()
});
var tester = new RestRequestValidator<BinanceRestClient>(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<string> { "orderTypes", "timeInForce" });
await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetExchangeInfoAsync(), "GetExchangeInfo", ignoreProperties: new List<string> { "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");
Expand Down Expand Up @@ -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<string> { "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<string> { "notified" });
Expand Down
2 changes: 1 addition & 1 deletion Binance.Net/Binance.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.10.0" />
<PackageReference Include="CryptoExchange.Net" Version="7.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
29 changes: 20 additions & 9 deletions Binance.Net/BinanceAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace Binance.Net
{
internal class BinanceAuthenticationProvider : AuthenticationProvider
{
public string GetApiKey() => _credentials.Key!.GetString();

public BinanceAuthenticationProvider(ApiCredentials credentials) : base(credentials)
{
}
Expand All @@ -15,26 +13,39 @@ public override void AuthenticateRequest(
RestApiClient apiClient,
Uri uri,
HttpMethod method,
IDictionary<string, object> uriParameters,
IDictionary<string, object> bodyParameters,
Dictionary<string, string> headers,
ref IDictionary<string, object>? uriParameters,
ref IDictionary<string, object>? bodyParameters,
ref Dictionary<string, string>? headers,
bool auth,
ArrayParametersSerialization arraySerialization,
HttpMethodParameterPosition parameterPosition,
RequestBodyFormat requestBodyFormat)
{
headers.Add("X-MBX-APIKEY", _credentials.Key!.GetString());
headers ??= new Dictionary<string, string>();
headers.Add("X-MBX-APIKEY", _credentials.Key);

if (!auth)
return;

var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParameters : bodyParameters;
IDictionary<string, object> parameters;
if (parameterPosition == HttpMethodParameterPosition.InUri)
{
uriParameters ??= new Dictionary<string, object>();
parameters = uriParameters;
}
else
{
bodyParameters ??= new Dictionary<string, object>();
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
Expand All @@ -49,7 +60,7 @@ public Dictionary<string, object> AuthenticateSocketParameters(Dictionary<string
{
var sortedParameters = new SortedDictionary<string, object>(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)));
Expand Down
2 changes: 1 addition & 1 deletion Binance.Net/Clients/SpotApi/BinanceSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal async Task<CallResult<BinanceResponse<T>>> QueryAsync<T>(string url, st
}
else
{
parameters.Add("apiKey", authProvider.GetApiKey());
parameters.Add("apiKey", authProvider.ApiKey);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public record BinanceFuturesAccountAsset
/// <summary>
/// Maint Margin
/// </summary>
[JsonPropertyName("mainMargin")]
[JsonPropertyName("maintMargin")]
public decimal MaintMargin { get; set; }

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Binance.Net/Objects/Models/Futures/BinancePosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public record BinancePositionBase
/// </summary>
[JsonPropertyName("unrealizedProfit")]
public decimal UnrealizedPnl { get; set; }
[JsonPropertyName("unRealizedProfit")]
internal decimal UnRealizedPnl { set => UnrealizedPnl = value; }

/// <summary>
/// Position side
Expand All @@ -51,7 +53,7 @@ public record BinancePositionInfoBase: BinancePositionBase
/// <summary>
/// Maint margin
/// </summary>
[JsonPropertyName("mainMargin")]
[JsonPropertyName("maintMargin")]
public decimal MaintMargin { get; set; }

/// <summary>
Expand Down

0 comments on commit 1507195

Please sign in to comment.