Ejemplo n.º 1
0
            public override void Serialize(Stream stream, IEnumerable <QuoteChangeMessage> data, IMarketDataMetaInfo metaInfo)
            {
                var list = data.SelectMany(d =>
                {
                    var items = new List <TimeQuoteChange>();

                    items.AddRange(d.Bids.OrderByDescending(q => q.Price).Select(q => new TimeQuoteChange(q, d)));

                    if (items.Count == 0)
                    {
                        items.Add(new TimeQuoteChange {
                            Side = Sides.Buy, ServerTime = d.ServerTime
                        });
                    }

                    var bidsCount = items.Count;

                    items.AddRange(d.Asks.OrderBy(q => q.Price).Select(q => new TimeQuoteChange(q, d)));

                    if (items.Count == bidsCount)
                    {
                        items.Add(new TimeQuoteChange {
                            Side = Sides.Sell, ServerTime = d.ServerTime
                        });
                    }

                    return(items);
                });

                _quoteSerializer.Serialize(stream, list, metaInfo);
            }
Ejemplo n.º 2
0
            public override byte[] Serialize(IEnumerable <QuoteChangeMessage> data, IMarketDataMetaInfo metaInfo)
            {
                var list = data.SelectMany(d =>
                {
                    var items = new List <TimeQuoteChange>();

                    items.AddRange(d.Bids.OrderBy(q => q.Price).Select(q => new TimeQuoteChange(q, d)));
                    items.AddRange(d.Asks.OrderBy(q => q.Price).Select(q => new TimeQuoteChange(q, d)));

                    return(items);
                });

                return(_quoteSerializer.Serialize(list, metaInfo));
            }