Esempio n. 1
0
        /// <summary>
        /// The DI constructor.
        /// </summary>
        /// <param name="aggregateTradeClient"></param>
        /// <param name="candlestickClient"></param>
        /// <param name="depthClient"></param>
        /// <param name="statisticsClient"></param>
        /// <param name="tradeClient"></param>
        /// <param name="logger"></param>
        protected BinanceJsonClientManager(
            IAggregateTradeWebSocketClient aggregateTradeClient,
            ICandlestickWebSocketClient candlestickClient,
            IDepthWebSocketClient depthClient,
            ISymbolStatisticsWebSocketClient statisticsClient,
            ITradeWebSocketClient tradeClient,
            ILogger<BinanceJsonClientManager<TStream>> logger = null)
        {
            Throw.IfNull(aggregateTradeClient, nameof(aggregateTradeClient));
            Throw.IfNull(candlestickClient, nameof(candlestickClient));
            Throw.IfNull(depthClient, nameof(depthClient));
            Throw.IfNull(statisticsClient, nameof(statisticsClient));
            Throw.IfNull(tradeClient, nameof(tradeClient));

            AggregateTradeClient = aggregateTradeClient;
            CandlestickClient = candlestickClient;
            DepthClient = depthClient;
            StatisticsClient = statisticsClient;
            TradeClient = tradeClient;
            _logger = logger;

            // Forward controller error events.
            aggregateTradeClient.Error += HandleError;
            candlestickClient.Error += HandleError;
            depthClient.Error += HandleError;
            statisticsClient.Error += HandleError;
            tradeClient.Error += HandleError;
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <param name="symbol"></param>
        /// <param name="interval"></param>
        /// <param name="callback"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task StreamAsync(this ICandlestickWebSocketClient client, string symbol, CandlestickInterval interval, Action <CandlestickEventArgs> callback, CancellationToken token)
        {
            Throw.IfNull(client, nameof(client));

            client.Subscribe(symbol, interval, callback);

            return(client.WebSocket.StreamAsync(token));
        }
 /// <summary>
 /// The DI constructor.
 /// </summary>
 /// <param name="aggregateTradeWebSocketClient"></param>
 /// <param name="candlestickWebSocketClient"></param>
 /// <param name="depthWebSocketClient"></param>
 /// <param name="symbolStatisticsWebSocketClient"></param>
 /// <param name="tradeWebSocketClient"></param>
 /// <param name="logger"></param>
 public BinanceWebSocketClientManager(
     IAggregateTradeWebSocketClient aggregateTradeWebSocketClient,
     ICandlestickWebSocketClient candlestickWebSocketClient,
     IDepthWebSocketClient depthWebSocketClient,
     ISymbolStatisticsWebSocketClient symbolStatisticsWebSocketClient,
     ITradeWebSocketClient tradeWebSocketClient,
     ILogger <BinanceWebSocketClientManager> logger = null)
     : base(aggregateTradeWebSocketClient,
            candlestickWebSocketClient,
            depthWebSocketClient,
            symbolStatisticsWebSocketClient,
            tradeWebSocketClient,
            logger)
 {
 }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task StreamAsync(this ICandlestickWebSocketClient client, CancellationToken token)
        {
            Throw.IfNull(client, nameof(client));

            return(client.WebSocket.StreamAsync(token));
        }
Esempio n. 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="client"></param>
 /// <param name="symbol"></param>
 /// <param name="interval"></param>
 public static void Unsubscribe(this ICandlestickWebSocketClient client, string symbol, CandlestickInterval interval)
 => client.Unsubscribe(symbol, interval, null);
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="client"></param>
 /// <param name="symbol"></param>
 /// <param name="interval"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Task StreamAsync(this ICandlestickWebSocketClient client, string symbol, CandlestickInterval interval, CancellationToken token)
 => StreamAsync(client, symbol, interval, null, token);
        public KucoinWebSocketManager(
            IAggregateTradeWebSocketClient aggregateTradeClient,
            ICandlestickWebSocketClient candlestickClient,
            IDepthWebSocketClient depthClient,
            ISymbolStatisticsWebSocketClient statisticsClient,
            ITradeWebSocketClient tradeClient,
            ILogger <IKucoinWebSocketManager> logger = null)
        {
            Throw.IfNull(aggregateTradeClient, nameof(aggregateTradeClient));
            Throw.IfNull(candlestickClient, nameof(candlestickClient));
            Throw.IfNull(depthClient, nameof(depthClient));
            Throw.IfNull(statisticsClient, nameof(statisticsClient));
            Throw.IfNull(tradeClient, nameof(tradeClient));

            _logger = logger;


            _aggregateTradeClientAdapter = new AggregateTradeWebSocketClientAdapter(
                this, aggregateTradeClient, _logger,
                err => RaiseErrorEvent(_aggregateTradeClientAdapter, err,
                                       $"{nameof(IAggregateTradeWebSocketClient)}: Adapter failed."));

            _candlestickClientAdapter = new CandlestickWebSocketClientAdapter(
                this, candlestickClient, _logger,
                err => RaiseErrorEvent(_candlestickClientAdapter, err,
                                       $"{nameof(ICandlestickWebSocketClient)}: Adapter failed."));

            _depthClientAdapter = new DepthWebSocketClientAdapter(
                this, depthClient, _logger,
                err => RaiseErrorEvent(_depthClientAdapter, err,
                                       $"{nameof(IDepthWebSocketClient)}: Adapter failed."));

            _statisticsClientAdapter = new SymbolStatisticsWebSocketClientAdapter(
                this, statisticsClient, _logger,
                err => RaiseErrorEvent(_statisticsClientAdapter, err,
                                       $"{nameof(ISymbolStatisticsWebSocketClient)}: Adapter failed."));

            _tradeClientAdapter = new TradeWebSocketClientAdapter(
                this, tradeClient, _logger,
                err => RaiseErrorEvent(_tradeClientAdapter, err,
                                       $"{nameof(ITradeWebSocketClient)}: Adapter failed."));


            _controllers[aggregateTradeClient.WebSocket] =
                new WebSocketStreamController(
                    aggregateTradeClient.WebSocket,
                    err => RaiseErrorEvent(_aggregateTradeClientAdapter, err,
                                           $"{nameof(IAggregateTradeWebSocketClient)}: Controller failed."));

            _controllers[candlestickClient.WebSocket] =
                new WebSocketStreamController(
                    candlestickClient.WebSocket,
                    err => RaiseErrorEvent(_candlestickClientAdapter, err,
                                           $"{nameof(ICandlestickWebSocketClient)}: Controller failed."));

            _controllers[depthClient.WebSocket] =
                new WebSocketStreamController(
                    depthClient.WebSocket,
                    err => RaiseErrorEvent(_depthClientAdapter, err,
                                           $"{nameof(IDepthWebSocketClient)}: Controller failed."));

            _controllers[statisticsClient.WebSocket] =
                new WebSocketStreamController(
                    statisticsClient.WebSocket,
                    err => RaiseErrorEvent(_statisticsClientAdapter, err,
                                           $"{nameof(ISymbolStatisticsWebSocketClient)}: Controller failed."));

            _controllers[tradeClient.WebSocket] =
                new WebSocketStreamController(
                    tradeClient.WebSocket,
                    err => RaiseErrorEvent(_tradeClientAdapter, err,
                                           $"{nameof(ITradeWebSocketClient)}: Controller failed."));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="client"></param>
 /// <param name="symbol"></param>
 /// <param name="interval"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Task SubscribeAsync(this ICandlestickWebSocketClient client, string symbol, CandlestickInterval interval, CancellationToken token)
 => client.SubscribeAsync(symbol, interval, null, token);