diff --git a/BingX.Net/BingX.Net.csproj b/BingX.Net/BingX.Net.csproj index 1c255a3..5a7963a 100644 --- a/BingX.Net/BingX.Net.csproj +++ b/BingX.Net/BingX.Net.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;netstandard2.1 10.0 @@ -48,7 +48,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BingX.Net/BingXAuthenticationProvider.cs b/BingX.Net/BingXAuthenticationProvider.cs index c5a20d0..7f257e4 100644 --- a/BingX.Net/BingXAuthenticationProvider.cs +++ b/BingX.Net/BingXAuthenticationProvider.cs @@ -18,14 +18,24 @@ public BingXAuthenticationProvider(ApiCredentials credentials) : base(credential { } - public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, IDictionary uriParams, IDictionary bodyParams, Dictionary headers, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, RequestBodyFormat bodyFormat) + public override void AuthenticateRequest( + RestApiClient apiClient, + Uri uri, + HttpMethod method, + IDictionary uriParameters, + IDictionary bodyParameters, + Dictionary headers, + bool auth, + ArrayParametersSerialization arraySerialization, + HttpMethodParameterPosition parameterPosition, + RequestBodyFormat requestBodyFormat) { headers.Add("X-BX-APIKEY", GetApiKey()); if (!auth) return; - var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParams : bodyParams; + var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParameters : bodyParameters; var timestamp = DateTimeConverter.ConvertToMilliseconds(GetTimestamp(apiClient)).Value; parameters.Add("timestamp", timestamp); if (!parameters.ContainsKey("recvWindow")) diff --git a/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs b/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs index 08a9194..dca5882 100644 --- a/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs +++ b/BingX.Net/Clients/PerpetualFuturesApi/BingXSocketClientPerpetualFuturesApi.cs @@ -18,6 +18,9 @@ using CryptoExchange.Net.Converters.SystemTextJson; using System.Net.WebSockets; using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices.ComTypes; +using System.Linq; namespace BingX.Net.Clients.PerpetualFuturesApi { @@ -59,7 +62,8 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden /// public async Task> SubscribeToTradeUpdatesAsync(string symbol, Action>> onMessage, CancellationToken ct = default) { - var subscription = new BingXSubscription>(_logger, symbol + "@trade", symbol + "@trade", onMessage, false); + var stream = symbol + "@trade"; + var subscription = new BingXSubscription>(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.First().Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -70,7 +74,7 @@ public async Task> SubscribeToPartialOrderBookUpd updateInterval.ValidateIntValues(nameof(updateInterval),100, 200, 500, 1000); var stream = symbol + $"@depth{depth}@{updateInterval}ms"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -81,7 +85,7 @@ public async Task> SubscribeToPartialOrderBookUpd updateInterval.ValidateIntValues(nameof(updateInterval), 100, 200, 500, 1000); var stream = $"all@depth{depth}@{updateInterval}ms"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol!)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -89,7 +93,7 @@ public async Task> SubscribeToPartialOrderBookUpd public async Task> SubscribeToKlineUpdatesAsync(KlineInterval interval, Action>> onMessage, CancellationToken ct = default) { var stream = "all@kline_" + EnumConverter.GetString(interval); - var subscription = new BingXSubscription>(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription>(_logger, stream, stream, x => onMessage(x.WithStreamId(stream)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -97,21 +101,23 @@ public async Task> SubscribeToKlineUpdatesAsync(K public async Task> SubscribeToKlineUpdatesAsync(string symbol, KlineInterval interval, Action>> onMessage, CancellationToken ct = default) { var stream = symbol + "@kline_" + EnumConverter.GetString(interval); - var subscription = new BingXSubscription>(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription>(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } /// public async Task> SubscribeToTickerUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { - var subscription = new BingXSubscription(_logger, symbol + "@ticker", symbol + "@ticker", onMessage, false); + var stream = symbol + "@ticker"; + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } /// public async Task> SubscribeToTickerUpdatesAsync(Action> onMessage, CancellationToken ct = default) { - var subscription = new BingXSubscription(_logger, "all@ticker", "all@ticker", onMessage, false); + var stream = "all@ticker"; + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -119,7 +125,7 @@ public async Task> SubscribeToTickerUpdatesAsync( public async Task> SubscribeToPriceUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { var stream = symbol + "@lastPrice"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -127,7 +133,7 @@ public async Task> SubscribeToPriceUpdatesAsync(s public async Task> SubscribeToMarkPriceUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { var stream = symbol + "@markPrice"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } @@ -135,7 +141,7 @@ public async Task> SubscribeToMarkPriceUpdatesAsy public async Task> SubscribeToBookPriceUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { var stream = symbol + "@bookTicker"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("swap-market"), subscription, ct).ConfigureAwait(false); } diff --git a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs index 1ce28f3..83fe4b4 100644 --- a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs +++ b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs @@ -18,6 +18,7 @@ using CryptoExchange.Net.Clients; using CryptoExchange.Net.Converters.SystemTextJson; using BingX.Net.Enums; +using System.Runtime.InteropServices.ComTypes; namespace BingX.Net.Clients.SpotApi { @@ -62,7 +63,8 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden /// public async Task> SubscribeToTradeUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { - var subscription = new BingXSubscription(_logger, symbol + "@trade", symbol + "@trade", onMessage, false); + var stream = symbol + "@trade"; + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market"), subscription, ct).ConfigureAwait(false); } @@ -70,7 +72,7 @@ public async Task> SubscribeToTradeUpdatesAsync(s public async Task> SubscribeToKlineUpdatesAsync(string symbol, KlineInterval interval, Action> onMessage, CancellationToken ct = default) { var stream = symbol + "@kline_" + KlineIntervalToWebsocketString(interval); - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market"), subscription, ct).ConfigureAwait(false); } @@ -80,14 +82,15 @@ public async Task> SubscribeToPartialOrderBookUpd depth.ValidateIntValues(nameof(depth), 5, 10, 20, 50, 100); var stream = symbol + "@depth" + depth; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market"), subscription, ct).ConfigureAwait(false); } /// public async Task> SubscribeToTickerUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { - var subscription = new BingXSubscription(_logger, symbol + "@ticker", "24hTicker" + symbol, onMessage, false); + var stream = symbol + "@ticker"; + var subscription = new BingXSubscription(_logger, stream, "24hTicker" + symbol, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market"), subscription, ct).ConfigureAwait(false); } @@ -95,7 +98,7 @@ public async Task> SubscribeToTickerUpdatesAsync( public async Task> SubscribeToPriceUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { var stream = symbol + "@lastPrice"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market"), subscription, ct).ConfigureAwait(false); } @@ -103,7 +106,7 @@ public async Task> SubscribeToPriceUpdatesAsync(s public async Task> SubscribeToBookPriceUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) { var stream = symbol + "@bookTicker"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market"), subscription, ct).ConfigureAwait(false); } @@ -111,7 +114,7 @@ public async Task> SubscribeToBookPriceUpdatesAsy public async Task> SubscribeToOrderUpdatesAsync(string listenKey, Action> onMessage, CancellationToken ct = default) { var stream = "spot.executionReport"; - var subscription = new BingXSubscription(_logger, stream, stream, onMessage, false); + var subscription = new BingXSubscription(_logger, stream, stream, x => onMessage(x.WithStreamId(stream).WithSymbol(x.Data.Symbol)), false); return await SubscribeAsync(BaseAddress.AppendPath("market") + "?listenKey=" + listenKey, subscription, ct).ConfigureAwait(false); } diff --git a/BingX.Net/Objects/Sockets/Subscriptions/BingXBalanceSubscription.cs b/BingX.Net/Objects/Sockets/Subscriptions/BingXBalanceSubscription.cs index 6b8ef3f..b02b1e1 100644 --- a/BingX.Net/Objects/Sockets/Subscriptions/BingXBalanceSubscription.cs +++ b/BingX.Net/Objects/Sockets/Subscriptions/BingXBalanceSubscription.cs @@ -59,7 +59,7 @@ public BingXBalanceSubscription(ILogger logger, Action message) { var update = (BingXBalanceUpdate)message.Data; - _handler.Invoke(message.As(update!, update.Event, SocketUpdateType.Update)); + _handler.Invoke(message.As(update!, update.Event, null, SocketUpdateType.Update)); return new CallResult(null); } } diff --git a/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs b/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs index e0e247e..0c0c0da 100644 --- a/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs +++ b/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs @@ -70,7 +70,7 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven klineUpdate.Symbol = update.Symbol!; } - _handler.Invoke(message.As(update.Data!, update.DataType, SocketUpdateType.Update)); + _handler.Invoke(message.As(update.Data!, update.DataType, update.Symbol, SocketUpdateType.Update)); return new CallResult(null); } } diff --git a/BingX.Net/Objects/Sockets/Subscriptions/BingXUserDataSubscription.cs b/BingX.Net/Objects/Sockets/Subscriptions/BingXUserDataSubscription.cs index eff5b78..5e35c47 100644 --- a/BingX.Net/Objects/Sockets/Subscriptions/BingXUserDataSubscription.cs +++ b/BingX.Net/Objects/Sockets/Subscriptions/BingXUserDataSubscription.cs @@ -78,19 +78,19 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven { if (message.Data is BingXConfigUpdate configUpdate) { - _configHandler?.Invoke(message.As(configUpdate, configUpdate.Configuration.Symbol, SocketUpdateType.Update)); + _configHandler?.Invoke(message.As(configUpdate, configUpdate.Event, configUpdate.Configuration.Symbol, SocketUpdateType.Update)); } else if (message.Data is BingXFuturesAccountUpdate accountUpdate) { - _accountHandler?.Invoke(message.As(accountUpdate, accountUpdate.Update.Trigger, SocketUpdateType.Update)); + _accountHandler?.Invoke(message.As(accountUpdate, accountUpdate.Event, null, SocketUpdateType.Update)); } else if (message.Data is BingXFuturesOrderUpdateWrapper orderUpdate) { - _orderHandler?.Invoke(message.As(orderUpdate.Data, orderUpdate.Data.Symbol, SocketUpdateType.Update)); + _orderHandler?.Invoke(message.As(orderUpdate.Data, orderUpdate.Event, orderUpdate.Data.Symbol, SocketUpdateType.Update)); } else if (message.Data is BingXListenKeyExpiredUpdate listenKeyUpdate) { - _listenkeyHandler?.Invoke(message.As(listenKeyUpdate!, listenKeyUpdate!.ListenKey, SocketUpdateType.Update)); + _listenkeyHandler?.Invoke(message.As(listenKeyUpdate!, listenKeyUpdate.Event, null, SocketUpdateType.Update)); } return new CallResult(null);