diff --git a/CryptoExchange.Net/SharedApis/SharedUtils.cs b/CryptoExchange.Net/SharedApis/SharedUtils.cs index 0a49c013..6603bac0 100644 --- a/CryptoExchange.Net/SharedApis/SharedUtils.cs +++ b/CryptoExchange.Net/SharedApis/SharedUtils.cs @@ -668,6 +668,20 @@ namespace CryptoExchange.Net.SharedApis .ParallelEnumerateAsync(); } + /// + /// Subscribe to funding info updates for all capabilities in parallel and return results as they arrive + /// + public static IAsyncEnumerable> SubscribeAllAsync( + this IEnumerable> capabilities, + SubscribeFundingInfoRequest request, + Action> onData, + CancellationToken ct = default) + { + return capabilities + .Select(x => x.Capability.SubscribeToFundingInfoUpdatesAsync(request, onData, ct)) + .ParallelEnumerateAsync(); + } + /// /// Subscribe to kline updates for all capabilities in parallel and return results as they arrive /// diff --git a/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/ISubscribeFundingInfoSocket.cs b/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/ISubscribeFundingInfoSocket.cs new file mode 100644 index 00000000..c4ff66fe --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/ISubscribeFundingInfoSocket.cs @@ -0,0 +1,28 @@ +using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Objects.Sockets; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Operation for subscribing to funding info updates + /// + public interface ISubscribeFundingInfoSocket : ISharedSubscription + { + /// + /// Funding info subscription options + /// + SubscribeFundingInfoOptions SubscribeFundingInfoOptions { get; } + + /// + /// Subscribe to funding info updates + /// + /// Request info + /// Update handler + /// Cancellation token, can be used to stop the updates + /// + Task> SubscribeToFundingInfoUpdatesAsync(SubscribeFundingInfoRequest request, Action> handler, CancellationToken ct = default); + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/SubscribeFundingInfoOptions.cs b/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/SubscribeFundingInfoOptions.cs new file mode 100644 index 00000000..1f14edf8 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/SubscribeFundingInfoOptions.cs @@ -0,0 +1,29 @@ +using CryptoExchange.Net.Objects; +using System; +using System.Linq; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Options for subscribing to funding info updates + /// + public class SubscribeFundingInfoOptions : CapabilityOptions + { + /// + public override string Description => "Subscribe to funding info updates for a symbol"; + + private static readonly RequestParameterDescription[] _defaultParameterRules = new[] + { + RequestParameterRule.Optional(x => x.Symbol, "The symbol to subscribe to", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")), + RequestParameterRule.Optional(x => x.Symbols, "The symbols to subscribe to", new[] { new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT") }), + }; + + /// + /// ctor + /// + public SubscribeFundingInfoOptions(string exchange, bool needsAuthentication) + : base(exchange, needsAuthentication, nameof(ISubscribeFundingInfoSocket.SubscribeToFundingInfoUpdatesAsync), _defaultParameterRules, SharedTradingModeSets.Futures) + { + } + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/SubscribeFundingInfoRequest.cs b/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/SubscribeFundingInfoRequest.cs new file mode 100644 index 00000000..dc24ff4a --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Funding/SubscribeFundingInfo/SubscribeFundingInfoRequest.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Request to subscribe to funding info updates for a symbol + /// + public record SubscribeFundingInfoRequest : SharedSymbolRequest + { + /// + /// ctor + /// + /// The symbol to subscribe to + /// Exchange specific parameters + public SubscribeFundingInfoRequest(SharedSymbol symbol, ExchangeParameters? exchangeParameters = null) + : base(symbol, exchangeParameters) + { + } + + /// + /// ctor + /// + /// The symbols to subscribe to + /// Exchange specific parameters + public SubscribeFundingInfoRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) + : base(symbols, exchangeParameters) + { + } + } +}