Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions BingX.Net.UnitTests/BingXRestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using CryptoExchange.Net.Objects;
using BingX.Net.Interfaces.Clients;
using CryptoExchange.Net.Converters.SystemTextJson;
using BingX.Net.Clients.SpotApi;

namespace BingX.Net.UnitTests
{
Expand All @@ -18,7 +19,7 @@ public class BingXRestClientTests
[Test]
public void CheckSignatureExample1()
{
var authProvider = new BingXAuthenticationProvider(new ApiCredentials("hO6oQotzTE0S5FRYze2Jx2wGx7eVnJGMolpA1nZyehsoMgCcgKNWQHd4QgTFZuwl4Zt4xMe2PqGBegWXO4A", "mheO6dR8ovSsxZQCOYEFCtelpuxcWGTfHw7te326y6jOwq5WpvFQ9JNljoTwBXZGv5It07m9RXSPpDQEK2w"));
var authProvider = new BingXAuthenticationProvider(new BingXCredentials("hO6oQotzTE0S5FRYze2Jx2wGx7eVnJGMolpA1nZyehsoMgCcgKNWQHd4QgTFZuwl4Zt4xMe2PqGBegWXO4A", "mheO6dR8ovSsxZQCOYEFCtelpuxcWGTfHw7te326y6jOwq5WpvFQ9JNljoTwBXZGv5It07m9RXSPpDQEK2w"));
var client = (RestApiClient)new BingXRestClient().SpotApi;

CryptoExchange.Net.Testing.TestHelpers.CheckSignature(
Expand Down Expand Up @@ -139,8 +140,8 @@ public void TestConstructorConfiguration()

Assert.That(((BaseApiClient)restClient.SpotApi).OutputOriginalData, Is.True);
Assert.That(((BaseApiClient)socketClient.SpotApi).OutputOriginalData, Is.False);
Assert.That(((BaseApiClient)restClient.SpotApi).AuthenticationProvider.ApiKey, Is.EqualTo("123"));
Assert.That(((BaseApiClient)socketClient.SpotApi).AuthenticationProvider.ApiKey, Is.EqualTo("456"));
Assert.That(((BingXRestClientSpotApi)restClient.SpotApi).AuthenticationProvider.Key, Is.EqualTo("123"));
Assert.That(((BingXSocketClientSpotApi)socketClient.SpotApi).AuthenticationProvider.Key, Is.EqualTo("456"));
Assert.That(((BaseApiClient)restClient.SpotApi).ClientOptions.Proxy.Host, Is.EqualTo("host"));
Assert.That(((BaseApiClient)restClient.SpotApi).ClientOptions.Proxy.Port, Is.EqualTo(80));
Assert.That(((BaseApiClient)socketClient.SpotApi).ClientOptions.Proxy.Host, Is.EqualTo("host2"));
Expand Down
3 changes: 2 additions & 1 deletion BingX.Net.UnitTests/BingXRestIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BingX.Net;
using BingX.Net.Clients;
using BingX.Net.SymbolOrderBooks;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Objects.Errors;
using CryptoExchange.Net.Testing;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -31,7 +32,7 @@ public override BingXRestClient GetClient(ILoggerFactory loggerFactory)
return new BingXRestClient(null, loggerFactory, Options.Create(new Objects.Options.BingXRestOptions
{
OutputOriginalData = true,
ApiCredentials = Authenticated ? new CryptoExchange.Net.Authentication.ApiCredentials(key, sec) : null
ApiCredentials = Authenticated ? new BingXCredentials(key, sec) : null
}));
}

Expand Down
5 changes: 3 additions & 2 deletions BingX.Net.UnitTests/BingXSocketIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BingX.Net.Clients;
using BingX.Net.Objects.Models;
using BingX.Net.Objects.Options;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Testing;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -28,7 +29,7 @@ public override BingXSocketClient GetClient(ILoggerFactory loggerFactory)
return new BingXSocketClient(Options.Create(new BingXSocketOptions
{
OutputOriginalData = true,
ApiCredentials = Authenticated ? new CryptoExchange.Net.Authentication.ApiCredentials(key, sec) : null
ApiCredentials = Authenticated ? new BingXCredentials(key, sec) : null
}), loggerFactory);
}

Expand All @@ -40,7 +41,7 @@ private BingXRestClient GetRestClient()
Authenticated = key != null && sec != null;
return new BingXRestClient(x =>
{
x.ApiCredentials = Authenticated ? new CryptoExchange.Net.Authentication.ApiCredentials(key, sec) : null;
x.ApiCredentials = Authenticated ? new BingXCredentials(key, sec) : null;
});
}

