Example #1
0
        public Quote GetQuote(int level)
        {
            DateTime datetime = DateTime.MinValue;
            double   bid      = 0.0;
            double   ask      = 0.0;
            int      bidSize  = 0;
            int      askSize  = 0;

            if (level < this.bidList.Count)
            {
                OrderBookEntry orderBookEntry = this.bidList[level];
                bid     = orderBookEntry.Price;
                bidSize = orderBookEntry.Size;
                if (orderBookEntry.DateTime > datetime)
                {
                    datetime = orderBookEntry.DateTime;
                }
            }
            if (level < this.askList.Count)
            {
                OrderBookEntry orderBookEntry = this.askList[level];
                ask     = orderBookEntry.Price;
                askSize = orderBookEntry.Size;
                if (orderBookEntry.DateTime > datetime)
                {
                    datetime = orderBookEntry.DateTime;
                }
            }
            return(new Quote(datetime, bid, bidSize, ask, askSize));
        }
Example #2
0
 internal void Insert(int index, OrderBookEntry entry)
 {
     this.entries.Insert(index, entry);
 }
Example #3
0
        public void Add(MarketDepth marketDepth)
        {
            try
            {
                OrderBookEntryList orderBookEntryList;
                switch (marketDepth.Side)
                {
                case MDSide.Bid:
                    orderBookEntryList = this.bidList;
                    break;

                case MDSide.Ask:
                    orderBookEntryList = this.askList;
                    break;

                default:
                    throw new ArgumentException("Invalid Side" + marketDepth.Side);
                }

                switch (marketDepth.Operation)
                {
                case MDOperation.Insert:
                    if (marketDepth.Position == -1)
                    {
                        int index = -1;
                        switch (marketDepth.Side)
                        {
                        case MDSide.Bid:
                            index = 0;
                            while (index < orderBookEntryList.Count && marketDepth.Price <= orderBookEntryList[index].Price)
                            {
                                ++index;
                            }
                            break;

                        case MDSide.Ask:
                            index = orderBookEntryList.Count;
                            while (index > 0 && marketDepth.Price <= orderBookEntryList[index - 1].Price)
                            {
                                --index;
                            }
                            break;
                        }
                        orderBookEntryList.Insert(index, new OrderBookEntry(marketDepth.DateTime, marketDepth.Price, marketDepth.Size));
                        this.EmitChanged(marketDepth.Side, marketDepth.Operation, index);
                        break;
                    }
                    else
                    {
                        orderBookEntryList.Insert(marketDepth.Position, new OrderBookEntry(marketDepth.DateTime, marketDepth.Price, marketDepth.Size));
                        this.EmitChanged(marketDepth.Side, marketDepth.Operation, marketDepth.Position);
                        break;
                    }

                case MDOperation.Update:
                    if (marketDepth.Position == -1 || marketDepth.Position >= orderBookEntryList.Count)
                    {
                        break;
                    }
                    OrderBookEntry orderBookEntry = orderBookEntryList[marketDepth.Position];
                    orderBookEntry.DateTime = marketDepth.DateTime;
                    orderBookEntry.Size     = marketDepth.Size;
                    if (marketDepth.Price > 0.0)
                    {
                        orderBookEntry.Price = marketDepth.Price;
                    }
                    this.EmitChanged(marketDepth.Side, marketDepth.Operation, marketDepth.Position);
                    break;

                case MDOperation.Delete:
                    if (marketDepth.Position == -1)
                    {
                        break;
                    }
                    orderBookEntryList.RemoveAt(marketDepth.Position);
                    this.EmitChanged(marketDepth.Side, marketDepth.Operation, marketDepth.Position);
                    break;

                case MDOperation.Reset:
                    orderBookEntryList.Clear();
                    this.EmitChanged(marketDepth.Side, marketDepth.Operation, marketDepth.Position);
                    break;

                case MDOperation.Undefined:
                    break;

                default:
                    throw new ArgumentException("MDOperation is unknown: " + marketDepth.Operation.ToString());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
Example #4
0
 internal void Insert(int index, OrderBookEntry entry)
 {
     this.entries.Insert(index, entry);
 }