Пример #1
0
        public MarketMakerBidAsk(string MMID)
        {
            this.MMID      = MMID;
            this.Bid       = 0;
            this.BidSize   = 0;
            this.Ask       = 0;
            this.AskSize   = 0;
            this.LastStamp = new DateTime(0);

            BidKey = new LimitBookKey(MMID);
            AskKey = new LimitBookKey(MMID);

            UpdateLimitBookKeys();
        }
Пример #2
0
        public MarketMakerBidAsk(
            string MMID, int Bid, int BidSize, int Ask, int AskSize, DateTime LastStamp)
        {
            this.MMID      = MMID;
            this.Bid       = Bid;
            this.BidSize   = BidSize;
            this.Ask       = Ask;
            this.AskSize   = AskSize;
            this.LastStamp = LastStamp;

            BidKey = new LimitBookKey(MMID);
            AskKey = new LimitBookKey(MMID);

            UpdateLimitBookKeys();
        }
Пример #3
0
        public void Update(MarketDepth md)
        {
            int ix = 0;

            MarketMakerBidAsk mmba       = null;
            MarketMakerBidAsk mmbaInside = null;

            LimitBookKey lbk = null;
            int          quan;

            int price = OneUnified.SmartQuant.Convert.DoublePriceToIntStock(md.Price);

            try {
                bInsideQuoteChanged = false;

                if (!htMMInfo.ContainsKey(md.MarketMaker))
                {
                    // simply add a new entry
                    mmba = new MarketMakerBidAsk(md.MarketMaker);
                    htMMInfo.Add(md.MarketMaker, mmba);
                }
                else
                {
                    // update existing entry after removing from sorted lists
                    mmba = (MarketMakerBidAsk)htMMInfo[md.MarketMaker];

                    // remove key from sorted arrays

                    switch (md.Side)
                    {
                    case MDSide.Bid:
                        if (mmba.BidSize > 0)
                        {
                            lbk = mmba.BidKey;
                            ix  = slBid.IndexOfKey(lbk);
                            slBid.RemoveAt(ix);
                            ActiveBidRows--;
                            if (0 < slBid.Count)
                            {
                                // get new inside bid if records remaining in order book
                                if (0 == ix)
                                {
                                    mmbaInside = ( MarketMakerBidAsk )slBid.GetByIndex(0);
                                }
                            }
                            // update price table
                            ix   = slBidPrice.IndexOfKey(mmba.Bid);
                            quan = ( int )slBidPrice.GetByIndex(ix);
                            if (quan == mmba.BidSize)
                            {
                                quan = 0;
                                slBidPrice.RemoveAt(ix);
                            }
                            else
                            {
                                quan -= mmba.BidSize;
                                slBidPrice.SetByIndex(ix, quan);
                            }
                            if (null != BidPriceBookRowChanged)
                            {
                                BidPriceBookRowChanged(this, mmba.Bid, quan);
                            }
                        }
                        else
                        {
                            Console.WriteLine("ob bid remove problem bs:{0}, bid:{1}, price:{2}, MM:{3}", mmba.BidSize, mmba.Bid, price, md.MarketMaker);
                        }
                        break;

                    case MDSide.Ask:
                        if (mmba.AskSize > 0)
                        {
                            lbk = mmba.AskKey;
                            ix  = slAsk.IndexOfKey(lbk);
                            slAsk.RemoveAt(ix);
                            ActiveAskRows--;
                            if (0 < slAsk.Count)
                            {
                                // get new inside ask if records remaining in order book
                                if (0 == ix)
                                {
                                    mmbaInside = ( MarketMakerBidAsk )slAsk.GetByIndex(0);
                                }
                            }
                            // update price table
                            ix   = slAskPrice.IndexOfKey(mmba.Ask);
                            quan = ( int )slAskPrice.GetByIndex(ix);
                            if (quan == mmba.AskSize)
                            {
                                quan = 0;
                                slAskPrice.RemoveAt(ix);
                            }
                            else
                            {
                                quan -= mmba.AskSize;
                                slAskPrice.SetByIndex(ix, quan);
                            }
                            if (null != AskPriceBookRowChanged)
                            {
                                AskPriceBookRowChanged(this, mmba.Ask, quan);
                            }
                        }
                        else
                        {
                            Console.WriteLine("ob ask remove problem as:{0}, ask:{1}, price:{2}, MM:{3}", mmba.AskSize, mmba.Ask, price, md.MarketMaker);
                        }
                        break;
                    }
                }

                switch (md.Side)
                {
                case MDSide.Bid:
                    mmba.UpdateBid(md.DateTime, price, md.Size);
                    if (md.Size > 0)
                    {
                        lbk = mmba.BidKey;
                        slBid.Add(lbk, mmba);
                        ActiveBidRows++;
                        mmba.BidActivity++;
                        MarketMakerBidAsk mmbaTmp = (MarketMakerBidAsk)slBid.GetByIndex(0);
                        if (mmba.MMID == mmbaTmp.MMID)
                        {
                            mmbaInside = mmbaTmp;
                        }
                        // update price table
                        if (slBidPrice.ContainsKey(price))
                        {
                            ix    = slBidPrice.IndexOfKey(price);
                            quan  = (int)slBidPrice.GetByIndex(ix);
                            quan += md.Size;
                            slBidPrice.SetByIndex(ix, quan);
                        }
                        else
                        {
                            quan = md.Size;
                            slBidPrice.Add(price, quan);
                        }
                        if (null != BidPriceBookRowChanged)
                        {
                            BidPriceBookRowChanged(this, price, quan);
                        }
                    }
                    if (null != mmbaInside)
                    {
                        mmbaInside.BidInside++;
                        bInsideQuoteChanged = true;
                    }
                    break;

                case MDSide.Ask:
                    mmba.UpdateAsk(md.DateTime, price, md.Size);
                    if (md.Size > 0)
                    {
                        lbk = mmba.AskKey;
                        slAsk.Add(lbk, mmba);
                        ActiveAskRows++;
                        mmba.AskActivity++;
                        MarketMakerBidAsk mmbaTmp = (MarketMakerBidAsk)slAsk.GetByIndex(0);
                        if (mmba.MMID == mmbaTmp.MMID)
                        {
                            mmbaInside = mmbaTmp;
                        }
                        // update price table
                        if (slAskPrice.ContainsKey(price))
                        {
                            ix    = slAskPrice.IndexOfKey(price);
                            quan  = (int)slAskPrice.GetByIndex(ix);
                            quan += md.Size;
                            slAskPrice.SetByIndex(ix, quan);
                        }
                        else
                        {
                            quan = md.Size;
                            slAskPrice.Add(price, quan);
                        }
                        if (null != AskPriceBookRowChanged)
                        {
                            AskPriceBookRowChanged(this, price, quan);
                        }
                    }
                    if (null != mmbaInside)
                    {
                        mmbaInside.AskInside++;
                        bInsideQuoteChanged = true;
                    }
                    break;
                }
                if (bInsideQuoteChanged)
                {
                    if (null != InsideQuoteChangedEventHandler)
                    {
                        InsideQuoteChangedEventHandler(this, EventArgs.Empty);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine("UpdateDataStructures problem {0}", e);
            }
            finally {
            }
        }