Expand Down
12 changes: 6 additions & 6 deletions BingX.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task ValidateSpotAccountCalls()
var client = new BingXRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new ApiCredentials("123", "456");
opts.ApiCredentials = new BingXCredentials("123", "456");
opts.OutputOriginalData = true;
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/Spot/Account", "https://open-api.bingx.com", IsAuthenticated);
Expand Down Expand Up @@ -49,7 +49,7 @@ public async Task ValidateSpotExchangeDataCalls()
var client = new BingXRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new ApiCredentials("123", "456");
opts.ApiCredentials = new BingXCredentials("123", "456");
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/Spot/ExchangeData", "https://open-api.bingx.com", IsAuthenticated, "data");
await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetSymbolsAsync(), "GetSymbols", nestedJsonProperty: "data.symbols");
Expand All @@ -68,7 +68,7 @@ public async Task ValidateSpotTradingCalls()
var client = new BingXRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new ApiCredentials("123", "456");
opts.ApiCredentials = new BingXCredentials("123", "456");
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/Spot/Trading", "https://open-api.bingx.com", IsAuthenticated, "data");
await tester.ValidateAsync(client => client.SpotApi.Trading.PlaceOrderAsync("ETHUSDT", Enums.OrderSide.Buy, Enums.OrderType.Market, 1), "PlaceOrder", nestedJsonProperty: "data");
Expand All @@ -93,7 +93,7 @@ public async Task ValidatePerpetualFuturesAccountCalls()
var client = new BingXRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new ApiCredentials("123", "456");
opts.ApiCredentials = new BingXCredentials("123", "456");
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/PerpetualFutures/Account", "https://open-api.bingx.com", IsAuthenticated, "data");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetBalancesAsync(), "GetBalances", nestedJsonProperty: "data");
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task ValidatePerpetualFuturesExchangeDataCalls()
var client = new BingXRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new ApiCredentials("123", "456");
opts.ApiCredentials = new BingXCredentials("123", "456");
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/PerpetualFutures/ExchangeData", "https://open-api.bingx.com", IsAuthenticated, "data");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.ExchangeData.GetContractsAsync(), "GetContracts", nestedJsonProperty: "data", ignoreProperties: new List<string> { "tradeMinLimit" });
Expand All @@ -147,7 +147,7 @@ public async Task ValidatePerpetualFuturesTradingCalls()
var client = new BingXRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new ApiCredentials("123", "456");
opts.ApiCredentials = new BingXCredentials("123", "456");
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/PerpetualFutures/Trading", "https://open-api.bingx.com", IsAuthenticated, "data");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.GetPositionsAsync(), "GetPositions");
Expand Down
9 changes: 5 additions & 4 deletions BingX.Net.UnitTests/SocketSubscriptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BingX.Net.Clients;
using BingX.Net.Objects.Models;
using BingX.Net.Objects.Options;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Testing;
using Microsoft.Extensions.Logging;
Expand All @@ -22,7 +23,7 @@ public async Task ValidateConcurrentSpotSubscriptions()

var client = new BingXSocketClient(Options.Create(new BingXSocketOptions
{
ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "456"),
ApiCredentials = new BingXCredentials("123", "456"),
OutputOriginalData = true
}), logger);

Expand All @@ -41,7 +42,7 @@ public async Task ValidateSpotSubscriptions()

var client = new BingXSocketClient(Options.Create(new BingXSocketOptions
{
ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "456")
ApiCredentials = new BingXCredentials("123", "456")
}), logger);
var tester = new SocketSubscriptionValidator<BingXSocketClient>(client, "Subscriptions/Spot", "wss://open-api-ws.bingx.com/market");
await tester.ValidateAsync<BingXTradeUpdate>((client, handler) => client.SpotApi.SubscribeToTradeUpdatesAsync("BTC-USDT", handler), "Trades", nestedJsonProperty: "data");
Expand All @@ -63,7 +64,7 @@ public async Task ValidateConcurrentPerpetualFutureSubscriptions()

var client = new BingXSocketClient(Options.Create(new BingXSocketOptions
{
ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "456"),
ApiCredentials = new BingXCredentials("123", "456"),
OutputOriginalData = true
}), logger);

Expand All @@ -82,7 +83,7 @@ public async Task ValidatePerpetualFutureSubscriptions()

