Ejemplo n.º 1
0
        //
        //
        #endregion//Private Event Handlers


        #region Form Event Handlers
        // *****************************************************************
        // ****                     Event Handlers                     ****
        // *****************************************************************
        //
        //
        private void button_Click(object sender, EventArgs e)
        {
            // Validate
            if (!(sender is Button))
            {
                return;
            }
            Button button = (Button)sender;

            //
            // Process button click
            //
            if (button == buttonStart)
            {
                TTApiService service = TTApiService.GetInstance();
                service.Start(this.checkBoxUseXTraderFollowLogin.Checked);
            }
            else if (button == buttonGetProducts)
            {
                int selectedIndex = listBoxMarkets.SelectedIndex;
                if (selectedIndex >= 0 && selectedIndex < listBoxMarkets.Items.Count)
                {
                    listBoxProducts.ClearSelected();                               // deselect any selected products.
                    listBoxProducts.Items.Clear();                                 // remove products from list.
                    m_Market.RequestProducts((string)listBoxMarkets.SelectedItem); // Request new products.
                }
            }
            else if (button == buttonGetInstruments)
            {
                int selectedIndex = listBoxProducts.SelectedIndex;
                if (selectedIndex >= 0 && selectedIndex < listBoxProducts.Items.Count)
                {
                    listBoxInstruments.ClearSelected();                                 // deselect any selected products.
                    listBoxInstruments.Items.Clear();                                   // remove products from list.
                    string  productUniqueName = ((string)listBoxProducts.SelectedItem); // Request new products.
                    Product product;
                    if (m_Products.TryGetValue(productUniqueName, out product))
                    {
                        m_Market.RequestInstruments(product);
                    }
                }
            }
            else if (button == buttonStop)
            {
            }
            else if (button == buttonExit)
            {
                Shutdown();
                this.Close();
            }
            else if (button == buttonUpdate)
            {
                ToggleUpdateState();
                //UpdateMarket();
            }
            else
            {   // unknown button
                return;
            }
        }
Ejemplo n.º 2
0
        }//StoreOrder()

        //
        //
        //
        #endregion // order update handlers


        #region Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        //
        //
        // *****************************************************
        // ****             Try Create New Book()           ****
        // *****************************************************
        private bool TryCreateNewBook(TT.InstrumentKey ttKey, out OrderBookTT book)
        {
            book = null;
            InstrumentName name;

            TT.InstrumentDetails details;
            if (m_Market.TryLookupInstrument(ttKey, out name) && m_Market.TryLookupInstrumentDetails(name, out details))
            {                                       // Market knows this instrument already.
                Log.BeginEntry(LogLevel.Minor, "TryCreateNewBook: Creating book.");
                book = new OrderBookTT(this, name); // Create book.
                double minTickSize = Convert.ToDouble(details.TickSize.Numerator) / Convert.ToDouble(details.TickSize.Denominator);
                book.MinimumPriceTick = minTickSize;
                if (m_Books.TryAdd(book.m_InstrumentName, book))
                {
                    m_TTKey2Name.TryAdd(ttKey, book.m_InstrumentName);

                    Log.AppendEntry(" New book created {0}.", book);
                    Log.EndEntry();
                    return(true);
                }
                else
                {
                    Log.AppendEntry(" Failed to add book to Books.");
                    Log.EndEntry();
                    return(false);
                }
            }
            else
            {                                       // Market doesnt know this instrument yet.
                Log.NewEntry(LogLevel.Minor, "TryCreateNewBook: Market instrument unknown.  Requesting details from market for {0}.", TTConvert.ToString(ttKey));
                m_Market.RequestInstruments(ttKey); // request to look it up.
                return(false);
            }
        }//TryCreateNewBook()