Exemple #1
0
 private IEnumerable <MarketDataUpdateDataBlock> GenerateFromAggregateBooks(Security sec, int depth, Side side,
                                                                            AggregateBookLevel[] old,
                                                                            AggregateBookLevel[] fresh)
 {
     // TODO: add support for Delete From/Delete Thru
     for (int i = 0; i < depth; i++)
     {
         if (old[i] == null && fresh[i] == null)
         {
             continue;
         }
         if (old[i] != null && fresh[i] == null)
         {
             yield return(MarketDataUpdateDataBlock.RealBookDelete(sec, side, 0, old[i].Price,
                                                                   old[i].Quantity, i, old[i].Count));
         }
         else if (old[i] == null && fresh[i] != null)
         {
             yield return(MarketDataUpdateDataBlock.RealBookNew(sec, side, 0, fresh[i].Price,
                                                                fresh[i].Quantity, i, fresh[i].Count));
         }
         else if (old[i].Price == fresh[i].Price &&
                  old[i].Quantity == fresh[i].Quantity &&
                  old[i].Count == fresh[i].Count)
         {
             continue;
         }
         else
         {
             yield return(MarketDataUpdateDataBlock.RealBookUpdate(sec, side, 0, fresh[i].Price,
                                                                   fresh[i].Quantity, i, fresh[i].Count));
         }
     }
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #6
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;
            }
        }
Exemple #7
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);
        }
Exemple #8
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);
        }