From aa280398058d7ea973bbccb89bccd735896c4b58 Mon Sep 17 00:00:00 2001 From: Ahmad Noman Musleh Date: Fri, 24 Dec 2021 11:45:40 +0300 Subject: [PATCH] Added MessagesQueueCount property to client --- src/OpenAPI.Net/OpenAPI.Net.csproj | 2 +- src/OpenAPI.Net/OpenClient.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/OpenAPI.Net/OpenAPI.Net.csproj b/src/OpenAPI.Net/OpenAPI.Net.csproj index dce6c6d..a5cea6b 100644 --- a/src/OpenAPI.Net/OpenAPI.Net.csproj +++ b/src/OpenAPI.Net/OpenAPI.Net.csproj @@ -9,7 +9,7 @@ cTrader, Open API, Spotware A .NET RX library for Spotware Open API Spotware.OpenAPI.Net - 1.3.2 + 1.3.3 AnyCPU Spotware Spotware diff --git a/src/OpenAPI.Net/OpenClient.cs b/src/OpenAPI.Net/OpenClient.cs index ef73966..c8cf7b6 100644 --- a/src/OpenAPI.Net/OpenClient.cs +++ b/src/OpenAPI.Net/OpenClient.cs @@ -108,6 +108,11 @@ public OpenClient(string host, int port, TimeSpan heartbeatInerval, int maxReque /// public DateTimeOffset LastSentMessageTime { get; private set; } + /// + /// The count of messages on queue to be sent + /// + public int MessagesQueueCount { get; private set; } + /// /// Connects to the API based on you specified method (websocket or TCP) /// @@ -235,6 +240,8 @@ public async Task SendMessage(T message, ProtoOAPayloadType payloadType, stri /// Task public async Task SendMessage(ProtoMessage message) { + MessagesQueueCount += 1; + await _messagesChannel.Writer.WriteAsync(message); } @@ -293,6 +300,8 @@ private async Task StartSendingMessages(CancellationToken cancellationToken) } await SendMessageInstant(message); + + if (MessagesQueueCount > 0) MessagesQueueCount -= 1; } } } @@ -321,6 +330,8 @@ public void Dispose() _messagesChannel.Writer.TryComplete(); + MessagesQueueCount = 0; + if (UseWebSocket) { _webSocketMessageReceivedDisposable?.Dispose();