Esempio n. 1
0
        private static bool HasIntervalThatIsSubsetOfInterval(
            C5.TreeDictionary <ulong, ulong> regions,
            ulong regionStart,
            ulong regionEnd)
        {
            // Is there any region in whose [start, end] interval is a sub-interval of
            // [regionStart, regionEnd]?
            // TryWeakSuccessor gives us the first region whose start is >= regionStart,
            // but there could be more regions with start >= regionStart and end <= regionEnd.
            // Need to traverse successors until start > regionEnd, making containment impossible.
            C5.KeyValuePair <ulong, ulong> range;
            if (regions.TryWeakSuccessor(regionStart, out range))
            {
                if (range.Key >= regionStart && range.Value <= regionEnd)
                {
                    return(true);
                }
            }
            while (regions.TrySuccessor(range.Key, out range))
            {
                if (range.Key > regionEnd)
                {
                    break;
                }

                if (range.Key >= regionStart && range.Value <= regionEnd)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        public double getAskPrice(double vol)
        {
            if (_asks.Count > 0)
            {
                double vtot   = 0.0;
                bool   virgin = true;
                double p      = -1.0;
                //Console.WriteLine ("********************************************");
                do
                {
                    if (virgin)
                    {
                        p      = (double)_asks.FindMin().Key;
                        virgin = false;
                    }
                    else
                    {
                        C5.KeyValuePair <double, IList <IOrder_Mutable> > kvp;
                        if (_asks.TrySuccessor(p, out kvp))
                        {
                            double newp = kvp.Key;
                            if (newp == p)
                            {
                                Console.WriteLine("newp = p = " + p);
                                Console.WriteLine("Orderbook = " + this.ToStringLong());
                                Environment.Exit(-1);
                            }

                            p = newp;
                        }
                        else
                        {
                            Console.WriteLine("ORDERBOOK ASYMMETRY CONDITION in getAskPrice, searching for AskPrice to capture BidVolume = " + vol);
                            Console.WriteLine("Orderbook = " + this.ToStringLong());
                            Environment.Exit(-1);

                            return(p + PUSH_OUT_FACTOR * (p - getLowestAsk()));
                        }
                    }

                    IList <IOrder_Mutable> orders = _asks[p];
                    foreach (IOrder_Mutable o in orders)
                    {
                        if (!o.isFilled() && !o.isCancelled())
                        {
                            vtot += o.getVolume();
                            if (vtot >= vol)
                            {
                                return(p);
                            }
                        }
                    }
                    //Console.WriteLine ("* xxx p="+p);
                }while (true);
            }
            return(-1.0);
        }