var client = new BingXSocketClient(Options.Create(new BingXSocketOptions
{
ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "456")
ApiCredentials = new BingXCredentials("123", "456")
}), logger);
var tester = new SocketSubscriptionValidator<BingXSocketClient>(client, "Subscriptions/PerpetualFutures", "wss://open-api-ws.bingx.com/market");
await tester.ValidateAsync<BingXFuturesTradeUpdate[]>((client, handler) => client.PerpetualFuturesApi.SubscribeToTradeUpdatesAsync("ETH-USDT", handler), "Trades", nestedJsonProperty: "data");
Expand Down
5 changes: 4 additions & 1 deletion BingX.Net/BingX.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<PackageReleaseNotes>https://github.com/JKorf/BingX.Net?tab=readme-ov-file#release-notes</PackageReleaseNotes>
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
</PropertyGroup>
<PropertyGroup Label="AOT" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
<IsAotCompatible>true</IsAotCompatible>
Expand Down Expand Up @@ -52,10 +53,12 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="10.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.101">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CryptoExchange.Net\CryptoExchange.Net\CryptoExchange.Net.csproj" />
</ItemGroup>
</Project>
7 changes: 3 additions & 4 deletions BingX.Net/BingXAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
using System.Collections.Generic;
using BingX.Net.Objects.Options;
using CryptoExchange.Net;
using CryptoExchange.Net.Authentication;

Check failure on line 5 in BingX.Net/BingXAuthenticationProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Authentication' does not exist in the namespace 'CryptoExchange.Net' (are you missing an assembly reference?)
using CryptoExchange.Net.Clients;

Check failure on line 6 in BingX.Net/BingXAuthenticationProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Clients' does not exist in the namespace 'CryptoExchange.Net' (are you missing an assembly reference?)
using CryptoExchange.Net.Objects;

Check failure on line 7 in BingX.Net/BingXAuthenticationProvider.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Objects' does not exist in the namespace 'CryptoExchange.Net' (are you missing an assembly reference?)
using System.Linq;
using System.Globalization;

