protected override async Task DoWork(PairConfig pair, CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { using (BinanceSocketClient client = new BinanceSocketClient()) { CallResult <UpdateSubscription> res = client.SubscribeToBookTickerUpdates(pair.Symbol, async(data) => { Book book = new Book(); book.ExchangeCode = Exchange.Code; book.Symbol = data.Symbol; book.BestAskPrice = data.BestAskPrice; book.BestAskQuantity = data.BestAskQuantity; book.BestBidPrice = data.BestBidPrice; book.BestBidQuantity = data.BestBidQuantity; await _bookProcessor.Create(book); }); res.Data.ConnectionLost += () => { _logger.LogError($"Connection to {Exchange} is lost"); }; res.Data.ConnectionRestored += (data) => { _logger.LogError($"Connection to {Exchange} is Restored"); }; while (!stoppingToken.IsCancellationRequested) { } } } catch (Exception ex) { _logger.LogError($"{Exchange.Description} Trades service failed with message {ex.Message}", ex); } } }