From 59acbd648eefd6fba829a9f8880199d0df1ca658 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Mon, 28 Sep 2026 11:11:41 +0200 Subject: [PATCH] Added UnsubscribeAllAsync method to Shared APIs ISharedSubscription and IShaerdApiClientBase --- .../SharedApis/SharedApiClientBase.cs | 15 +++++++++++++++ .../SharedApis/V2/ISharedSubscription.cs | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs b/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs index 09f83740..507522da 100644 --- a/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs +++ b/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace CryptoExchange.Net.SharedApis { @@ -104,6 +105,11 @@ namespace CryptoExchange.Net.SharedApis SharedCapabilityResolution? GetCapability(SharedCapabilityReference capability, TradingMode tradingMode) where T : ISharedApiCapability; + /// + /// Unsubscribes all subscriptions created by the underlying socket API + /// client and closes its subscription connections. + /// + Task UnsubscribeAllAsync(); } /// @@ -209,6 +215,15 @@ namespace CryptoExchange.Net.SharedApis return GetCapabilities(tradingMode); } + /// + public Task UnsubscribeAllAsync() + { + return Task.WhenAll( + _sharedApis + .OfType() + .Select(x => x.UnsubscribeAllAsync())); + } + object? ISharedApiClientResolver.GetCapability(Type capabilityType) { return _sharedApis diff --git a/CryptoExchange.Net/SharedApis/V2/ISharedSubscription.cs b/CryptoExchange.Net/SharedApis/V2/ISharedSubscription.cs index 1d6cd387..159a9e47 100644 --- a/CryptoExchange.Net/SharedApis/V2/ISharedSubscription.cs +++ b/CryptoExchange.Net/SharedApis/V2/ISharedSubscription.cs @@ -1,13 +1,19 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading.Tasks; namespace CryptoExchange.Net.SharedApis { /// - /// Shared WebSocket API subscription capabitlity + /// Shared WebSocket API subscription capability /// public interface ISharedSubscription : ISharedSocket { + /// + /// Unsubscribes all subscriptions created by the underlying socket API + /// client and closes its subscription connections. + /// + Task UnsubscribeAllAsync(); } }