From d8ac0ec48c0e55e64b609a9543ce7f3eaeb42ada Mon Sep 17 00:00:00 2001 From: JKorf Date: Tue, 12 Mar 2024 16:33:11 +0100 Subject: [PATCH] wip --- BingX.Net/BingX.Net.xml | 4 ++-- BingX.Net/Clients/SpotApi/BingXRestClientSpotApi.cs | 2 +- BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs | 10 +++++----- BingX.Net/Objects/Sockets/BingXQuery.cs | 6 +++--- .../Sockets/Subscriptions/BingXPingSubscription.cs | 4 ++-- .../Objects/Sockets/Subscriptions/BingXSubscription.cs | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/BingX.Net/BingX.Net.xml b/BingX.Net/BingX.Net.xml index aa3179c..f2fc7a8 100644 --- a/BingX.Net/BingX.Net.xml +++ b/BingX.Net/BingX.Net.xml @@ -336,7 +336,7 @@ - + @@ -2397,7 +2397,7 @@ - + diff --git a/BingX.Net/Clients/SpotApi/BingXRestClientSpotApi.cs b/BingX.Net/Clients/SpotApi/BingXRestClientSpotApi.cs index 6078e95..fcb3024 100644 --- a/BingX.Net/Clients/SpotApi/BingXRestClientSpotApi.cs +++ b/BingX.Net/Clients/SpotApi/BingXRestClientSpotApi.cs @@ -61,7 +61,7 @@ internal BingXRestClientSpotApi(ILogger logger, HttpClient? httpClient, BingXRes /// protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(); /// - protected override IMessageAccessor CreateAccessor() => new SystemTextJsonMessageAccessor(); + protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(); /// protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) diff --git a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs index 6b7390b..5033c06 100644 --- a/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs +++ b/BingX.Net/Clients/SpotApi/BingXSocketClientSpotApi.cs @@ -54,7 +54,7 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden /// protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(); /// - protected override IMessageAccessor CreateAccessor() => new SystemTextJsonMessageAccessor(); + protected override IByteMessageAccessor CreateAccessor() => new SystemTextJsonByteMessageAccessor(); /// public async Task> SubscribeToTradeUpdatesAsync(string symbol, Action> onMessage, CancellationToken ct = default) @@ -122,16 +122,16 @@ public async Task> SubscribeToBalanceUpdatesAsync } /// - public override Stream PreprocessStreamMessage(WebSocketMessageType type, Stream stream) + public override ReadOnlyMemory PreprocessStreamMessage(WebSocketMessageType type, ReadOnlyMemory data) { if (type != WebSocketMessageType.Binary) - return stream; + return data; var decompressedStream = new MemoryStream(); - using var deflateStream = new GZipStream(stream, CompressionMode.Decompress); + using var deflateStream = new GZipStream(new MemoryStream(data.ToArray()), CompressionMode.Decompress); deflateStream.CopyTo(decompressedStream); decompressedStream.Position = 0; - return decompressedStream; + return new ReadOnlyMemory(decompressedStream.ToArray()); } /// diff --git a/BingX.Net/Objects/Sockets/BingXQuery.cs b/BingX.Net/Objects/Sockets/BingXQuery.cs index ec4bbe2..3447bac 100644 --- a/BingX.Net/Objects/Sockets/BingXQuery.cs +++ b/BingX.Net/Objects/Sockets/BingXQuery.cs @@ -16,12 +16,12 @@ public BingXQuery(BingXSocketRequest request, bool authenticated, int weight = 1 ListenerIdentifiers = new HashSet { request.Id }; } - public override Task> HandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) { if (message.Data.Code != 0) - return Task.FromResult(new CallResult(new ServerError(message.Data.Code, message.Data.Message!), message.OriginalData)); + return new CallResult(new ServerError(message.Data.Code, message.Data.Message!), message.OriginalData); - return Task.FromResult(new CallResult(message.Data, message.OriginalData, null)); + return new CallResult(message.Data, message.OriginalData, null); } } } diff --git a/BingX.Net/Objects/Sockets/Subscriptions/BingXPingSubscription.cs b/BingX.Net/Objects/Sockets/Subscriptions/BingXPingSubscription.cs index fc98f26..15ee4f7 100644 --- a/BingX.Net/Objects/Sockets/Subscriptions/BingXPingSubscription.cs +++ b/BingX.Net/Objects/Sockets/Subscriptions/BingXPingSubscription.cs @@ -17,10 +17,10 @@ public BingXPingSubscription(ILogger logger) : base(logger, false) { } - public override Task HandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) { connection.Send(ExchangeHelpers.NextId(), new BingXPong { Pong = message.Data.Ping, Timestamp = message.Data.Timestamp }, 1); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs b/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs index 81ec928..a1959f8 100644 --- a/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs +++ b/BingX.Net/Objects/Sockets/Subscriptions/BingXSubscription.cs @@ -62,11 +62,11 @@ public BingXSubscription(ILogger logger, string dataType, string listenId, Actio }, false); /// - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var update = (BingXUpdate)message.Data; _handler.Invoke(message.As(update.Data!, update.DataType, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } }