Ejemplo n.º 1
0
        public double getBidPrice(double vol)
        {
            if (_bids.Count > 0)
            {
                double vtot   = 0.0;
                bool   virgin = true;
                double p      = -1.0;
                //Console.WriteLine ("********************************************");
                do
                {
                    if (virgin)
                    {
                        p      = (double)_bids.FindMax().Key;
                        virgin = false;
                    }
                    else
                    {
                        C5.KeyValuePair <double, IList <IOrder_Mutable> > kvp;
                        if (_bids.TryPredecessor(p, out kvp))
                        {
                            double newp = kvp.Key;
                            if (newp == p)
                            {
                                Console.WriteLine("newp = p = " + p);
                                Console.WriteLine("Orderbook = " + this.ToStringLong());
                                Environment.Exit(-1);
                            }
                            else
                            {
                                //Console.WriteLine ("newp = "+newp+" != p = "+p);
                            }

                            p = newp;
                        }
                        else
                        {
                            Console.WriteLine("ORDERBOOK IMBALANCE CONDITION in getBidPrice, searching for BidPrice to capture AskVolume = " + vol);
                            Console.WriteLine("Orderbook = " + this.ToStringLong());
                            throw new Exception("frobby");

                            // return p - PUSH_OUT_FACTOR * (getHighestBid() - p);
                        }
                    }

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