From 733f973f7102e46d74c9d902e45f3e90597c0566 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Fri, 13 Mar 2026 16:30:37 +0100 Subject: [PATCH 1/9] wip --- BingX.Net.UnitTests/BingXRestClientTests.cs | 7 ++++--- .../BingXRestIntegrationTests.cs | 2 +- .../BingXSocketIntegrationTests.cs | 4 ++-- BingX.Net.UnitTests/RestRequestTests.cs | 12 ++++++------ BingX.Net.UnitTests/SocketSubscriptionTests.cs | 8 ++++---- BingX.Net/BingX.Net.csproj | 4 +++- BingX.Net/BingXAuthenticationProvider.cs | 6 +++--- BingX.Net/BingXCredentials.cs | 18 ++++++++++++++++++ BingX.Net/BingXTrackerFactory.cs | 4 ++-- .../Apis/BingXRestClientSubAccountApi.cs | 2 +- BingX.Net/Clients/BingXRestClient.cs | 17 +---------------- BingX.Net/Clients/BingXRestClientApi.cs | 6 +++--- BingX.Net/Clients/BingXSocketClient.cs | 15 +-------------- BingX.Net/Clients/BingXUserClientProvider.cs | 10 +++++----- .../BingXSocketClientPerpetualFuturesApi.cs | 4 ++-- .../SpotApi/BingXSocketClientSpotApi.cs | 4 ++-- .../Interfaces/Clients/IBingXRestClient.cs | 14 +------------- .../Interfaces/Clients/IBingXSocketClient.cs | 14 +------------- .../Clients/IBingXUserClientProvider.cs | 6 +++--- .../IBingXRestClientPerpetualFuturesApi.cs | 2 +- .../IBingXSocketClientPerpetualFuturesApi.cs | 2 +- .../Clients/SpotApi/IBingXRestClientSpotApi.cs | 2 +- .../SpotApi/IBingXSocketClientSpotApi.cs | 2 +- BingX.Net/Interfaces/IBingXTrackerFactory.cs | 4 ++-- BingX.Net/Objects/Options/BingXOptions.cs | 2 +- BingX.Net/Objects/Options/BingXRestOptions.cs | 6 +++--- .../Objects/Options/BingXSocketOptions.cs | 6 +++--- 27 files changed, 76 insertions(+), 107 deletions(-) create mode 100644 BingX.Net/BingXCredentials.cs diff --git a/BingX.Net.UnitTests/BingXRestClientTests.cs b/BingX.Net.UnitTests/BingXRestClientTests.cs index b31e0cf..c5c7efb 100644 --- a/BingX.Net.UnitTests/BingXRestClientTests.cs +++ b/BingX.Net.UnitTests/BingXRestClientTests.cs @@ -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 { @@ -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( @@ -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.PublicKey, Is.EqualTo("123")); + Assert.That(((BingXSocketClientSpotApi)socketClient.SpotApi).AuthenticationProvider.PublicKey, 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")); diff --git a/BingX.Net.UnitTests/BingXRestIntegrationTests.cs b/BingX.Net.UnitTests/BingXRestIntegrationTests.cs index dad91c7..b951c70 100644 --- a/BingX.Net.UnitTests/BingXRestIntegrationTests.cs +++ b/BingX.Net.UnitTests/BingXRestIntegrationTests.cs @@ -31,7 +31,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 })); } diff --git a/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs b/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs index 8a7941d..9296226 100644 --- a/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs +++ b/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs @@ -28,7 +28,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); } @@ -40,7 +40,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; }); } diff --git a/BingX.Net.UnitTests/RestRequestTests.cs b/BingX.Net.UnitTests/RestRequestTests.cs index afb6a55..71ea582 100644 --- a/BingX.Net.UnitTests/RestRequestTests.cs +++ b/BingX.Net.UnitTests/RestRequestTests.cs @@ -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(client, "Endpoints/Spot/Account", "https://open-api.bingx.com", IsAuthenticated); @@ -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(client, "Endpoints/Spot/ExchangeData", "https://open-api.bingx.com", IsAuthenticated, "data"); await tester.ValidateAsync(client => client.SpotApi.ExchangeData.GetSymbolsAsync(), "GetSymbols", nestedJsonProperty: "data.symbols"); @@ -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(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"); @@ -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(client, "Endpoints/PerpetualFutures/Account", "https://open-api.bingx.com", IsAuthenticated, "data"); await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetBalancesAsync(), "GetBalances", nestedJsonProperty: "data"); @@ -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(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 { "tradeMinLimit" }); @@ -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(client, "Endpoints/PerpetualFutures/Trading", "https://open-api.bingx.com", IsAuthenticated, "data"); await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.GetPositionsAsync(), "GetPositions"); diff --git a/BingX.Net.UnitTests/SocketSubscriptionTests.cs b/BingX.Net.UnitTests/SocketSubscriptionTests.cs index a367e1b..ac99309 100644 --- a/BingX.Net.UnitTests/SocketSubscriptionTests.cs +++ b/BingX.Net.UnitTests/SocketSubscriptionTests.cs @@ -22,7 +22,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); @@ -41,7 +41,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(client, "Subscriptions/Spot", "wss://open-api-ws.bingx.com/market"); await tester.ValidateAsync((client, handler) => client.SpotApi.SubscribeToTradeUpdatesAsync("BTC-USDT", handler), "Trades", nestedJsonProperty: "data"); @@ -63,7 +63,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); @@ -82,7 +82,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(client, "Subscriptions/PerpetualFutures", "wss://open-api-ws.bingx.com/market"); await tester.ValidateAsync((client, handler) => client.PerpetualFuturesApi.SubscribeToTradeUpdatesAsync("ETH-USDT", handler), "Trades", nestedJsonProperty: "data"); diff --git a/BingX.Net/BingX.Net.csproj b/BingX.Net/BingX.Net.csproj index f0e9e58..3785f35 100644 --- a/BingX.Net/BingX.Net.csproj +++ b/BingX.Net/BingX.Net.csproj @@ -52,10 +52,12 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/BingX.Net/BingXAuthenticationProvider.cs b/BingX.Net/BingXAuthenticationProvider.cs index 5174eec..87e5e61 100644 --- a/BingX.Net/BingXAuthenticationProvider.cs +++ b/BingX.Net/BingXAuthenticationProvider.cs @@ -10,17 +10,17 @@ namespace BingX.Net { - internal class BingXAuthenticationProvider : AuthenticationProvider + internal class BingXAuthenticationProvider : AuthenticationProvider { public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.Hmac]; - public BingXAuthenticationProvider(ApiCredentials credentials) : base(credentials) + public BingXAuthenticationProvider(BingXCredentials credentials) : base(credentials) { } public override void ProcessRequest(RestApiClient apiClient, RestRequestConfiguration request) { request.Headers ??= new Dictionary(); - request.Headers.Add("X-BX-APIKEY", ApiKey); + request.Headers.Add("X-BX-APIKEY", Credential.PublicKey); if (!request.Authenticated) return; diff --git a/BingX.Net/BingXCredentials.cs b/BingX.Net/BingXCredentials.cs new file mode 100644 index 0000000..3ef809d --- /dev/null +++ b/BingX.Net/BingXCredentials.cs @@ -0,0 +1,18 @@ +using CryptoExchange.Net.Authentication; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BingX.Net +{ + public class BingXCredentials : ApiCredentials + { + public BingXCredentials(string apiKey, string secret) : this(new HMACCredential(apiKey, secret)) { } + + public BingXCredentials(HMACCredential credential) : base(credential) { } + + public override ApiCredentials Copy() => new BingXCredentials(Hmac!); + } +} diff --git a/BingX.Net/BingXTrackerFactory.cs b/BingX.Net/BingXTrackerFactory.cs index 185d03e..40da295 100644 --- a/BingX.Net/BingXTrackerFactory.cs +++ b/BingX.Net/BingXTrackerFactory.cs @@ -114,7 +114,7 @@ public IUserSpotDataTracker CreateUserSpotDataTracker(SpotUserDataTrackerConfig? } /// - 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() ?? new BingXUserClientProvider(); var restClient = clientProvider.GetRestClient(userIdentifier, credentials, environment); @@ -143,7 +143,7 @@ public IUserFuturesDataTracker BingXUserPerpetualFuturesDataTracker(FuturesUserD } /// - 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() ?? new BingXUserClientProvider(); var restClient = clientProvider.GetRestClient(userIdentifier, credentials, environment); diff --git a/BingX.Net/Clients/Apis/BingXRestClientSubAccountApi.cs b/BingX.Net/Clients/Apis/BingXRestClientSubAccountApi.cs index 23a3a21..3ba4133 100644 --- a/BingX.Net/Clients/Apis/BingXRestClientSubAccountApi.cs +++ b/BingX.Net/Clients/Apis/BingXRestClientSubAccountApi.cs @@ -15,7 +15,7 @@ namespace BingX.Net.Clients.Apis { /// - public class BingXRestClientSubAccountApi : BingXRestClientApi, IBingXRestClientSubAccountApi + internal class BingXRestClientSubAccountApi : BingXRestClientApi, IBingXRestClientSubAccountApi { #region fields private static readonly RequestDefinitionCache _definitions = new(); diff --git a/BingX.Net/Clients/BingXRestClient.cs b/BingX.Net/Clients/BingXRestClient.cs index 8adb689..5f17f8c 100644 --- a/BingX.Net/Clients/BingXRestClient.cs +++ b/BingX.Net/Clients/BingXRestClient.cs @@ -17,7 +17,7 @@ namespace BingX.Net.Clients { /// - public class BingXRestClient : BaseRestClient, IBingXRestClient + public class BingXRestClient : BaseRestClient, IBingXRestClient { #region Api clients @@ -58,14 +58,6 @@ public BingXRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, IO #endregion - /// - public void SetOptions(UpdateOptions options) - { - PerpetualFuturesApi.SetOptions(options); - SpotApi.SetOptions(options); - SubAccountApi.SetOptions(options); - } - /// /// Set the default options to be used when creating new clients /// @@ -75,12 +67,5 @@ public static void SetDefaultOptions(Action optionsDelegate) BingXRestOptions.Default = ApplyOptionsDelegate(optionsDelegate); } - /// - public void SetApiCredentials(ApiCredentials credentials) - { - SpotApi.SetApiCredentials(credentials); - PerpetualFuturesApi.SetApiCredentials(credentials); - SubAccountApi.SetApiCredentials(credentials); - } } } diff --git a/BingX.Net/Clients/BingXRestClientApi.cs b/BingX.Net/Clients/BingXRestClientApi.cs index 8b075da..2e04b64 100644 --- a/BingX.Net/Clients/BingXRestClientApi.cs +++ b/BingX.Net/Clients/BingXRestClientApi.cs @@ -23,7 +23,7 @@ namespace BingX.Net.Clients /// /// BingX rest client base /// - public abstract class BingXRestClientApi : RestApiClient + internal abstract class BingXRestClientApi : RestApiClient { private IStringMessageSerializer? _serializer; @@ -35,7 +35,7 @@ public abstract class BingXRestClientApi : RestApiClient #endregion #region constructor/destructor - internal BingXRestClientApi(ILogger logger, HttpClient? httpClient, BingXRestOptions options, RestApiOptions apiOptions) + internal BingXRestClientApi(ILogger logger, HttpClient? httpClient, BingXRestOptions options, RestApiOptions apiOptions) : base(logger, httpClient, options.Environment.RestClientAddress, options, apiOptions) { ParameterPositions[HttpMethod.Delete] = HttpMethodParameterPosition.InUri; @@ -51,7 +51,7 @@ public override string FormatSymbol(string baseAsset, string quoteAsset, Trading protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(SerializerOptions.WithConverters(BingXExchange._serializerContext)); /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) + protected override BingXAuthenticationProvider CreateAuthenticationProvider(BingXCredentials credentials) => new BingXAuthenticationProvider(credentials); internal Task SendAsync(RequestDefinition definition, ParameterCollection? parameters, CancellationToken cancellationToken, int? weight = null) diff --git a/BingX.Net/Clients/BingXSocketClient.cs b/BingX.Net/Clients/BingXSocketClient.cs index 4801226..4d42553 100644 --- a/BingX.Net/Clients/BingXSocketClient.cs +++ b/BingX.Net/Clients/BingXSocketClient.cs @@ -14,7 +14,7 @@ namespace BingX.Net.Clients { /// - public class BingXSocketClient : BaseSocketClient, IBingXSocketClient + public class BingXSocketClient : BaseSocketClient, IBingXSocketClient { #region fields #endregion @@ -54,13 +54,6 @@ public BingXSocketClient(IOptions options, ILoggerFactory? l } #endregion - /// - public void SetOptions(UpdateOptions options) - { - PerpetualFuturesApi.SetOptions(options); - SpotApi.SetOptions(options); - } - /// /// Set the default options to be used when creating new clients /// @@ -70,11 +63,5 @@ public static void SetDefaultOptions(Action optionsDelegate) BingXSocketOptions.Default = ApplyOptionsDelegate(optionsDelegate); } - /// - public void SetApiCredentials(ApiCredentials credentials) - { - SpotApi.SetApiCredentials(credentials); - PerpetualFuturesApi.SetApiCredentials(credentials); - } } } diff --git a/BingX.Net/Clients/BingXUserClientProvider.cs b/BingX.Net/Clients/BingXUserClientProvider.cs index bee2c97..0d4f762 100644 --- a/BingX.Net/Clients/BingXUserClientProvider.cs +++ b/BingX.Net/Clients/BingXUserClientProvider.cs @@ -49,7 +49,7 @@ public BingXUserClientProvider( } /// - public void InitializeUserClient(string userIdentifier, ApiCredentials credentials, BingXEnvironment? environment = null) + public void InitializeUserClient(string userIdentifier, BingXCredentials credentials, BingXEnvironment? environment = null) { CreateRestClient(userIdentifier, credentials, environment); CreateSocketClient(userIdentifier, credentials, environment); @@ -63,7 +63,7 @@ public void ClearUserClients(string userIdentifier) } /// - public IBingXRestClient GetRestClient(string userIdentifier, ApiCredentials? credentials = null, BingXEnvironment? environment = null) + public IBingXRestClient GetRestClient(string userIdentifier, BingXCredentials? credentials = null, BingXEnvironment? environment = null) { if (!_restClients.TryGetValue(userIdentifier, out var client) || client.Disposed) client = CreateRestClient(userIdentifier, credentials, environment); @@ -72,7 +72,7 @@ public IBingXRestClient GetRestClient(string userIdentifier, ApiCredentials? cre } /// - public IBingXSocketClient GetSocketClient(string userIdentifier, ApiCredentials? credentials = null, BingXEnvironment? environment = null) + public IBingXSocketClient GetSocketClient(string userIdentifier, BingXCredentials? credentials = null, BingXEnvironment? environment = null) { if (!_socketClients.TryGetValue(userIdentifier, out var client) || client.Disposed) client = CreateSocketClient(userIdentifier, credentials, environment); @@ -80,7 +80,7 @@ public IBingXSocketClient GetSocketClient(string userIdentifier, ApiCredentials? return client; } - private IBingXRestClient CreateRestClient(string userIdentifier, ApiCredentials? credentials, BingXEnvironment? environment) + private IBingXRestClient CreateRestClient(string userIdentifier, BingXCredentials? credentials, BingXEnvironment? environment) { var clientRestOptions = SetRestEnvironment(environment); var client = new BingXRestClient(_httpClient, _loggerFactory, clientRestOptions); @@ -92,7 +92,7 @@ private IBingXRestClient CreateRestClient(string userIdentifier, ApiCredentials? return client; } - private IBingXSocketClient CreateSocketClient(string userIdentifier, ApiCredentials? credentials, BingXEnvironment? environment) + private IBingXSocketClient CreateSocketClient(string userIdentifier, BingXCredentials? credentials, BingXEnvironment? environment) { var clientSocketOptions = SetSocketEnvironment(environment); var client = new BingXSocketClient(clientSocketOptions!, _loggerFactory); diff --git a/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs b/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs index 4ae6655..b25af5e 100644 --- a/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs +++ b/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs @@ -30,7 +30,7 @@ namespace BingX.Net.Clients.PerpetualFuturesApi /// /// Client providing access to the BingX futures websocket Api /// - internal partial class BingXSocketClientPerpetualFuturesApi : SocketApiClient, IBingXSocketClientPerpetualFuturesApi + internal partial class BingXSocketClientPerpetualFuturesApi : SocketApiClient, IBingXSocketClientPerpetualFuturesApi { // No HighPerf websocket subscriptions because the data is received compressed and needs to be decompressed @@ -56,7 +56,7 @@ public override string FormatSymbol(string baseAsset, string quoteAsset, Trading => BingXExchange.FormatSymbol(baseAsset, quoteAsset, tradingMode, deliverTime); /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) + protected override BingXAuthenticationProvider CreateAuthenticationProvider(BingXCredentials credentials) => new BingXAuthenticationProvider(credentials); diff --git a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs index 07731d3..963093c 100644 --- a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs +++ b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs @@ -30,7 +30,7 @@ namespace BingX.Net.Clients.SpotApi /// /// Client providing access to the BingX spot websocket Api /// - internal partial class BingXSocketClientSpotApi : SocketApiClient, IBingXSocketClientSpotApi + internal partial class BingXSocketClientSpotApi : SocketApiClient, IBingXSocketClientSpotApi { // No HighPerf websocket subscriptions because the data is received compressed and needs to be decompressed @@ -53,7 +53,7 @@ internal BingXSocketClientSpotApi(ILogger logger, BingXSocketOptions options) : #endregion /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) + protected override BingXAuthenticationProvider CreateAuthenticationProvider(BingXCredentials credentials) => new BingXAuthenticationProvider(credentials); /// diff --git a/BingX.Net/Interfaces/Clients/IBingXRestClient.cs b/BingX.Net/Interfaces/Clients/IBingXRestClient.cs index d6789c7..a014da3 100644 --- a/BingX.Net/Interfaces/Clients/IBingXRestClient.cs +++ b/BingX.Net/Interfaces/Clients/IBingXRestClient.cs @@ -10,7 +10,7 @@ namespace BingX.Net.Interfaces.Clients /// /// Client for accessing the BingX Rest API. /// - public interface IBingXRestClient : IRestClient + public interface IBingXRestClient : IRestClient { /// /// Spot API endpoints @@ -27,17 +27,5 @@ public interface IBingXRestClient : IRestClient /// /// IBingXRestClientSubAccountApi SubAccountApi { get; } - - /// - /// Update specific options - /// - /// Options to update. Only specific options are changeable after the client has been created - void SetOptions(UpdateOptions options); - - /// - /// Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options. - /// - /// The credentials to set - void SetApiCredentials(ApiCredentials credentials); } } diff --git a/BingX.Net/Interfaces/Clients/IBingXSocketClient.cs b/BingX.Net/Interfaces/Clients/IBingXSocketClient.cs index e33ff72..97bacfd 100644 --- a/BingX.Net/Interfaces/Clients/IBingXSocketClient.cs +++ b/BingX.Net/Interfaces/Clients/IBingXSocketClient.cs @@ -9,7 +9,7 @@ namespace BingX.Net.Interfaces.Clients /// /// Client for accessing the BingX websocket API /// - public interface IBingXSocketClient : ISocketClient + public interface IBingXSocketClient : ISocketClient { /// /// Spot streams @@ -21,17 +21,5 @@ public interface IBingXSocketClient : ISocketClient /// /// IBingXSocketClientPerpetualFuturesApi PerpetualFuturesApi { get; } - - /// - /// Update specific options - /// - /// Options to update. Only specific options are changeable after the client has been created - void SetOptions(UpdateOptions options); - - /// - /// Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options. - /// - /// The credentials to set - void SetApiCredentials(ApiCredentials credentials); } } diff --git a/BingX.Net/Interfaces/Clients/IBingXUserClientProvider.cs b/BingX.Net/Interfaces/Clients/IBingXUserClientProvider.cs index a6a8ce2..b8cce88 100644 --- a/BingX.Net/Interfaces/Clients/IBingXUserClientProvider.cs +++ b/BingX.Net/Interfaces/Clients/IBingXUserClientProvider.cs @@ -14,7 +14,7 @@ public interface IBingXUserClientProvider : IExchangeService /// The identifier for the user /// The credentials for the user /// The environment to use - void InitializeUserClient(string userIdentifier, ApiCredentials credentials, BingXEnvironment? environment = null); + void InitializeUserClient(string userIdentifier, BingXCredentials credentials, BingXEnvironment? environment = null); /// /// Reset the cached clients for a user. This can be useful when a user changes API credentials. @@ -27,7 +27,7 @@ public interface IBingXUserClientProvider : IExchangeService /// The identifier for user /// The credentials for the user. Required the first time a client is requested for this user unless has been called prior for this user. /// The environment to use - IBingXRestClient GetRestClient(string userIdentifier, ApiCredentials? credentials = null, BingXEnvironment? environment = null); + IBingXRestClient GetRestClient(string userIdentifier, BingXCredentials? credentials = null, BingXEnvironment? environment = null); /// /// Get the Socket client for a specific user. In case the client does not exist yet it will be created and the should be provided, unless has been called prior for this user. @@ -35,6 +35,6 @@ public interface IBingXUserClientProvider : IExchangeService /// The identifier for user /// The credentials for the user. Required the first time a client is requested for this user unless has been called prior for this user. /// The environment to use - IBingXSocketClient GetSocketClient(string userIdentifier, ApiCredentials? credentials = null, BingXEnvironment? environment = null); + IBingXSocketClient GetSocketClient(string userIdentifier, BingXCredentials? credentials = null, BingXEnvironment? environment = null); } } \ No newline at end of file diff --git a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs index 1d97339..96c4990 100644 --- a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs +++ b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs @@ -7,7 +7,7 @@ namespace BingX.Net.Interfaces.Clients.PerpetualFuturesApi /// /// BingX futures API endpoints /// - public interface IBingXRestClientPerpetualFuturesApi : IRestApiClient, IDisposable + public interface IBingXRestClientPerpetualFuturesApi : IRestApiClient, IDisposable { /// /// Endpoints related to account settings, info or actions diff --git a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs index 14471f0..35bf140 100644 --- a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs +++ b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs @@ -13,7 +13,7 @@ namespace BingX.Net.Interfaces.Clients.PerpetualFuturesApi /// /// BingX futures streams /// - public interface IBingXSocketClientPerpetualFuturesApi : ISocketApiClient, IDisposable + public interface IBingXSocketClientPerpetualFuturesApi : ISocketApiClient, IDisposable { /// /// Get the shared socket subscription client. This interface is shared with other exchanges to allow for a common implementation for different exchanges. diff --git a/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs b/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs index cdd59d6..651a31b 100644 --- a/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs +++ b/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs @@ -6,7 +6,7 @@ namespace BingX.Net.Interfaces.Clients.SpotApi /// /// BingX Spot API endpoints /// - public interface IBingXRestClientSpotApi : IRestApiClient, IDisposable + public interface IBingXRestClientSpotApi : IRestApiClient, IDisposable { /// /// Endpoints related to account settings, info or actions diff --git a/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs b/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs index cfece8a..72efdc3 100644 --- a/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs +++ b/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs @@ -12,7 +12,7 @@ namespace BingX.Net.Interfaces.Clients.SpotApi /// /// BingX spot streams /// - public interface IBingXSocketClientSpotApi : ISocketApiClient, IDisposable + public interface IBingXSocketClientSpotApi : ISocketApiClient, IDisposable { /// /// Get the shared socket subscription client. This interface is shared with other exchanges to allow for a common implementation for different exchanges. diff --git a/BingX.Net/Interfaces/IBingXTrackerFactory.cs b/BingX.Net/Interfaces/IBingXTrackerFactory.cs index 9537d25..bf02874 100644 --- a/BingX.Net/Interfaces/IBingXTrackerFactory.cs +++ b/BingX.Net/Interfaces/IBingXTrackerFactory.cs @@ -18,7 +18,7 @@ public interface IBingXTrackerFactory : ITrackerFactory /// Configuration /// Credentials /// Environment - IUserSpotDataTracker CreateUserSpotDataTracker(string userIdentifier, ApiCredentials credentials, SpotUserDataTrackerConfig? config = null, BingXEnvironment? environment = null); + IUserSpotDataTracker CreateUserSpotDataTracker(string userIdentifier, BingXCredentials credentials, SpotUserDataTrackerConfig? config = null, BingXEnvironment? environment = null); /// /// Create a new spot user data tracker /// @@ -32,7 +32,7 @@ public interface IBingXTrackerFactory : ITrackerFactory /// Configuration /// Credentials /// Environment - IUserFuturesDataTracker BingXUserPerpetualFuturesDataTracker(string userIdentifier, ApiCredentials credentials, FuturesUserDataTrackerConfig? config = null, BingXEnvironment? environment = null); + IUserFuturesDataTracker BingXUserPerpetualFuturesDataTracker(string userIdentifier, BingXCredentials credentials, FuturesUserDataTrackerConfig? config = null, BingXEnvironment? environment = null); /// /// Create a new futures user data tracker /// diff --git a/BingX.Net/Objects/Options/BingXOptions.cs b/BingX.Net/Objects/Options/BingXOptions.cs index a2c9195..89bf8c1 100644 --- a/BingX.Net/Objects/Options/BingXOptions.cs +++ b/BingX.Net/Objects/Options/BingXOptions.cs @@ -6,7 +6,7 @@ namespace BingX.Net.Objects.Options /// /// BingX services options /// - public class BingXOptions : LibraryOptions + public class BingXOptions : LibraryOptions { } } diff --git a/BingX.Net/Objects/Options/BingXRestOptions.cs b/BingX.Net/Objects/Options/BingXRestOptions.cs index 718d0c3..8087135 100644 --- a/BingX.Net/Objects/Options/BingXRestOptions.cs +++ b/BingX.Net/Objects/Options/BingXRestOptions.cs @@ -6,7 +6,7 @@ namespace BingX.Net.Objects.Options /// /// Options for the BingXRestClient /// - public class BingXRestOptions : RestExchangeOptions + public class BingXRestOptions : RestExchangeOptions { /// /// Default options for new clients @@ -38,14 +38,14 @@ public BingXRestOptions() /// /// Spot API options /// - public RestApiOptions SpotOptions { get; private set; } = new RestApiOptions + public RestApiOptions SpotOptions { get; private set; } = new RestApiOptions { }; /// /// Futures API options /// - public RestApiOptions FuturesOptions { get; private set; } = new RestApiOptions(); + public RestApiOptions FuturesOptions { get; private set; } = new RestApiOptions(); internal BingXRestOptions Set(BingXRestOptions targetOptions) { diff --git a/BingX.Net/Objects/Options/BingXSocketOptions.cs b/BingX.Net/Objects/Options/BingXSocketOptions.cs index 6457be6..11a4353 100644 --- a/BingX.Net/Objects/Options/BingXSocketOptions.cs +++ b/BingX.Net/Objects/Options/BingXSocketOptions.cs @@ -6,7 +6,7 @@ namespace BingX.Net.Objects.Options /// /// Options for the BingXSocketClient /// - public class BingXSocketOptions : SocketExchangeOptions + public class BingXSocketOptions : SocketExchangeOptions { /// /// Default options for new clients @@ -28,7 +28,7 @@ public BingXSocketOptions() /// /// Options for the Spot API /// - public SocketApiOptions SpotOptions { get; private set; } = new SocketApiOptions() + public SocketApiOptions SpotOptions { get; private set; } = new SocketApiOptions() { SocketNoDataTimeout = TimeSpan.FromSeconds(40) // Ping message is sent every 30 seconds }; @@ -36,7 +36,7 @@ public BingXSocketOptions() /// /// Options for the Futures API /// - public SocketApiOptions FuturesOptions { get; private set; } = new SocketApiOptions() + public SocketApiOptions FuturesOptions { get; private set; } = new SocketApiOptions() { MaxSocketConnections = 60, SocketNoDataTimeout = TimeSpan.FromSeconds(40) // Ping message is sent every 30 seconds From cf213b2c886c5c50aacbb95829a756da9b7abed7 Mon Sep 17 00:00:00 2001 From: JKorf Date: Sun, 15 Mar 2026 21:47:56 +0100 Subject: [PATCH 2/9] wip --- BingX.Net/BingXAuthenticationProvider.cs | 2 +- BingX.Net/BingXCredentials.cs | 26 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/BingX.Net/BingXAuthenticationProvider.cs b/BingX.Net/BingXAuthenticationProvider.cs index 87e5e61..2f4ef1b 100644 --- a/BingX.Net/BingXAuthenticationProvider.cs +++ b/BingX.Net/BingXAuthenticationProvider.cs @@ -20,7 +20,7 @@ public BingXAuthenticationProvider(BingXCredentials credentials) : base(credenti public override void ProcessRequest(RestApiClient apiClient, RestRequestConfiguration request) { request.Headers ??= new Dictionary(); - request.Headers.Add("X-BX-APIKEY", Credential.PublicKey); + request.Headers.Add("X-BX-APIKEY", Credential.Key); if (!request.Authenticated) return; diff --git a/BingX.Net/BingXCredentials.cs b/BingX.Net/BingXCredentials.cs index 3ef809d..a02d6a0 100644 --- a/BingX.Net/BingXCredentials.cs +++ b/BingX.Net/BingXCredentials.cs @@ -1,18 +1,34 @@ using CryptoExchange.Net.Authentication; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BingX.Net { + /// + /// BingX API credentials + /// public class BingXCredentials : ApiCredentials { + /// + /// + [Obsolete("Parameterless constructor is only for deserialization purposes and should not be used directly. Use parameterized constructor instead.")] + public BingXCredentials() { } + + /// + /// Create credentials using an HMAC key and secret. + /// + /// API key + /// API secret public BingXCredentials(string apiKey, string secret) : this(new HMACCredential(apiKey, secret)) { } + /// + /// Create credentials using HMAC credentials + /// + /// HMAC credentials public BingXCredentials(HMACCredential credential) : base(credential) { } - public override ApiCredentials Copy() => new BingXCredentials(Hmac!); + /// +#pragma warning disable CS0618 // Type or member is obsolete + public override ApiCredentials Copy() => new BingXCredentials { CredentialPairs = CredentialPairs }; +#pragma warning restore CS0618 // Type or member is obsolete } } From 9a44e0031ef7ff841198fe2439e70825dfab0326 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Mon, 16 Mar 2026 13:57:22 +0100 Subject: [PATCH 3/9] wip --- BingX.Net.UnitTests/BingXRestClientTests.cs | 12 ++++++------ BingX.Net/BingX.Net.csproj | 1 + .../ExtensionMethods/ServiceCollectionExtensions.cs | 13 ++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/BingX.Net.UnitTests/BingXRestClientTests.cs b/BingX.Net.UnitTests/BingXRestClientTests.cs index c5c7efb..ce65103 100644 --- a/BingX.Net.UnitTests/BingXRestClientTests.cs +++ b/BingX.Net.UnitTests/BingXRestClientTests.cs @@ -119,10 +119,10 @@ public void TestConstructorConfiguration() var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "ApiCredentials:Key", "123" }, - { "ApiCredentials:Secret", "456" }, - { "Socket:ApiCredentials:Key", "456" }, - { "Socket:ApiCredentials:Secret", "789" }, + { "ApiCredentials:Hmac:Key", "123" }, + { "ApiCredentials:Hmac:Secret", "456" }, + { "Socket:ApiCredentials:Hmac:Key", "456" }, + { "Socket:ApiCredentials:Hmac:Secret", "789" }, { "Rest:OutputOriginalData", "true" }, { "Socket:OutputOriginalData", "false" }, { "Rest:Proxy:Host", "host" }, @@ -140,8 +140,8 @@ public void TestConstructorConfiguration() Assert.That(((BaseApiClient)restClient.SpotApi).OutputOriginalData, Is.True); Assert.That(((BaseApiClient)socketClient.SpotApi).OutputOriginalData, Is.False); - Assert.That(((BingXRestClientSpotApi)restClient.SpotApi).AuthenticationProvider.PublicKey, Is.EqualTo("123")); - Assert.That(((BingXSocketClientSpotApi)socketClient.SpotApi).AuthenticationProvider.PublicKey, 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")); diff --git a/BingX.Net/BingX.Net.csproj b/BingX.Net/BingX.Net.csproj index 3785f35..6ce34f2 100644 --- a/BingX.Net/BingX.Net.csproj +++ b/BingX.Net/BingX.Net.csproj @@ -23,6 +23,7 @@ true true https://github.com/JKorf/BingX.Net?tab=readme-ov-file#release-notes + $(NoWarn);SYSLIB1100;SYSLIB1101 true diff --git a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs index ebf3243..364e6d5 100644 --- a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -36,11 +36,22 @@ public static IServiceCollection AddBingX( // Reset environment so we know if they're overridden options.Rest.Environment = null!; options.Socket.Environment = null!; - configuration.Bind(options); + try + { + configuration.Bind(options); + } + catch (InvalidOperationException ex) + { + throw new InvalidOperationException("Invalid configuration provided", ex); + } if (options.Rest == null || options.Socket == null) throw new ArgumentException("Options null"); + LibraryHelpers.ValidateCredentials(options.ApiCredentials); + LibraryHelpers.ValidateCredentials(options.Rest.ApiCredentials); + LibraryHelpers.ValidateCredentials(options.Socket.ApiCredentials); + var restEnvName = options.Rest.Environment?.Name ?? options.Environment?.Name ?? BingXEnvironment.Live.Name; var socketEnvName = options.Socket.Environment?.Name ?? options.Environment?.Name ?? BingXEnvironment.Live.Name; options.Rest.Environment = BingXEnvironment.GetEnvironmentByName(restEnvName) ?? options.Rest.Environment!; From 76d55832351c98f3687b16add995cc3150ea1c02 Mon Sep 17 00:00:00 2001 From: JKorf Date: Mon, 16 Mar 2026 22:00:21 +0100 Subject: [PATCH 4/9] wip --- BingX.Net.UnitTests/BingXRestClientTests.cs | 8 ++++---- BingX.Net/BingXAuthenticationProvider.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BingX.Net.UnitTests/BingXRestClientTests.cs b/BingX.Net.UnitTests/BingXRestClientTests.cs index ce65103..52abe50 100644 --- a/BingX.Net.UnitTests/BingXRestClientTests.cs +++ b/BingX.Net.UnitTests/BingXRestClientTests.cs @@ -119,10 +119,10 @@ public void TestConstructorConfiguration() var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "ApiCredentials:Hmac:Key", "123" }, - { "ApiCredentials:Hmac:Secret", "456" }, - { "Socket:ApiCredentials:Hmac:Key", "456" }, - { "Socket:ApiCredentials:Hmac:Secret", "789" }, + { "ApiCredentials:HMAC:Key", "123" }, + { "ApiCredentials:HMAC:Secret", "456" }, + { "Socket:ApiCredentials:HMAC:Key", "456" }, + { "Socket:ApiCredentials:HMAC:Secret", "789" }, { "Rest:OutputOriginalData", "true" }, { "Socket:OutputOriginalData", "false" }, { "Rest:Proxy:Host", "host" }, diff --git a/BingX.Net/BingXAuthenticationProvider.cs b/BingX.Net/BingXAuthenticationProvider.cs index 2f4ef1b..a14fe44 100644 --- a/BingX.Net/BingXAuthenticationProvider.cs +++ b/BingX.Net/BingXAuthenticationProvider.cs @@ -12,7 +12,7 @@ namespace BingX.Net { internal class BingXAuthenticationProvider : AuthenticationProvider { - public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.Hmac]; + public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.HMAC]; public BingXAuthenticationProvider(BingXCredentials credentials) : base(credentials) { } From 25e104eda3c612fdcdd42992a93fefe5ff46e959 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Tue, 17 Mar 2026 09:57:01 +0100 Subject: [PATCH 5/9] wip --- ...ingXRestClientPerpetualFuturesApiShared.cs | 11 +++++-- ...gXSocketClientPerpetualFuturesApiShared.cs | 15 +++++++++- .../SpotApi/BingXRestClientSpotApiShared.cs | 29 +++++++++++++++---- .../SpotApi/BingXSocketClientSpotApiShared.cs | 16 ++++++++-- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/BingX.Net/Clients/PerpetualFuturesApi/BingXRestClientPerpetualFuturesApiShared.cs b/BingX.Net/Clients/PerpetualFuturesApi/BingXRestClientPerpetualFuturesApiShared.cs index 34b7ea7..bc7e2cd 100644 --- a/BingX.Net/Clients/PerpetualFuturesApi/BingXRestClientPerpetualFuturesApiShared.cs +++ b/BingX.Net/Clients/PerpetualFuturesApi/BingXRestClientPerpetualFuturesApiShared.cs @@ -837,9 +837,14 @@ async Task> IFuturesOrderRestClient.ClosePositionAsy private SharedOrderStatus ParseOrderStatus(OrderStatus status) { - if (status == OrderStatus.New || status == OrderStatus.PartiallyFilled || status == OrderStatus.Pending) return SharedOrderStatus.Open; - if (status == OrderStatus.Canceled || status == OrderStatus.Failed) return SharedOrderStatus.Canceled; - return SharedOrderStatus.Filled; + if (status == Enums.OrderStatus.Canceled || status == OrderStatus.Failed) + return SharedOrderStatus.Canceled; + if (status == Enums.OrderStatus.New || status == Enums.OrderStatus.Pending || status == Enums.OrderStatus.PartiallyFilled) + return SharedOrderStatus.Open; + if (status == OrderStatus.Filled) + return SharedOrderStatus.Filled; + + return SharedOrderStatus.Unknown; } private SharedOrderType ParseOrderType(FuturesOrderType type) diff --git a/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApiShared.cs b/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApiShared.cs index bae8abf..b359fc4 100644 --- a/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApiShared.cs +++ b/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApiShared.cs @@ -1,3 +1,4 @@ +using BingX.Net.Enums; using BingX.Net.Interfaces.Clients.SpotApi; using BingX.Net.Objects.Models; using CryptoExchange.Net; @@ -152,7 +153,7 @@ async Task> IFuturesOrderSocketClient.Subscri update.Data.OrderId.ToString(), ParseOrderType(update.Data), update.Data.Side == Enums.OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell, - update.Data.Status == Enums.OrderStatus.Canceled ? SharedOrderStatus.Canceled : (update.Data.Status == Enums.OrderStatus.New || update.Data.Status == Enums.OrderStatus.PartiallyFilled) ? SharedOrderStatus.Open : SharedOrderStatus.Filled, + ParseOrderStatus(update.Data.Status), update.Data.UpdateTime) { ClientOrderId = update.Data.ClientOrderId, @@ -176,6 +177,18 @@ async Task> IFuturesOrderSocketClient.Subscri return new ExchangeResult(Exchange, result); } + private SharedOrderStatus ParseOrderStatus(OrderStatus status) + { + if (status == Enums.OrderStatus.Canceled || status == OrderStatus.Failed) + return SharedOrderStatus.Canceled; + if (status == Enums.OrderStatus.New || status == Enums.OrderStatus.Pending || status == Enums.OrderStatus.PartiallyFilled) + return SharedOrderStatus.Open; + if (status == OrderStatus.Filled) + return SharedOrderStatus.Filled; + + return SharedOrderStatus.Unknown; + } + private SharedOrderType ParseOrderType(BingXFuturesOrderUpdate data) { if (data.Type == Enums.FuturesOrderType.Market diff --git a/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiShared.cs b/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiShared.cs index 58abbac..3104f88 100644 --- a/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiShared.cs +++ b/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiShared.cs @@ -539,9 +539,14 @@ async Task> ISpotOrderRestClient.CancelSpotOrderAsyn private SharedOrderStatus ParseOrderStatus(OrderStatus status) { - if (status == OrderStatus.Pending || status == OrderStatus.PartiallyFilled || status == OrderStatus.New) return SharedOrderStatus.Open; - if (status == OrderStatus.Canceled || status == OrderStatus.Failed) return SharedOrderStatus.Canceled; - return SharedOrderStatus.Filled; + if (status == Enums.OrderStatus.Canceled || status == OrderStatus.Failed) + return SharedOrderStatus.Canceled; + if (status == Enums.OrderStatus.New || status == Enums.OrderStatus.Pending || status == Enums.OrderStatus.PartiallyFilled) + return SharedOrderStatus.Open; + if (status == OrderStatus.Filled) + return SharedOrderStatus.Filled; + + return SharedOrderStatus.Unknown; } private SharedOrderType ParseOrderType(OrderType type, TimeInForce? tif) @@ -741,7 +746,8 @@ async Task> IDepositRestClient.GetDepositsAsy x.Quantity, x.Status == DepositStatus.Completed, x.InsertTime, - x.Status == DepositStatus.Completed ? SharedTransferStatus.Completed : SharedTransferStatus.InProgress) + ParseTransferStatus(x.Status) + ) { Confirmations = x.ConfirmedTimes.Contains("/") ? int.Parse(x.ConfirmedTimes.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[0]) : null, Tag = x.AddressTag, @@ -751,6 +757,16 @@ async Task> IDepositRestClient.GetDepositsAsy .ToArray(), nextPageRequest); } + private SharedTransferStatus ParseTransferStatus(DepositStatus status) + { + if (status == DepositStatus.Completed) + return SharedTransferStatus.Completed; + if (status == DepositStatus.InProgress || status == DepositStatus.ChainUploaded) + return SharedTransferStatus.InProgress; + + return SharedTransferStatus.Unknown; + } + #endregion #region Order Book client @@ -992,7 +1008,10 @@ private SharedTriggerOrderStatus ParseTriggerStatus(BingXOrderDetails data) if (data.Status == OrderStatus.Canceled || data.Status == OrderStatus.Failed) return SharedTriggerOrderStatus.CanceledOrRejected; - return SharedTriggerOrderStatus.Active; + if (data.Status == OrderStatus.New || data.Status == OrderStatus.PartiallyFilled) + return SharedTriggerOrderStatus.Active; + + return SharedTriggerOrderStatus.Unknown; } EndpointOptions ISpotTriggerOrderRestClient.CancelSpotTriggerOrderOptions { get; } = new EndpointOptions(true); diff --git a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApiShared.cs b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApiShared.cs index 4566c79..543281f 100644 --- a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApiShared.cs +++ b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApiShared.cs @@ -143,8 +143,8 @@ async Task> ISpotOrderSocketClient.SubscribeT update.Data.Symbol, update.Data.OrderId.ToString(), ParseOrderType(update.Data.Type), - update.Data.Side == Enums.OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell, - update.Data.Status == Enums.OrderStatus.Canceled ? SharedOrderStatus.Canceled : (update.Data.Status == Enums.OrderStatus.New || update.Data.Status == Enums.OrderStatus.Pending || update.Data.Status == Enums.OrderStatus.PartiallyFilled) ? SharedOrderStatus.Open : SharedOrderStatus.Filled, + update.Data.Side == Enums.OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell, + ParseOrderStatus(update.Data.Status), update.Data.CreateTime) { ClientOrderId = update.Data.ClientOrderId, @@ -176,6 +176,18 @@ async Task> ISpotOrderSocketClient.SubscribeT return new ExchangeResult(Exchange, result); } + private SharedOrderStatus ParseOrderStatus(OrderStatus status) + { + if (status == Enums.OrderStatus.Canceled || status == OrderStatus.Failed) + return SharedOrderStatus.Canceled; + if (status == Enums.OrderStatus.New || status == Enums.OrderStatus.Pending || status == Enums.OrderStatus.PartiallyFilled) + return SharedOrderStatus.Open; + if (status == OrderStatus.Filled) + return SharedOrderStatus.Filled; + + return SharedOrderStatus.Unknown; + } + private SharedOrderType ParseOrderType(OrderType type) { if (type == OrderType.Market || type == OrderType.StopMarket) From 1dc52dc93e4920c77c0612c6e4a744e5bba2fa96 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Wed, 18 Mar 2026 16:15:50 +0100 Subject: [PATCH 6/9] wip --- BingX.Net.UnitTests/BingXRestClientTests.cs | 8 +++--- .../BingXRestIntegrationTests.cs | 1 + .../BingXSocketIntegrationTests.cs | 1 + .../SocketSubscriptionTests.cs | 1 + BingX.Net/BingXAuthenticationProvider.cs | 5 ++-- BingX.Net/BingXCredentials.cs | 27 +++++-------------- BingX.Net/Clients/BingXRestClientApi.cs | 2 +- .../ServiceCollectionExtensions.cs | 3 ++- .../Apis/BingXRestClientSubAccountApi.cs | 3 ++- .../IBingXRestClientPerpetualFuturesApi.cs | 1 + .../IBingXSocketClientPerpetualFuturesApi.cs | 1 + .../SpotApi/IBingXRestClientSpotApi.cs | 3 ++- .../SpotApi/IBingXSocketClientSpotApi.cs | 1 + BingX.Net/Objects/Options/BingXRestOptions.cs | 7 ++--- .../Objects/Options/BingXSocketOptions.cs | 7 ++--- 15 files changed, 33 insertions(+), 38 deletions(-) diff --git a/BingX.Net.UnitTests/BingXRestClientTests.cs b/BingX.Net.UnitTests/BingXRestClientTests.cs index 52abe50..0a605f7 100644 --- a/BingX.Net.UnitTests/BingXRestClientTests.cs +++ b/BingX.Net.UnitTests/BingXRestClientTests.cs @@ -119,10 +119,10 @@ public void TestConstructorConfiguration() var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { - { "ApiCredentials:HMAC:Key", "123" }, - { "ApiCredentials:HMAC:Secret", "456" }, - { "Socket:ApiCredentials:HMAC:Key", "456" }, - { "Socket:ApiCredentials:HMAC:Secret", "789" }, + { "ApiCredentials:Key", "123" }, + { "ApiCredentials:Secret", "456" }, + { "Socket:ApiCredentials:Key", "456" }, + { "Socket:ApiCredentials:Secret", "789" }, { "Rest:OutputOriginalData", "true" }, { "Socket:OutputOriginalData", "false" }, { "Rest:Proxy:Host", "host" }, diff --git a/BingX.Net.UnitTests/BingXRestIntegrationTests.cs b/BingX.Net.UnitTests/BingXRestIntegrationTests.cs index b951c70..9186468 100644 --- a/BingX.Net.UnitTests/BingXRestIntegrationTests.cs +++ b/BingX.Net.UnitTests/BingXRestIntegrationTests.cs @@ -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; diff --git a/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs b/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs index 9296226..c26a527 100644 --- a/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs +++ b/BingX.Net.UnitTests/BingXSocketIntegrationTests.cs @@ -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; diff --git a/BingX.Net.UnitTests/SocketSubscriptionTests.cs b/BingX.Net.UnitTests/SocketSubscriptionTests.cs index ac99309..f66a644 100644 --- a/BingX.Net.UnitTests/SocketSubscriptionTests.cs +++ b/BingX.Net.UnitTests/SocketSubscriptionTests.cs @@ -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; diff --git a/BingX.Net/BingXAuthenticationProvider.cs b/BingX.Net/BingXAuthenticationProvider.cs index a14fe44..e4d7a4f 100644 --- a/BingX.Net/BingXAuthenticationProvider.cs +++ b/BingX.Net/BingXAuthenticationProvider.cs @@ -10,10 +10,9 @@ namespace BingX.Net { - internal class BingXAuthenticationProvider : AuthenticationProvider + internal class BingXAuthenticationProvider : AuthenticationProvider { - public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.HMAC]; - public BingXAuthenticationProvider(BingXCredentials credentials) : base(credentials) + public BingXAuthenticationProvider(BingXCredentials credentials) : base(credentials, credentials) { } diff --git a/BingX.Net/BingXCredentials.cs b/BingX.Net/BingXCredentials.cs index a02d6a0..cbdec0b 100644 --- a/BingX.Net/BingXCredentials.cs +++ b/BingX.Net/BingXCredentials.cs @@ -1,34 +1,19 @@ using CryptoExchange.Net.Authentication; -using System; namespace BingX.Net { /// /// BingX API credentials /// - public class BingXCredentials : ApiCredentials + public class BingXCredentials : HMACCredential { /// + /// Create new credentials providing only credentials in HMAC format /// - [Obsolete("Parameterless constructor is only for deserialization purposes and should not be used directly. Use parameterized constructor instead.")] - public BingXCredentials() { } - - /// - /// Create credentials using an HMAC key and secret. - /// - /// API key + /// API key /// API secret - public BingXCredentials(string apiKey, string secret) : this(new HMACCredential(apiKey, secret)) { } - - /// - /// Create credentials using HMAC credentials - /// - /// HMAC credentials - public BingXCredentials(HMACCredential credential) : base(credential) { } - - /// -#pragma warning disable CS0618 // Type or member is obsolete - public override ApiCredentials Copy() => new BingXCredentials { CredentialPairs = CredentialPairs }; -#pragma warning restore CS0618 // Type or member is obsolete + public BingXCredentials(string key, string secret) : base(key, secret) + { + } } } diff --git a/BingX.Net/Clients/BingXRestClientApi.cs b/BingX.Net/Clients/BingXRestClientApi.cs index 2e04b64..1d54072 100644 --- a/BingX.Net/Clients/BingXRestClientApi.cs +++ b/BingX.Net/Clients/BingXRestClientApi.cs @@ -35,7 +35,7 @@ internal abstract class BingXRestClientApi : RestApiClient apiOptions) + internal BingXRestClientApi(ILogger logger, HttpClient? httpClient, BingXRestOptions options, RestApiOptions apiOptions) : base(logger, httpClient, options.Environment.RestClientAddress, options, apiOptions) { ParameterPositions[HttpMethod.Delete] = HttpMethodParameterPosition.InUri; diff --git a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs index 364e6d5..59a2b98 100644 --- a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -23,7 +23,8 @@ namespace Microsoft.Extensions.DependencyInjection public static class ServiceCollectionExtensions { /// - /// Add services such as the IBingXRestClient and IBingXSocketClient. Configures the services based on the provided configuration. + /// Add services such as the IBingXRestClient and IBingXSocketClient. Configures the services based on the provided configuration.
+ /// See for an example of how to set up the configuration. ///
/// The service collection /// The configuration(section) containing the options diff --git a/BingX.Net/Interfaces/Clients/Apis/BingXRestClientSubAccountApi.cs b/BingX.Net/Interfaces/Clients/Apis/BingXRestClientSubAccountApi.cs index ea4bd11..14b3cce 100644 --- a/BingX.Net/Interfaces/Clients/Apis/BingXRestClientSubAccountApi.cs +++ b/BingX.Net/Interfaces/Clients/Apis/BingXRestClientSubAccountApi.cs @@ -4,13 +4,14 @@ using CryptoExchange.Net.Objects; using BingX.Net.Objects.Models; using CryptoExchange.Net.Interfaces.Clients; +using CryptoExchange.Net.Authentication; namespace BingX.Net.Interfaces.Clients.Apis { /// /// BingX sub account API endpoints /// - public interface IBingXRestClientSubAccountApi: IRestApiClient, IDisposable + public interface IBingXRestClientSubAccountApi: IRestApiClient, IDisposable { /// /// Get the permissions of the API key diff --git a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs index 96c4990..bb2bd82 100644 --- a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs +++ b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXRestClientPerpetualFuturesApi.cs @@ -1,4 +1,5 @@ using BingX.Net.Interfaces.Clients.SpotApi; +using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces.Clients; using System; diff --git a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs index 35bf140..5b3fe84 100644 --- a/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs +++ b/BingX.Net/Interfaces/Clients/PerpetualFuturesApi/IBingXSocketClientPerpetualFuturesApi.cs @@ -4,6 +4,7 @@ using BingX.Net.Enums; using BingX.Net.Interfaces.Clients.SpotApi; using BingX.Net.Objects.Models; +using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces.Clients; using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; diff --git a/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs b/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs index 651a31b..53e45ae 100644 --- a/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs +++ b/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApi.cs @@ -1,4 +1,5 @@ -using CryptoExchange.Net.Interfaces.Clients; +using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Interfaces.Clients; using System; namespace BingX.Net.Interfaces.Clients.SpotApi diff --git a/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs b/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs index 72efdc3..c5a830a 100644 --- a/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs +++ b/BingX.Net/Interfaces/Clients/SpotApi/IBingXSocketClientSpotApi.cs @@ -6,6 +6,7 @@ using BingX.Net.Enums; using BingX.Net.Objects.Models; using CryptoExchange.Net.Interfaces.Clients; +using CryptoExchange.Net.Authentication; namespace BingX.Net.Interfaces.Clients.SpotApi { diff --git a/BingX.Net/Objects/Options/BingXRestOptions.cs b/BingX.Net/Objects/Options/BingXRestOptions.cs index 8087135..09b1f89 100644 --- a/BingX.Net/Objects/Options/BingXRestOptions.cs +++ b/BingX.Net/Objects/Options/BingXRestOptions.cs @@ -1,4 +1,5 @@ -using CryptoExchange.Net.Objects.Options; +using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Objects.Options; using System; namespace BingX.Net.Objects.Options @@ -38,14 +39,14 @@ public BingXRestOptions() /// /// Spot API options /// - public RestApiOptions SpotOptions { get; private set; } = new RestApiOptions + public RestApiOptions SpotOptions { get; private set; } = new RestApiOptions { }; /// /// Futures API options /// - public RestApiOptions FuturesOptions { get; private set; } = new RestApiOptions(); + public RestApiOptions FuturesOptions { get; private set; } = new RestApiOptions(); internal BingXRestOptions Set(BingXRestOptions targetOptions) { diff --git a/BingX.Net/Objects/Options/BingXSocketOptions.cs b/BingX.Net/Objects/Options/BingXSocketOptions.cs index 11a4353..75e9645 100644 --- a/BingX.Net/Objects/Options/BingXSocketOptions.cs +++ b/BingX.Net/Objects/Options/BingXSocketOptions.cs @@ -1,4 +1,5 @@ -using CryptoExchange.Net.Objects.Options; +using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Objects.Options; using System; namespace BingX.Net.Objects.Options @@ -28,7 +29,7 @@ public BingXSocketOptions() /// /// Options for the Spot API /// - public SocketApiOptions SpotOptions { get; private set; } = new SocketApiOptions() + public SocketApiOptions SpotOptions { get; private set; } = new SocketApiOptions() { SocketNoDataTimeout = TimeSpan.FromSeconds(40) // Ping message is sent every 30 seconds }; @@ -36,7 +37,7 @@ public BingXSocketOptions() /// /// Options for the Futures API /// - public SocketApiOptions FuturesOptions { get; private set; } = new SocketApiOptions() + public SocketApiOptions FuturesOptions { get; private set; } = new SocketApiOptions() { MaxSocketConnections = 60, SocketNoDataTimeout = TimeSpan.FromSeconds(40) // Ping message is sent every 30 seconds From e820b0c6d3b6c48940ce885be745dd060c1bec88 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Thu, 19 Mar 2026 14:00:40 +0100 Subject: [PATCH 7/9] wip --- BingX.Net/BingXCredentials.cs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/BingX.Net/BingXCredentials.cs b/BingX.Net/BingXCredentials.cs index cbdec0b..ecaefb8 100644 --- a/BingX.Net/BingXCredentials.cs +++ b/BingX.Net/BingXCredentials.cs @@ -1,4 +1,6 @@ using CryptoExchange.Net.Authentication; +using System; +using System.Net; namespace BingX.Net { @@ -8,12 +10,39 @@ namespace BingX.Net public class BingXCredentials : HMACCredential { /// - /// Create new credentials providing only credentials in HMAC format + /// Create new credentials + /// + public BingXCredentials() { } + + /// + /// Create new credentials providing credentials in HMAC format /// /// API key /// API secret public BingXCredentials(string key, string secret) : base(key, secret) { } + + /// + /// Create new credentials providing HMAC credentials + /// + /// Credentials + public BingXCredentials(HMACCredential credential) : base(credential.Key, credential.Secret) + { + } + + /// + /// Specify the HMAC credentials + /// + /// API key + /// API secret + public BingXCredentials WithHMAC(string key, string secret) + { + if (!string.IsNullOrEmpty(Key)) throw new InvalidOperationException("Credentials already set"); + + Key = key; + Secret = secret; + return this; + } } } From 4720f38b1b62832185ebea860a42828c00de828a Mon Sep 17 00:00:00 2001 From: Jkorf Date: Thu, 19 Mar 2026 16:34:44 +0100 Subject: [PATCH 8/9] wip --- BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs index 59a2b98..aee62a7 100644 --- a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -49,10 +49,6 @@ public static IServiceCollection AddBingX( if (options.Rest == null || options.Socket == null) throw new ArgumentException("Options null"); - LibraryHelpers.ValidateCredentials(options.ApiCredentials); - LibraryHelpers.ValidateCredentials(options.Rest.ApiCredentials); - LibraryHelpers.ValidateCredentials(options.Socket.ApiCredentials); - var restEnvName = options.Rest.Environment?.Name ?? options.Environment?.Name ?? BingXEnvironment.Live.Name; var socketEnvName = options.Socket.Environment?.Name ?? options.Environment?.Name ?? BingXEnvironment.Live.Name; options.Rest.Environment = BingXEnvironment.GetEnvironmentByName(restEnvName) ?? options.Rest.Environment!; From 89634235f483204d34c46c73800b3203308ab256 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Fri, 20 Mar 2026 13:57:30 +0100 Subject: [PATCH 9/9] wip --- .../ServiceCollectionExtensions.cs | 2 +- example-config.json | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 example-config.json diff --git a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs index aee62a7..082deb9 100644 --- a/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/BingX.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -24,7 +24,7 @@ public static class ServiceCollectionExtensions { /// /// Add services such as the IBingXRestClient and IBingXSocketClient. Configures the services based on the provided configuration.
- /// See for an example of how to set up the configuration. + /// See for an example of how to set up the configuration. ///
/// The service collection /// The configuration(section) containing the options diff --git a/example-config.json b/example-config.json new file mode 100644 index 0000000..842e443 --- /dev/null +++ b/example-config.json @@ -0,0 +1,31 @@ +{ + // Options section, select this section during DI registration using Configuration.GetSection("BingX") + "BingX": { + // API credentials for both REST and Websocket client + "ApiCredentials": { + "Key": "APIKEY", + "Secret": "APISECRET", + }, + // Set the environment by name + "Environment": { + "name": "live" + }, + // REST client options + "Rest": { + "RequestTimeout": "00:00:20", + "CachingEnabled": true, + "OutputOriginalData": true, + "Proxy": { + "Host": "https://127.0.0.1", + "Port": 8080, + "Login": "User", + "Password": "Pass" + } + }, + // Socket client options + "Socket": { + "RequestTimeout": "00:00:05", + "SocketSubscriptionsCombineTarget": 15 + } + } +} \ No newline at end of file