From abda0652371b250eb65f7a98f33e60ab6337539b Mon Sep 17 00:00:00 2001 From: Jkorf Date: Mon, 9 Feb 2026 12:57:52 +0100 Subject: [PATCH] Updated websocket message forwarding logic --- .../Sockets/Default/SocketConnection.cs | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/CryptoExchange.Net/Sockets/Default/SocketConnection.cs b/CryptoExchange.Net/Sockets/Default/SocketConnection.cs index 1f67f89..b91e4cb 100644 --- a/CryptoExchange.Net/Sockets/Default/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/Default/SocketConnection.cs @@ -633,22 +633,38 @@ namespace CryptoExchange.Net.Sockets.Default if (route.TypeIdentifier != typeIdentifier) continue; - if (topicFilter == null - || route.TopicFilter == null - || route.TopicFilter.Equals(topicFilter, StringComparison.Ordinal)) + // Forward message rules: + // | Message Topic | Route Topic Filter | Topics Match | Forward | Description + // | N | N | - | Y | No topic filter applied + // | N | Y | - | N | Route only listens to specific topic + // | Y | N | - | Y | Route listens to all message regardless of topic + // | Y | Y | Y | Y | Route listens to specific message topic + // | Y | Y | N | N | Route listens to different topic + if (topicFilter == null) { - processed = true; - - if (isQuery && query!.Completed) + if (route.TopicFilter != null) + // No topic on message, but route is filtering on topic continue; - - processor.Handle(this, receiveTime, originalData, result, route); - if (isQuery && !route.MultipleReaders) - { - complete = true; - break; - } } + else + { + if (route.TopicFilter != null && !route.TopicFilter.Equals(topicFilter, StringComparison.Ordinal)) + // Message has a topic, and the route has a filter for another topic + continue; + } + + processed = true; + + if (isQuery && query!.Completed) + continue; + + processor.Handle(this, receiveTime, originalData, result, route); + if (isQuery && !route.MultipleReaders) + { + complete = true; + break; + } + } if (complete)