コード例 #1
0
        }//listBoxMarkets_SelectedIndexChanged()

        /// <summary>
        /// When the selected index for the product changes, it should show the instruments for that product.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBoxProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Wait the response above and subscribe to every spread instrument under that spread product.
            m_FutureInstruments.Clear();
            m_SpreadInstruments.Clear();
            string selectedProduct = listBoxProducts.SelectedItem.ToString();

            // When the selected product changes, it subscribe to the instruments.
            if (string.IsNullOrEmpty(selectedProduct))
            {
                Log.NewEntry(LogLevel.Warning, "The program does not have a selected spread product.");
                return;
            }
            else
            {
                // Subscribe to the future instruments.
                if (!m_FutureProducts.ContainsKey(selectedProduct))
                {
                    Log.NewEntry(LogLevel.Warning, "The selected spread is not contained in the future dictionary.");
                    return;
                }
                else
                {
                    if (!m_MarketTTAPI.RequestInstruments(m_FutureProducts[selectedProduct]))
                    {
                        Log.NewEntry(LogLevel.Warning, "Send instruments request for future term structure failed.");
                        return;
                    }
                }

                // Subscribe to the spread instruments.
                if (!m_SpreadProducts.ContainsKey(selectedProduct))
                {
                    Log.NewEntry(LogLevel.Warning, "The selected spread is not contained in the spread dictionary.");
                    return;
                }
                else
                {
                    if (!m_MarketTTAPI.RequestInstruments(m_SpreadProducts[selectedProduct]))
                    {
                        Log.NewEntry(LogLevel.Warning, "Send instruments request for spread term structure failed.");
                        return;
                    }
                }

                Log.NewEntry(LogLevel.Minor, "Successfully send request for the instruments search for product {0}.", selectedProduct);
            }
        }//listBoxProducts_SelectedIndexChanged()
コード例 #2
0
        /// <summary>
        /// In the time to not connect to TT, the developer may choose this method to create books.
        /// </summary>
        public void CreateBooksStatic(MarketTTAPI marketTTAPI)
        {
            // Create books for all the instruments without connecting to TT and using start method.
            MarketHub = marketTTAPI;

            foreach (BookLifo book in m_FillBooks.Values)
            {
                PositionBookChangedEventArgs eventArgs = new PositionBookChangedEventArgs();
                eventArgs.Instrument = book.Name;
                eventArgs.Sender     = this;
                OnPositionBookCreated(eventArgs);
                MarketHub.RequestInstruments(m_BookNameMap[book.Name].Key);
            }
        }
コード例 #3
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()