public void ProcessCandles(CandlesUpdatedEvent candleEvent)
        {
            foreach (var candle in candleEvent.Candles)
            {
                if (candle.TimeInterval != CandleTimeInterval.Minute)
                {
                    continue;
                }

                if (candle.PriceType != CandlePriceType.Ask && candle.PriceType != CandlePriceType.Bid)
                {
                    continue;
                }

                var candlestick = new OutCandlestick
                {
                    AssetPairId = candle.AssetPairId,
                    IsAsk       = candle.PriceType == CandlePriceType.Ask,
                    High        = (decimal)candle.High,
                    Low         = (decimal)candle.Low,
                    Open        = (decimal)candle.Open,
                    Close       = (decimal)candle.Close,
                    Start       = DateTimeConverter.Convert(candle.CandleTimestamp),
                    Finish      = DateTimeConverter.Convert(candle.ChangeTimestamp),
                };

                string key   = GetKey(candle);
                var    start = candle.CandleTimestamp;
                if (_candlesDict.ContainsKey(key))
                {
                    var datesDict = _candlesDict[key];
                    if (datesDict.ContainsKey(start))
                    {
                        datesDict[start] = Merge(datesDict[start], candlestick);
                    }
                    else
                    {
                        datesDict.Add(start, candlestick);
                    }
                }
                else
                {
                    var datesDict = new Dictionary <DateTime, OutCandlestick>
                    {
                        { start, candlestick },
                    };
                    _candlesDict.Add(key, datesDict);
                }
            }
        }
 public TablesStructure GetTablesStructure()
 {
     return(new TablesStructure
     {
         Tables = new List <TableStructure>
         {
             new TableStructure
             {
                 TableName = "Candlesticks",
                 AzureBlobFolder = MainContainer,
                 Columns = OutCandlestick.GetStructure()
                           .Select(p => new ColumnInfo {
                     ColumnName = p.Item1, ColumnType = p.Item2
                 })
                           .ToList(),
             }
         },
     });
 }
 private OutCandlestick Merge(OutCandlestick oldItem, OutCandlestick newItem)
 {
     if (newItem.High > oldItem.High)
     {
         oldItem.High = newItem.High;
     }
     if (newItem.Low < oldItem.Low)
     {
         oldItem.Low = newItem.Low;
     }
     if (newItem.Start.CompareTo(oldItem.Start) > 0)
     {
         oldItem.Close  = newItem.Close;
         oldItem.Finish = newItem.Finish;
     }
     else if (newItem.Start.CompareTo(oldItem.Start) < 0)
     {
         oldItem.Open  = newItem.Open;
         oldItem.Start = newItem.Start;
     }
     return(oldItem);
 }