Пример #1
0
        public static MdpMessage GetMessage(byte[] data)
        {
            MessageType type = GetType(data);

            MdpMessage mes = null;

            if (type == MessageType.SecurityDefinition)
            {
                mes = new SecurityDefinition();
            }
            else if (type == MessageType.SecurityStatus)
            {
                mes = new StatusUpdate();
            }
            else if (type == MessageType.MarketDataSnapshotFullRefresh)
            {
                mes = new SnapshotUpdate();
            }
            else if (type == MessageType.MarketDataIncrementalRefresh)
            {
                mes = new IncrementalUpdate();
            }

            mes.Decode(data);

            return(mes);
        }
Пример #2
0
        private void SendVolumeUpdate(TradedEventArgs e, OrderBook book)
        {
            var volumeUpdate = new IncrementalUpdate(MatchEventIndicator.LastVolume, e.Time);

            volumeUpdate.MDEntries.Add(MarketDataUpdateDataBlock.VolumeNew(e.Security,
                                                                           incrementalSeqNums[e.Security],
                                                                           book.SessionVolume));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(volumeUpdate);
        }
Пример #3
0
        private void SendOpenInterestUpdate(TradedEventArgs e, OrderBook book)
        {
            var interestUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            interestUpdate.MDEntries.Add(MarketDataUpdateDataBlock.OpenInterestNew(e.Security,
                                                                                   incrementalSeqNums[e.Security],
                                                                                   book.PreviousSessionOpenInterest,
                                                                                   book.PreviousSessionDate));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(interestUpdate);
        }
Пример #4
0
        private void SendOpenPriceUpdate(TradedEventArgs e, OrderBook book)
        {
            var tradeHighUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            tradeHighUpdate.MDEntries.Add(MarketDataUpdateDataBlock.OpenPriceNew(e.Security,
                                                                                 incrementalSeqNums[e.Security],
                                                                                 book.SessionOpenPrice.Value,
                                                                                 false));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(tradeHighUpdate);
        }
Пример #5
0
        private void SendSettlementUpdate(TradedEventArgs e, OrderBook book)
        {
            var settlementUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            settlementUpdate.MDEntries.Add(MarketDataUpdateDataBlock.SettlePriceNew(e.Security,
                                                                                    incrementalSeqNums[e.Security],
                                                                                    book.PreviousSessionSettlementPrice,
                                                                                    SettlementPriceType.Final,
                                                                                    book.PreviousSessionDate));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(settlementUpdate);
        }
Пример #6
0
        private void SendBookUpdate(TradedEventArgs e)
        {
            var bookUpdate = new IncrementalUpdate(MatchEventIndicator.LastRealQuote, e.Time);

            foreach (var bookLevelUpdate in GenerateBookUpdateDataBlock(e.Security))
            {
                bookLevelUpdate.RptSeq = incrementalSeqNums[e.Security];
                incrementalSeqNums[e.Security]++;
                bookUpdate.MDEntries.Add(bookLevelUpdate);
            }
            incrementalServer.Send(bookUpdate);
        }
Пример #7
0
        private void HandleSnapshotTimerInterval(object state)
        {
            return;

            if (snapshotSecurityIterator == 0)
            {
                // take snapshot of all books
                // i.e. generate all kinds of messages
                // x Book Quotes – Bids and Offers
                // x Implied Book Quotes – Bids and Offers
                // Last Trade
                // Opening Prices
                // Session High and Low Trade Prices
                // Session High Bid and Session Low Offer
                // Fixing Price
                // Settlement Price
                // Cleared Trade Volume
                // Open Interest
                // Electronic Volume
                // Threshold Limits

                //SendRangeUpdate(e, book);
                //SendOpenPriceUpdate(e, book);
                //SendClearedVolumeUpdate(e, book);
                //SendOpenInterestUpdate();
                //SendSettlementUpdate(e, book);

                snapshotTime = DateTime.UtcNow;
            }

            var sec = securities[snapshotSecurityIterator];

            var update = new IncrementalUpdate(MatchEventIndicator.LastMessage, snapshotTime);

            update.MDEntries.Add(MarketDataUpdateDataBlock.VolumeNew(sec, incrementalSeqNums[sec], 0));
            incrementalSeqNums[sec]++;
            snapshotServer.Send(update);

            // move iterator on
            snapshotSecurityIterator++;
            if (snapshotSecurityIterator >= securities.Count)
            {
                snapshotSecurityIterator = 0;
            }
        }
