Exemplo n.º 1
0
        public bool Remove(DepthInfo di)
        {
            bool removed = false;

            if (MarketMakers.ContainsKey(di.Depth.MarketMaker))
            {
                DepthInfo tmp = MarketMakers[di.Depth.MarketMaker];
                if (tmp == di)
                {
                    int size = tmp.Depth.Size;
                    m_quantity -= size;                        // remove affect of market maker
                    //tmp.Object.Node.List.Remove(tmp.Object.Node);  // remove this node from list:  already removed
                    MarketMakers.Remove(di.Depth.MarketMaker); // then remove market maker entry
                    removed = true;
                }
            }
            return(removed);
        }
Exemplo n.º 2
0
        public void Update(DepthInfo di)
        {
            MarketDepth md = di.Depth;

            // check for market maker, add if not present
            // what is best?  keep removing and creating lbse's, or leave them there and just set to zero when nothing?
            if (0 == md.Size)
            {
                // remove market maker entry
                if (MarketMakers.ContainsKey(md.MarketMaker))
                {
                    DepthInfo tmp  = MarketMakers[md.MarketMaker];
                    int       size = tmp.Depth.Size;
                    m_quantity -= size;                           // remove affect of market maker
                    tmp.Object.Node.List.Remove(tmp.Object.Node); // remove this node from list
                    MarketMakers.Remove(md.MarketMaker);          // then remove market maker entry
                }
                else
                {
                    //Console.WriteLine( "0 size but market maker {0} does not exist at {1:0.00}", md.MarketMaker, md.Price );
                }
            }
            else
            {
                // add or update the market maker entry
                if (MarketMakers.ContainsKey(md.MarketMaker))
                {
                    DepthInfo tmp  = MarketMakers[md.MarketMaker];
                    int       size = tmp.Depth.Size;
                    m_quantity -= size;
                    tmp.Object.Node.List.Remove(tmp.Object.Node);
                    MarketMakers[md.MarketMaker] = di; // replace expired entry with new entry
                    m_quantity += md.Size;
                }
                else
                {
                    MarketMakers.Add(md.MarketMaker, di);
                    m_quantity += md.Size;
                }
            }
        }
Exemplo n.º 3
0
        protected override ObjectAtTime Remove()
        {
            LimitBookEntry lbe;
            int            keyindex;

            ObjectAtTime oat = base.Remove();
            DepthInfo    di  = (DepthInfo)oat.Object;

            if (entries.ContainsKey(di.Level))
            {
                keyindex = entries.IndexOfKey(di.Level);
                lbe      = entries.Values[keyindex];
                bool removed = lbe.Remove(di);

                if (removed)
                {
                    if (null != PriceBookRowChanged)
                    {
                        PriceBookRowChanged(this, di.Level, lbe.Price, lbe.Size);
                    }

                    // if level has no active depth markers, remove it
                    if (0 == lbe.Size)
                    {
                        entries.RemoveAt(keyindex);
                        if (0 == keyindex)
                        {
                            //LoChanged++;
                        }
                        if (entries.Count == keyindex) // matches without the '-1' with the removal
                        //HiChanged++;
                        {
                        }
                    }
                }
            }

            // handle instance where depth entry has expired
            return(oat);
        }
Exemplo n.º 4
0
        public void Update(MarketMakerStats mms, MarketDepth md)
        {
            int            keyindex;
            int            level;
            double         price = md.Price;
            LimitBookEntry lbe;
            int            HiChanged = 0;
            int            LoChanged = 0;

            lock (entries) {
                level = OneUnified.SmartQuant.Convert.DoublePriceToIntStock(md.Price);

                DepthInfo di = new DepthInfo(mms, md, level);

                // obtain level at which depth is used
                if (entries.ContainsKey(level))
                {
                    keyindex = entries.IndexOfKey(level);
                    lbe      = entries.Values[keyindex];
                }
                else
                {
                    lbe = new LimitBookEntry(level, md.Price);
                    entries.Add(level, lbe);
                    keyindex = entries.IndexOfKey(level);
                }

                // update the level, and signal change event
                //lbe.Update(mms, md);
                di.Object = base.Add(md.DateTime, di);
                lbe.Update(di);
                if (null != PriceBookRowChanged)
                {
                    PriceBookRowChanged(this, level, lbe.Price, lbe.Size);
                }

                // used for indicating inside quote changed (is this useful due to problems with expiration?)
                if (0 == keyindex)
                {
                    LoChanged++;
                }
                if (entries.Count - 1 == keyindex)
                {
                    HiChanged++;
                }

                // if level has no active depth markers, remove it
                if (0 == lbe.Size)
                {
                    entries.RemoveAt(keyindex);
                    if (0 == keyindex)
                    {
                        LoChanged++;
                    }
                    if (entries.Count == keyindex) // matches without the '-1' with the removal
                    {
                        HiChanged++;
                    }
                }

                // signal event that inside quote has changed (again, not sure if this will actually work properly,
                //   as we are using quotes to clear this stuff out.
                if (entries.Count > 0)
                {
                    if (0 < HiChanged)
                    {
                        // highest changed so indicate as such, other code will determine if it is a new inside or not
                        int ix = entries.Count - 1;
                        if (null != PriceBookHiEdgeChanged)
                        {
                            PriceBookHiEdgeChanged(this, ix, entries.Keys[ix], entries.Values[ix].Price);
                        }
                    }
                    if (0 < LoChanged)
                    {
                        // lowest changed so indicate as such, other code will determine if it is a new inside or not
                        if (null != PriceBookLoEdgeChanged)
                        {
                            PriceBookLoEdgeChanged(this, 0, entries.Keys[0], entries.Values[0].Price);
                        }
                    }
                }
                ;
            }
        }