示例#1
0
        }// ProcessOrderAdded

        //
        //
        private void ProcessOrderDeleted(TT.OrderDeletedEventArgs eventArg)
        {
            Log.BeginEntry(LogLevel.Minor, "ProcessOrderDeleted:");
            OrderBookEventArgs outgoingEventArg = null;                 // outgoing event, if needed.

            TT.Order       ttOrder = eventArg.OldOrder;
            InstrumentName name;
            OrderBook      baseBook;

            if (m_TTKey2Name.TryGetValue(ttOrder.InstrumentKey, out name) && this.TryEnterBookWrite(name, out baseBook))
            {
                OrderBookTT book = (OrderBookTT)baseBook;
                string      tag;
                if (book.m_TagTT2Bre.TryGetValue(ttOrder.SiteOrderKey, out tag))
                {
                    Order deletedOrder;
                    if (book.TryDeleteOrder(tag, out deletedOrder))
                    {
                        outgoingEventArg       = new OrderBookEventArgs(this, name, OrderBookEventArgs.EventTypes.DeletedOrder); // Load out-going eventArg
                        outgoingEventArg.Order = deletedOrder;
                        Log.AppendEntry(" Deleted order {0} to book {1}.", deletedOrder, book);
                    }
                }
                this.ExitBookWrite(baseBook);
            }
            Log.EndEntry();
            if (outgoingEventArg != null)
            {
                OnBookChanged(outgoingEventArg);
            }
        }// ProcessOrderDelete()
示例#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()
示例#3
0
        }// ProcessMarketFoundResource()

        //
        //
        //
        #endregion//Private HubEvent Handler


        #region Private Order Update Handlers
        // *****************************************************************
        // ****             Private Order Update Handlers               ****
        // *****************************************************************
        //
        //
        private void ProcessOrderAdded(TT.OrderAddedEventArgs eventArg)
        {
            Log.BeginEntry(LogLevel.Minor, "ProcessOrderAdded:");
            OrderBookEventArgs outgoingEventArg = null;

            TT.Order       ttOrder = eventArg.Order;
            InstrumentName name;
            OrderBook      book;

            if (m_TTKey2Name.TryGetValue(ttOrder.InstrumentKey, out name) && this.TryEnterBookWrite(name, out book))
            {   // We know this TTKey, and have an associated book!
                OrderBookTT booktt   = (OrderBookTT)book;
                Order       newOrder = booktt.CreateNewOrder();
                int         mktSign  = Misty.Lib.Utilities.QTMath.BuySign;
                newOrder.Side = Misty.Lib.Utilities.QTMath.BuySide;
                if (ttOrder.BuySell == TT.BuySell.Sell)
                {
                    mktSign       = Misty.Lib.Utilities.QTMath.SellSign;
                    newOrder.Side = Misty.Lib.Utilities.QTMath.SellSide;
                }
                newOrder.Qty    = mktSign * ttOrder.WorkingQuantity.ToInt();
                newOrder.IPrice = (int)Math.Round(ttOrder.LimitPrice.ToDouble() / book.MinimumPriceTick);
                int intPrice = ttOrder.LimitPrice.ToInt();  // for debugging
                if (book.TryAddOrder(newOrder))
                {
                    booktt.m_TagBre2TT.Add(newOrder.Tag, ttOrder.SiteOrderKey);
                    booktt.m_TagTT2Bre.Add(ttOrder.SiteOrderKey, newOrder.Tag);
                    outgoingEventArg       = new OrderBookEventArgs(this, name, OrderBookEventArgs.EventTypes.NewOrder); // Load out-going eventArg
                    outgoingEventArg.Order = newOrder;
                    Log.AppendEntry(" Added new order {0} to book {2}.", newOrder, ttOrder, book);
                }
                else
                {
                    Log.AppendEntry(" Failed to add order {0} to book {2}. Store order for later.", newOrder, ttOrder, book);
                    StoreTTEvent(eventArg, ttOrder.InstrumentKey);
                }
                this.ExitBookWrite(book);
            }
            else
            {                                                  // We have no book for this instrument.
                StoreTTEvent(eventArg, ttOrder.InstrumentKey); // Store order and request mkt details.
            }
            Log.EndEntry();
            if (outgoingEventArg != null)
            {
                OnBookChanged(outgoingEventArg);
            }
        }// ProcessOrderAdded