Example #1
0
        //
        //
        #endregion//Constructors

        #region no Properties
        // *****************************************************************
        // ****                     Properties                          ****
        // *****************************************************************
        //
        //
        #endregion//Properties

        #region Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        //
        // **********************************************
        // ****         CreateOrderBook()            ****
        // **********************************************
        /// <summary>
        /// External caller request for an order book for a specific instrument.
        /// Once he has the order book, he can subscribe to its events for updates
        /// and
        /// See base class explanation.
        /// </summary>
        /// <param name="instrumentName"></param>
        /// <returns></returns>
        public override OrderBook CreateOrderBook(InstrumentName instrumentName)
        {
            OrderBookTT orderBook = new OrderBookTT(instrumentName, m_OrderRecycleFactory);

            this.HubEventEnqueue(m_Requests.Get(RequestCode.CreateBook, orderBook));
            return(orderBook);
        }//CreateOrderBook()
Example #2
0
        }     //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()