/// <summary>
 /// Name		: doMod
 /// Description	: Modify an existing event in the market depth cache.
 ///               Find the cached market depth entry by the position in
 ///               new the market depth cache and replace the cached event
 ///               by the fields and data in the new event.
 /// </summary>
 /// <param name="pos">position to be modified</param>
 /// <param name="entry">new book entry</param>
 public void doMod(int pos, ref BookEntry entry)
 {
     lock (d_entries)
     {
         d_entries[pos] = entry;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Name		: doReplaceByBroker
        /// Description	: This table command is used for top of file feeds
        ///               where the action is to replace by the broker mnemonic.
        ///               The recipient needs to find the broker in their cache
        ///               and replace the quote with the one in the market depth event.
        ///               If that broker is not present, it should added to the cache.
        ///               If the price and size for a broker is set to 0,
        ///               the broker should be deleted from the cache.
        /// </summary>
        /// <param name="entry">new book entry</param>
        public void doReplaceByBroker(ref BookEntry entry)
        {
            lock (d_entries)
            {
                if (entry.Price == 0 && entry.Size == 0)
                {
                    doDeleteByBroker(entry.Broker);
                    return;
                }

                bool brokerFound = false;
                for (int index = 0; index < d_entries.Count; ++index)
                {
                    if (d_entries[index].Broker == entry.Broker)
                    {
                        // replace broker entry
                        d_entries[index] = entry;
                        brokerFound      = true;
                        break;
                    }
                }
                if (!brokerFound)
                {
                    // add broker entry
                    d_entries.Add(entry);
                }
            }
        }
 /// <summary>
 /// Name		: BookEntry copy constructor
 /// Description	: Copy constructor for ByLevelBookEntry
 /// </summary>
 /// <param name="copy">BookEntry to be copied</param>
 public BookEntry(BookEntry copy)
 {
     Price        = copy.Price;
     Time         = copy.Time;
     NumberOrders = copy.NumberOrders;
     Size         = copy.Size;
     IsValid      = copy.IsValid;
 }
 /// <summary>
 /// Name		: doExec
 /// Description	: Trade Execution. Find the corresponding order in the cache
 ///               replace the entry with the new entry and delete orders with
 ///               greater priority
 /// </summary>
 /// <param name="pos">position to be modified</param>
 /// <param name="entry">new book entry</param>
 public void doExec(int pos, ref BookEntry entry)
 {
     lock (d_entries)
     {
         d_entries[pos] = entry;
         if (pos != 0)
         {
             d_entries.RemoveRange(0, pos);
         }
     }
 }
 /// <summary>
 ///  Name			: doReplace
 ///  Description	: Replace previous price level or order at this position.
 ///                   Add price level or order if you do not have it currently in
 ///                   the cache. A 0 price and size will be sent when there is
 ///                   no active price or order at this level.
 /// </summary>
 /// <param name="pos">position to be modified</param>
 /// <param name="entry">new book entry</param>
 public void doReplace(int pos, ref BookEntry entry)
 {
     lock (d_entries)
     {
         if (d_entries.Count <= pos)
         {
             // fill in entries
             for (int i = d_entries.Count; i <= pos; ++i)
             {
                 d_entries.Add(new BookEntry());
             }
         }
         d_entries[pos] = entry;
     }
 }
 /// <summary>
 /// Name		: doAdd
 /// Description	: Add an entry to the order book.
 ///               When you add this order in the market depth table,
 ///               you should shift all orders at the market depth position
 ///               in the event and market depth orders or levels inferior to
 ///               event passed to one position inferior.
 ///               For example, if a new order is added to position one of the
 ///               market depth table, then the previous order at position one is
 ///               shifted to position two. The order at position two is shifted to
 ///               position three and so on until you get to the market depth window size.
 /// </summary>
 /// <param name="pos">position to add the entry</param>
 /// <param name="entry">entry to add</param>
 public void doAdd(int pos, BookEntry entry)
 {
     lock (d_entries)
     {
         if (d_entries.Count < pos)
         {
             // gap detected
             System.Console.WriteLine("Gap detected in cache for level " + (pos + 1) +
                                      ". Cache size is " + d_entries.Count + ".");
             return;
         }
         d_entries.Insert(pos, entry);
         if (WindowSize < d_entries.Count)
         {
             //remove entries > window size
             d_entries.RemoveRange(WindowSize, d_entries.Count - WindowSize);
         }
     }
 }
 /// <summary>
 /// Name		: doReplaceClear
 /// Description	: The REPLACE_CLEAR table command is intended to remove an order or
 ///               more often a level in the market depth cache. The REPLACE_CLEAR
 ///               should be indexed by the MarketDepth.ByLevel/ByOrder.Bid/Ask.Position
 ///               field. The cache should NOT be shifted up after the level is
 ///               cleared. A clear means all orders at that position have been deleted
 ///               from the orderbook. It is possible that a order or level at a
 ///               superior or most superior position to be cleared prior to more
 ///               inferior levels. After the level is cleared in this case, it is
 ///               expected that subsequent market depth event(s) will be passed
 ///               to clear the orders or levels at positions inferior to the one just
 ///               cleared.
 /// </summary>
 /// <param name="pos">position to be modified</param>
 public void doReplaceClear(int pos)
 {
     lock (d_entries)
     {
         if (d_entries.Count <= pos)
         {
             // fill in entries
             for (int i = d_entries.Count; i <= pos; ++i)
             {
                 d_entries.Add(new BookEntry());
             }
         }
         else
         {
             BookEntry entry = new BookEntry();
             d_entries[pos] = entry;
         }
     }
 }
        /// <summary>
        /// Name		: getEtnry
        /// Description	: Returns the entry at the specified position
        /// </summary>
        /// <param name="pos">position of the entry</param>
        /// <returns>true is the cache is valid, false if the cache is invalid</returns>
        public BookEntry getEntry(int pos)
        {
            BookEntry entry = null;

            lock (d_entries)
            {
                if (pos >= d_entries.Count)
                {
                    entry = null;
                }
                else
                {
                    entry = d_entries[pos];
                    if (!entry.IsValid)
                    {
                        // invalid entry
                        entry = null;
                    }
                }
            }
            return(entry);
        }