Esempio n. 1
0
        /// <summary>
        /// Deep copies the calling OrderBook to the OrderBook object specified as a parameter.
        /// </summary>
        /// <returns></returns>
        public void CopyInto(OrderBook destinationOrderBook)
        {
            for (int i = 1; i < Depth + 1; i++)
            {
                Ask[i].CopyInto(destinationOrderBook.Ask[i]);
                Bid[i].CopyInto(destinationOrderBook.Bid[i]);
            }

            destinationOrderBook.LastTradedPrice = LastTradedPrice;
            destinationOrderBook.UpdateTime = UpdateTime;
            destinationOrderBook.InstrumentId = InstrumentId;
        }
Esempio n. 2
0
 private void MergeAllDepth(OrderBook impliedOrderBook, int outrightDepth, int impliedDepth)
 {
     MergeBids(impliedOrderBook, outrightDepth, impliedDepth);
     MergeAsks(impliedOrderBook, outrightDepth, impliedDepth);
 }
Esempio n. 3
0
 private void CopyAllDepth(OrderBook outrightOrderBook, int outrightDepth)
 {
     for (int i = 1; i < outrightDepth + 1; i++)
     {
         outrightOrderBook.Bid[i].CopyInto(Bid[i]);
         outrightOrderBook.Ask[i].CopyInto(Ask[i]);
     }
 }
Esempio n. 4
0
        private void MergeAsks(OrderBook impliedOrderBook, int outrightDepth, int impliedDepth)
        {
            int previousMatch = 1;

            for (int i = 1; i < impliedDepth + 1; i++)
            {
                int? impliedPrice = impliedOrderBook.Ask[i].Price;
                if (impliedPrice == null)
                    continue;

                int match = GetMatchingOutrightLevel(Ask, impliedPrice, outrightDepth, ref previousMatch);

                if (match != NOT_FOUND)
                {
                    MergeDepth(impliedOrderBook.Ask[i], Ask[i]);
                }
                else
                {
                    int insertionPoint = FindImpliedAskInsertionPoint(impliedPrice, outrightDepth);

                    if (insertionPoint == NOT_FOUND) 
                        continue;

                    if (Ask[insertionPoint].Price == null)
                    {
                        InsertIntoNullLevel(impliedOrderBook.Ask[i], Ask[insertionPoint]);

                        continue;
                    }

                    InsertIntoNonNullLevel(Ask, impliedOrderBook.Ask[i], outrightDepth, insertionPoint);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Consolidates the implied book and the outright book into a single limit order book.
        /// </summary>
        /// <param name="outrightOrderBook"></param>
        /// <param name="impliedOrderBook"></param>
        public void Consolidate(OrderBook outrightOrderBook, OrderBook impliedOrderBook)
        {
            int outrightDepth = outrightOrderBook.Depth;
            int impliedDepth = impliedOrderBook.Depth;

            CopyAllDepth(outrightOrderBook, outrightDepth);
            MergeAllDepth(impliedOrderBook, outrightDepth, impliedDepth);
            
            outrightOrderBook.LastTradedPrice.CopyInto(LastTradedPrice);

            UpdateTime = (outrightOrderBook.UpdateTime > impliedOrderBook.UpdateTime ? outrightOrderBook.UpdateTime : impliedOrderBook.UpdateTime);
        }