using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Objects.Sockets;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace CryptoExchange.Net.Sockets
{
///
/// Socket subscription
///
public abstract class Subscription : IMessageProcessor
{
///
/// Subscription id
///
public int Id { get; set; }
///
/// Total amount of invocations
///
public int TotalInvocations { get; set; }
///
/// Amount of invocation during this connection
///
public int ConnectionInvocations { get; set; }
///
/// Is it a user subscription
///
public bool UserSubscription { get; set; }
///
/// Has the subscription been confirmed
///
public bool Confirmed { get; set; }
///
/// Is the subscription closed
///
public bool Closed { get; set; }
///
/// Logger
///
protected readonly ILogger _logger;
///
/// If the subscription is a private subscription and needs authentication
///
public bool Authenticated { get; }
///
/// Strings to match this subscription to a received message
///
public abstract HashSet ListenerIdentifiers { get; set; }
///
/// Cancellation token registration
///
public CancellationTokenRegistration? CancellationTokenRegistration { get; set; }
///
/// Exception event
///
public event Action? Exception;
///
/// Get the deserialization type for this message
///
///
///
public abstract Type? GetMessageType(IMessageAccessor message);
///
/// ctor
///
///
///
///
public Subscription(ILogger logger, bool authenticated, bool userSubscription = true)
{
_logger = logger;
Authenticated = authenticated;
UserSubscription = userSubscription;
Id = ExchangeHelpers.NextId();
}
///
/// Get the subscribe query to send when subscribing
///
///
public abstract Query? GetSubQuery(SocketConnection connection);
///
/// Handle a subscription query response
///
///
public virtual void HandleSubQueryResponse(object message) { }
///
/// Handle an unsubscription query response
///
///
public virtual void HandleUnsubQueryResponse(object message) { }
///
/// Get the unsubscribe query to send when unsubscribing
///
///
public abstract Query? GetUnsubQuery();
///
public virtual CallResult