public async Task ProcessMessageAsync(object obj) { var book = obj as InOrderBook; if (!book.IsValid()) { _log.WriteWarning(nameof(MessageProcessor), nameof(Convert), $"Orderbook {book.ToJson()} is invalid!"); } decimal bestPrice = 0; if (book.Prices != null && book.Prices.Count > 0) { bestPrice = book.IsBuy ? (decimal)book.Prices.Max(p => p.Price) : (decimal)book.Prices.Min(p => p.Price); } var orderbook = new OutOrderbook { AssetPairId = book.AssetPair, IsBuy = book.IsBuy, Timestamp = DateTimeConverter.Convert(book.Timestamp), BestPrice = bestPrice, }; if (!_minutesDict.ContainsKey(book.AssetPair)) { _minutesDict.Add(book.AssetPair, new Dictionary <int, string>()); } var assetPairDict = _minutesDict[book.AssetPair]; int minuteKey = GetMinuteKey(book.Timestamp); var allCount = _minutesDict.Sum(i => i.Value.Values.Sum(k => k.Length)); if (allCount >= _maxBatchCount) { var allOtherMinutesItems = new List <string>(); foreach (var pair in _minutesDict) { foreach (var key in pair.Value.Keys.ToArray()) { if (key == minuteKey) { continue; } allOtherMinutesItems.Add(pair.Value[key]); pair.Value.Remove(key); } } await _messagesHandler(StructureBuilder.MainContainer, allOtherMinutesItems); } assetPairDict[minuteKey] = orderbook.GetValuesString(); }
public TablesStructure GetTablesStructure() { return(new TablesStructure { Tables = new List <TableStructure> { new TableStructure { TableName = "Orderbook", AzureBlobFolder = MainContainer, Columns = OutOrderbook.GetStructure() .Select(p => new ColumnInfo { ColumnName = p.Item1, ColumnType = p.Item2 }) .ToList(), } } }); }