} //HubEventHandler() // // #endregion//Private Methods #region Processing Methods // ***************************************************************** // **** Processing Methods **** // ***************************************************************** // // // // ***************************************** // **** ProcessCreateBook() **** // ***************************************** /// <summary> /// Process to initialize a single order book. /// </summary> /// <param name="request"></param> private void ProcessCreateBook(RequestEventArg <RequestCode> request) { // Extract order book and validate request. if (request.Data.Count < 1) { Log.NewEntry(LogLevel.Warning, "ProcessCreateBook: Fail to find book in request."); return; } OrderBookTT orderBook = request.Data[0] as OrderBookTT; if (orderBook == null) { Log.NewEntry(LogLevel.Warning, "ProcessCreateBook: Fail to find valid order book in request."); return; } // Locate the OrderInstrument for this book. OrderInstrument orderInstrument = null; if (!m_OrderInstruments.TryGetValue(orderBook.Instrument, out orderInstrument)) { // We do not have an order instrument for this Instrument. InstrumentDetails instrumentDetails; if (!m_Market.TryGetInstrumentDetails(orderBook.Instrument, out instrumentDetails)) { // We don't know this instrument yet. // Request information from market, and set this to pending. Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Requesting instrument details for {0} OrderBookID {1}. Will try again later.", orderBook.Instrument, orderBook.BookID); m_Market.RequestInstruments(orderBook.Instrument); m_PendingQueue.AddPending(request, 2); return; } else { // We have the instrument details, so create the OrderInstrument now Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Attempting to Process OrderBookID {0}", orderBook.BookID); orderInstrument = new OrderInstrument(orderBook.Instrument, instrumentDetails, m_OrderRecycleFactory); TradingTechnologies.TTAPI.InstrumentDetails ttDetails; if (m_Market.TryLookupInstrumentDetails(orderBook.Instrument, out ttDetails)) { m_InstrumentNameToTTKey[orderBook.Instrument] = ttDetails.Key; } if (m_OrderInstruments.TryAdd(orderBook.Instrument, orderInstrument)) { Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Created new OrderInstrument {0}.", orderBook.Instrument); } else { // This could only happen if the orderInstrument somehow just now showed up spontaneously. // That could happen if we allow other threads to add new OrderInstruments to list. Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Failed to add new OrderInstrument {0}. Will try again later.", orderBook.Instrument); m_PendingQueue.AddPending(request, 1); return; } } // If we get here, lets try to add our new book to the order instrument. TTKey ttKey; if (orderInstrument != null && orderInstrument.TryAddBook(orderBook) && m_InstrumentNameToTTKey.TryGetValue(orderBook.Instrument, out ttKey)) { Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Added book {0} into OrderInstrument {1}.", orderBook.BookID, orderInstrument); m_Listener.SubscribeToInstrument(ttKey); } } else { Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Exisiting OrderInstrument {0} found. Attempting to add OrderBookID {1}", orderInstrument.Instrument, orderBook.BookID); orderInstrument.TryAddBook(orderBook); } }// ProcessCreateBook()
}// TryChangeOrderQty() // // // ***************************************** // **** ProcessCreateBook() **** // ***************************************** /// <summary> /// Process to initialize a single order book. /// </summary> /// <param name="orderBook"></param> protected override void ProcessCreateBook(OrderBook orderBook) { // Locate the OrderInstrument for this book. OrderInstrument orderInstrument = null; if (!m_ExecContainer.m_OrderInstruments.TryGetValue(orderBook.Instrument, out orderInstrument)) { // We do not have an order instrument for this Instrument. InstrumentDetails instrumentDetails; if (!m_UVInstrumentDetails.TryGetValue(orderBook.Instrument, out instrumentDetails)) { // We don't know this instrument yet. // Request information from market, and set this to pending. Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Requesting instrument details for {0} OrderBookID {1}. Will try again later.", orderBook.Instrument, orderBook.BookID); SubscribeTo(orderBook.Instrument); if (m_PendingOrderBooks.ContainsKey(orderBook.Instrument)) { // we have other order books waiting on this instrument details, just add to the list m_PendingOrderBooks[orderBook.Instrument].Add(orderBook); } else { // we don't have anything waiting on this instrument yet, so create a new list. m_PendingOrderBooks[orderBook.Instrument] = new List <OrderBook> { orderBook }; } return; } else { // We have the instrument details, so create the OrderInstrument now Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Attempting to Process OrderBookID {0}", orderBook.BookID); orderInstrument = new OrderInstrument(orderBook.Instrument, instrumentDetails); m_ExecContainer.m_OrderInstruments.Add(orderBook.Instrument, orderInstrument); Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Created new OrderInstrument {0}.", orderBook.Instrument); //int instrId = -1; //if (m_Market != null && m_Market.TryLookupInstrumentID(orderBook.Instrument, out instrId) == false) //{ // Subscribe to this market instrument. // // Order sim needs market updates for each instrument with orders. // m_Market.RequestInstrumentSubscription(orderBook.Instrument); //} } // If we get here, lets try to add our new book to the order instrument. if (orderInstrument != null) { orderInstrument.TryAddBook(orderBook); // Simulator also needs to keep a copy of all books to simulate fills. List <OrderBook> orderBookList = null; if (!m_SimOrderBooks.TryGetValue(orderInstrument.Instrument, out orderBookList)) { orderBookList = new List <OrderBook>(); m_SimOrderBooks.Add(orderInstrument.Instrument, orderBookList); } orderBookList.Add(orderBook); } } else { Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Exisiting OrderInstrument {0} found. Attempting to add OrderBookID {1}", orderInstrument.Instrument, orderBook.BookID); orderInstrument.TryAddBook(orderBook); // Simulator also needs to keep a copy of all books to simulate fills. List <OrderBook> orderBookList = null; if (!m_SimOrderBooks.TryGetValue(orderInstrument.Instrument, out orderBookList)) { orderBookList = new List <OrderBook>(); m_SimOrderBooks.Add(orderInstrument.Instrument, orderBookList); } orderBookList.Add(orderBook); } }// ProcessCreateBook()
}//ProcessServiceStateChange() // // // // ***************************************** // **** ProcessCreateBook() **** // ***************************************** /// <summary> /// Process to initialize a single order book. /// </summary> /// <param name="request"></param> private void ProcessCreateBook(RequestEventArg <RequestCode> request) { // Extract order book and validate request. if (request.Data.Count < 1) { Log.NewEntry(LogLevel.Warning, "ProcessCreateBook: Fail to find book in request."); return; } OrderBook orderBook = request.Data[0] as OrderBook; if (orderBook == null) { Log.NewEntry(LogLevel.Warning, "ProcessCreateBook: Fail to find valid order book in request."); return; } // Locate the OrderInstrument for this book. OrderInstrument orderInstrument = null; if (!m_OrderInstruments.TryGetValue(orderBook.Instrument, out orderInstrument)) { // We do not have an order instrument for this Instrument. InstrumentDetails instrumentDetails; if (!m_Market.TryGetInstrumentDetails(orderBook.Instrument, out instrumentDetails)) { // We don't know this instrument yet. // Request information from market, and set this to pending. Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Requesting instrument details for {0} OrderBookID {1}. Will try again later.", orderBook.Instrument, orderBook.BookID); m_Market.RequestInstruments(orderBook.Instrument); m_PendingQueue.AddPending(request, 2); return; } else { // We have the instrument details, so create the OrderInstrument now Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Attempting to Process OrderBookID {0}", orderBook.BookID); orderInstrument = new OrderInstrument(orderBook.Instrument, instrumentDetails, m_OrderRecycleFactory); if (m_OrderInstruments.TryAdd(orderBook.Instrument, orderInstrument)) { Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Created new OrderInstrument {0}.", orderBook.Instrument); int instrId = -1; if (m_Market != null && m_Market.TryLookupInstrumentID(orderBook.Instrument, out instrId) == false) { // Subscribe to this market instrument. // Order sim needs market updates for each instrument with orders. m_Market.RequestInstrumentSubscription(orderBook.Instrument); } } else { // This could only happen if the orderInstrument somehow just now showed up spontaneously. // That could happen if we allow other threads to add new OrderInstruments to list. Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Failed to add new OrderInstrument {0}. Will try again later.", orderBook.Instrument); m_PendingQueue.AddPending(request, 1); return; } } // If we get here, lets try to add our new book to the order instrument. if (orderInstrument != null) { orderInstrument.TryAddBook(orderBook); // Simulator also needs to keep a copy of all books to simulate fills. List <OrderBook> orderBookList = null; if (!m_SimOrderBooks.TryGetValue(orderInstrument.Instrument, out orderBookList)) { orderBookList = new List <OrderBook>(); m_SimOrderBooks.Add(orderInstrument.Instrument, orderBookList); } orderBookList.Add(orderBook); } } else { Log.NewEntry(LogLevel.Minor, "ProcessCreateBook: Exisiting OrderInstrument {0} found. Attempting to add OrderBookID {1}", orderInstrument.Instrument, orderBook.BookID); orderInstrument.TryAddBook(orderBook); // Simulator also needs to keep a copy of all books to simulate fills. List <OrderBook> orderBookList = null; if (!m_SimOrderBooks.TryGetValue(orderInstrument.Instrument, out orderBookList)) { orderBookList = new List <OrderBook>(); m_SimOrderBooks.Add(orderInstrument.Instrument, orderBookList); } orderBookList.Add(orderBook); } }// ProcessCreateBook()