/// <summary> /// Insert or replace orders from a given OrderBook. /// It is assumed that all the orders in the incoming OrderBook are from the same Exchange (identified by ExchangeID). /// Any order from the same Exchange will be removed before the incoming OrderBook is inserted /// </summary> /// <param name="orderBook">orderbook containing the orders which should be inserted in the aggregated orderbook.</param> /// <returns>AggregatedOrderBook where order from the same Exchange as orderBook as replaced with the ones in orderBook</returns> public AggregatedOrderBook InsertBook(IOrderBook orderBook) { int exchangeID = orderBook.ExchangeID; var modifiedAggregatedBids = Bids; var modifiedAggregatedAsks = Asks; var correspondingBids = Bids.Where(a => a.ExchangeID == exchangeID); modifiedAggregatedBids = Bids.Except(correspondingBids).Union(orderBook.Bids); var correspondingAsks = Asks.Where(a => a.ExchangeID == exchangeID); modifiedAggregatedAsks = Asks.Except(correspondingAsks).Union(orderBook.Asks); return(new AggregatedOrderBook(modifiedAggregatedBids, modifiedAggregatedAsks)); }