Пример #8
0
        private void SendBookUpdates(Security security)
        {
            var bookUpdate = new IncrementalUpdate(MatchEventIndicator.LastRealQuote, DateTime.UtcNow);

            foreach (var bookLevelUpdate in GenerateBookUpdateDataBlock(security))
            {
                bookLevelUpdate.RptSeq = incrementalSeqNums[security];
                incrementalSeqNums[security]++;
                bookUpdate.MDEntries.Add(bookLevelUpdate);
            }

            if (bookUpdate.MDEntries.Count < 1)
            {
                return;
            }

            incrementalServer.Send(bookUpdate);
        }
Пример #9
0
        private void SendTradeUpdate(Security security, DateTime time, List <Server.Fill> fills)
        {
            var tradeUpdate = new IncrementalUpdate(MatchEventIndicator.LastTradeSummary, time);

            // aggregate by price
            var xyz         = fills.GroupBy(x => x.Price).Select(group => new { Price = group.Key, Orders = group.ToList() }).ToList();
            var infoByPrice = fills.GroupBy(x => x.Price)
                              .Select(group => new
            {
                Price          = group.Key,
                Quantity       = group.Sum(z => z.Quantity) / 2,
                Count          = group.Select(z => z.OrderId).Distinct().Count(),
                AggressiveSide = group.First(x => x.Side == Side.Buy).IsAggressor ? Side.Buy : Side.Sell,
            }).ToList();

            foreach (var grpByPrice in infoByPrice)
            {
                tradeUpdate.MDEntries.Add(MarketDataUpdateDataBlock.TradeNew(security, incrementalSeqNums[security],
                                                                             grpByPrice.Price, grpByPrice.Quantity,
                                                                             grpByPrice.Quantity, grpByPrice.AggressiveSide));
                incrementalSeqNums[security]++;
            }

            // aggregate by orderid
            var qtyById = fills.GroupBy(x => new { Id = x.OrderId, Price = x.Price })
                          .Select(group => new
            {
                OrderId  = group.Key.Id,
                Quantity = group.Sum(z => z.Quantity),
            }).ToList();

            foreach (var orderFillQty in qtyById)
            {
                tradeUpdate.NoOrderIDEntries.Add(new IncrementalUpdateOrderEntry()
                {
                    OrderId = orderFillQty.OrderId.ToString(), FillQuantity = orderFillQty.Quantity
                });
            }

            incrementalServer.Send(tradeUpdate);
        }
Пример #10
0
        private void SendRangeUpdate(TradedEventArgs e, OrderBook book)
        {
            var tradeHighUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            tradeHighUpdate.MDEntries.Add(MarketDataUpdateDataBlock.TradeHighLowNew(e.Security,
                                                                                    incrementalSeqNums[e.Security],
                                                                                    true,
                                                                                    book.SessionMaxTradePrice.Value));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(tradeHighUpdate);

            var tradeLowUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            tradeLowUpdate.MDEntries.Add(MarketDataUpdateDataBlock.TradeHighLowNew(e.Security,
                                                                                   incrementalSeqNums[e.Security],
                                                                                   true,
                                                                                   book.SessionMinTradePrice.Value));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(tradeLowUpdate);

            var highBidUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            highBidUpdate.MDEntries.Add(MarketDataUpdateDataBlock.TradeHighBidLowAskNew(e.Security,
                                                                                        incrementalSeqNums[e.Security],
                                                                                        Side.Buy,
                                                                                        book.SessionMaxBidPrice.Value));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(highBidUpdate);

            var lowAskUpdate = new IncrementalUpdate(MatchEventIndicator.None, e.Time);

            lowAskUpdate.MDEntries.Add(MarketDataUpdateDataBlock.TradeHighBidLowAskNew(e.Security,
                                                                                       incrementalSeqNums[e.Security],
                                                                                       Side.Sell,
                                                                                       book.SessionMinAskPrice.Value));
            incrementalSeqNums[e.Security]++;
            incrementalServer.Send(lowAskUpdate);
        }