private async Task ProcessMessageAsync(Quote quote) { if (quote.Ask == 0 && quote.Bid == 0) { return; } quote.SourceId = quote.Source.GetHashCode(); quote.AssetPairId = quote.Asset.GetHashCode(); lock (_sync) { _quoteMemoryCache.Add(quote); var count = _quoteMemoryCache.GetCount(); if (count >= _config.Main.QuoteBatchSize) { var quotes = _quoteMemoryCache.GetAllAndClear(); //if (_config.Main.WriteToDB) // WriteToDB(quotes); if (_config.Main.WriteToBlob) { WriteToBlob(quotes); } } } }
private async Task ProcessMessageAsync(Trade arg) { _tradeMemoryCache.Add(arg); if (_tradeMemoryCache.GetCount() >= 500) { var sw = new Stopwatch(); sw.Start(); var list = _tradeMemoryCache.GetAllAndClear(); using (var context = _connectionFactory.CreateDataContext()) { context.Trades.AddRange(list); await context.SaveChangesAsync(); } sw.Stop(); _logger.LogInformation("Added to DB.Trades {tradeCount} trades, took {seconds} seconds.", list.Count, sw.Elapsed.TotalSeconds); } }