namespace BingX.Net
{
internal class BingXAuthenticationProvider : AuthenticationProvider
internal class BingXAuthenticationProvider : AuthenticationProvider<BingXCredentials, BingXCredentials>
{
public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.Hmac];
public BingXAuthenticationProvider(ApiCredentials credentials) : base(credentials)
public BingXAuthenticationProvider(BingXCredentials credentials) : base(credentials, credentials)
{
}

public override void ProcessRequest(RestApiClient apiClient, RestRequestConfiguration request)
{
request.Headers ??= new Dictionary<string, string>();
request.Headers.Add("X-BX-APIKEY", ApiKey);
request.Headers.Add("X-BX-APIKEY", Credential.Key);

if (!request.Authenticated)
return;
Expand Down
48 changes: 48 additions & 0 deletions BingX.Net/BingXCredentials.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using CryptoExchange.Net.Authentication;

Check failure on line 1 in BingX.Net/BingXCredentials.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Authentication' does not exist in the namespace 'CryptoExchange.Net' (are you missing an assembly reference?)
using System;
using System.Net;

namespace BingX.Net
{
/// <summary>
/// BingX API credentials
/// </summary>
public class BingXCredentials : HMACCredential
{
/// <summary>
/// Create new credentials
/// </summary>
public BingXCredentials() { }

/// <summary>
/// Create new credentials providing credentials in HMAC format
/// </summary>
/// <param name="key">API key</param>
/// <param name="secret">API secret</param>
public BingXCredentials(string key, string secret) : base(key, secret)
{
}

/// <summary>
/// Create new credentials providing HMAC credentials
/// </summary>
/// <param name="credential">Credentials</param>
public BingXCredentials(HMACCredential credential) : base(credential.Key, credential.Secret)
{
}

/// <summary>
/// Specify the HMAC credentials
/// </summary>
/// <param name="key">API key</param>
/// <param name="secret">API secret</param>
public BingXCredentials WithHMAC(string key, string secret)
{
if (!string.IsNullOrEmpty(Key)) throw new InvalidOperationException("Credentials already set");

Key = key;
Secret = secret;
return this;
}
}
}
4 changes: 2 additions & 2 deletions BingX.Net/BingXTrackerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public IUserSpotDataTracker CreateUserSpotDataTracker(SpotUserDataTrackerConfig?
}

/// <inheritdoc />
public IUserSpotDataTracker CreateUserSpotDataTracker(string userIdentifier, ApiCredentials credentials, SpotUserDataTrackerConfig? config = null, BingXEnvironment? environment = null)
public IUserSpotDataTracker CreateUserSpotDataTracker(string userIdentifier, BingXCredentials credentials, SpotUserDataTrackerConfig? config = null, BingXEnvironment? environment = null)
{
var clientProvider = _serviceProvider?.GetRequiredService<IBingXUserClientProvider>() ?? new BingXUserClientProvider();
var restClient = clientProvider.GetRestClient(userIdentifier, credentials, environment);
Expand Down Expand Up @@ -143,7 +143,7 @@ public IUserFuturesDataTracker BingXUserPerpetualFuturesDataTracker(FuturesUserD
}

/// <inheritdoc />
public IUserFuturesDataTracker BingXUserPerpetualFuturesDataTracker(string userIdentifier, ApiCredentials credentials, FuturesUserDataTrackerConfig? config = null, BingXEnvironment? environment = null)
public IUserFuturesDataTracker BingXUserPerpetualFuturesDataTracker(string userIdentifier, BingXCredentials credentials, FuturesUserDataTrackerConfig? config = null, BingXEnvironment? environment = null)
{
var clientProvider = _serviceProvider?.GetRequiredService<IBingXUserClientProvider>() ?? new BingXUserClientProvider();
var restClient = clientProvider.GetRestClient(userIdentifier, credentials, environment);
Expand Down
2 changes: 1 addition & 1 deletion BingX.Net/Clients/Apis/BingXRestClientSubAccountApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace BingX.Net.Clients.Apis
{
/// <inheritdoc cref="IBingXRestClientSubAccountApi" />
public class BingXRestClientSubAccountApi : BingXRestClientApi, IBingXRestClientSubAccountApi
internal class BingXRestClientSubAccountApi : BingXRestClientApi, IBingXRestClientSubAccountApi
{
#region fields
private static readonly RequestDefinitionCache _definitions = new();
Expand Down
17 changes: 1 addition & 16 deletions BingX.Net/Clients/BingXRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace BingX.Net.Clients
{
/// <inheritdoc cref="IBingXRestClient" />
public class BingXRestClient : BaseRestClient, IBingXRestClient
public class BingXRestClient : BaseRestClient<BingXEnvironment, BingXCredentials>, IBingXRestClient
{
#region Api clients

Expand Down Expand Up @@ -58,14 +58,6 @@ public BingXRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, IO

#endregion

/// <inheritdoc />
public void SetOptions(UpdateOptions options)
{
PerpetualFuturesApi.SetOptions(options);
SpotApi.SetOptions(options);
SubAccountApi.SetOptions(options);
}

/// <summary>
/// Set the default options to be used when creating new clients
/// </summary>
Expand All @@ -75,12 +67,5 @@ public static void SetDefaultOptions(Action<BingXRestOptions> optionsDelegate)
BingXRestOptions.Default = ApplyOptionsDelegate(optionsDelegate);
}

/// <inheritdoc />
public void SetApiCredentials(ApiCredentials credentials)
{
SpotApi.SetApiCredentials(credentials);
PerpetualFuturesApi.SetApiCredentials(credentials);
SubAccountApi.SetApiCredentials(credentials);
}
}
}
4 changes: 2 additions & 2 deletions BingX.Net/Clients/BingXRestClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace BingX.Net.Clients
/// <summary>
/// BingX rest client base
/// </summary>
public abstract class BingXRestClientApi : RestApiClient
internal abstract class BingXRestClientApi : RestApiClient<BingXEnvironment, BingXAuthenticationProvider, BingXCredentials>
{
private IStringMessageSerializer? _serializer;

Expand Down Expand Up @@ -51,7 +51,7 @@ public override string FormatSymbol(string baseAsset, string quoteAsset, Trading
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(SerializerOptions.WithConverters(BingXExchange._serializerContext));

/// <inheritdoc />
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
protected override BingXAuthenticationProvider CreateAuthenticationProvider(BingXCredentials credentials)
=> new BingXAuthenticationProvider(credentials);

internal Task<WebCallResult> SendAsync(RequestDefinition definition, ParameterCollection? parameters, CancellationToken cancellationToken, int? weight = null)
Expand Down
15 changes: 1 addition & 14 deletions BingX.Net/Clients/BingXSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace BingX.Net.Clients
{
/// <inheritdoc cref="IBingXSocketClient" />
public class BingXSocketClient : BaseSocketClient, IBingXSocketClient
public class BingXSocketClient : BaseSocketClient<BingXEnvironment, BingXCredentials>, IBingXSocketClient
{
#region fields
#endregion
Expand Down Expand Up @@ -54,13 +54,6 @@ public BingXSocketClient(IOptions<BingXSocketOptions> options, ILoggerFactory? l
}
#endregion

/// <inheritdoc />
public void SetOptions(UpdateOptions options)
{
PerpetualFuturesApi.SetOptions(options);
SpotApi.SetOptions(options);
}

/// <summary>
/// Set the default options to be used when creating new clients
/// </summary>
Expand All @@ -70,11 +63,5 @@ public static void SetDefaultOptions(Action<BingXSocketOptions> optionsDelegate)
BingXSocketOptions.Default = ApplyOptionsDelegate(optionsDelegate);
}

/// <inheritdoc />
public void SetApiCredentials(ApiCredentials credentials)
{
SpotApi.SetApiCredentials(credentials);
PerpetualFuturesApi.SetApiCredentials(credentials);
}
}
}
Loading
Loading