Exemplo n.º 1
0
        protected void ApplyIncrementalUpdate(string rateString, string amountString, List <OrderBookEntry> list, bool ascending)
        {
            double value  = FastValueConverter.Convert(rateString);
            double amount = FastValueConverter.Convert(amountString);
            int    index  = 0;

            if (amount == 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (IsEqual(e.Value, value))
                    {
                        list.Remove(e);
                        return;
                    }
                }
                if (EnableValidationOnRemove)
                {
                    IsDirty = true;
                }
                return;
            }
            if (ascending)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (IsEqual(e.Value, value))
                    {
                        e.AmountString = amountString;
                        return;
                    }
                    if (e.Value > value)
                    {
                        OrderBookEntry ee = new OrderBookEntry()
                        {
                            ValueString = rateString, AmountString = amountString
                        };
                        list.Insert(index, ee);
                        return;
                    }
                    index++;
                }
            }
            else
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (IsEqual(e.Value, value))
                    {
                        e.AmountString = amountString;
                        return;
                    }
                    if (e.Value < value)
                    {
                        OrderBookEntry ee = new OrderBookEntry()
                        {
                            ValueString = rateString, AmountString = amountString
                        };
                        list.Insert(index, ee);
                        return;
                    }
                    index++;
                }
            }
            OrderBookEntry addE = new OrderBookEntry()
            {
                ValueString = rateString, AmountString = amountString
            };

            list.Add(addE);
        }
Exemplo n.º 2
0
        protected void ApplyIncrementalUpdate(long id, OrderBookUpdateType type, string rateString, string amountString, List <OrderBookEntry> list, bool ascending)
        {
            int index = 0;

            if (type == OrderBookUpdateType.Remove)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (e.Id == id)
                    {
                        list.Remove(e);
                        return;
                    }
                }
                if (EnableValidationOnRemove)
                {
                    IsDirty = true;
                }
                return;
            }
            double amount = FastValueConverter.Convert(amountString);

            if (type == OrderBookUpdateType.Modify)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (e.Id == id)
                    {
                        e.Amount = amount;
                        return;
                    }
                }
                if (EnableValidationOnRemove)
                {
                    IsDirty = true;
                }
                return;
            }
            double value = FastValueConverter.Convert(rateString);

            if (ascending)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (e.Value > value)
                    {
                        OrderBookEntry ee = new OrderBookEntry()
                        {
                            ValueString = rateString, AmountString = amountString, Id = id
                        };
                        list.Insert(index, ee);
                        return;
                    }
                    index++;
                }
            }
            else
            {
                for (int i = 0; i < list.Count; i++)
                {
                    OrderBookEntry e = list[i];
                    if (e.Value < value)
                    {
                        OrderBookEntry ee = new OrderBookEntry()
                        {
                            ValueString = rateString, AmountString = amountString, Id = id
                        };
                        list.Insert(index, ee);
                        return;
                    }
                    index++;
                }
            }
            OrderBookEntry addE = new OrderBookEntry()
            {
                ValueString = rateString, AmountString = amountString, Id = id
            };

            list.Add(addE);
        }