コード例 #1
0
 void OnRemove(OrderBookUpdateInfo info)
 {
     if (info.Type == OrderBookEntryType.Bid)
     {
         OrderBookEntry entry = Bids.FirstOrDefault((e) => e.Value == info.Entry.Value);
         if (entry == null)
         {
             Debug.WriteLine("Error removing: '" + info.Type + "' with rate " + info.Entry.Value + " not found");
             return;
         }
         Bids.Remove(entry);
     }
     else
     {
         OrderBookEntry entry = Asks.FirstOrDefault((e) => e.Value == info.Entry.Value);
         if (entry == null)
         {
             Debug.WriteLine("Error removing: '" + info.Type + "' with rate " + info.Entry.Value + " not found");
             return;
         }
         Asks.Remove(entry);
     }
     RaiseOnChanged(info);
     OnChangedCore(info);
 }
コード例 #2
0
        void OnAddBid(OrderBookUpdateInfo info)
        {
            OrderBookEntry before = Bids.FirstOrDefault((e) => e.Value < info.Entry.Value);

            if (before == null)
            {
                Bids.Add(info.Entry);
                return;
            }
            Bids.Insert(Bids.IndexOf(before), info.Entry);
        }
コード例 #3
0
        protected internal void OnAddAsk(OrderBookUpdateInfo info)
        {
            OrderBookEntry before = Asks.FirstOrDefault((e) => e.Value < info.Entry.Value);

            if (before == null)
            {
                Asks.Insert(0, info.Entry);
                return;
            }
            Asks.Insert(Asks.IndexOf(before), info.Entry);
        }
コード例 #4
0
        private void bidGridView_MouseDown(object sender, MouseEventArgs e)
        {
            GridHitInfo hi = this.bidGridView.CalcHitInfo(e.Location);

            if (!hi.InDataRow)
            {
                return;
            }
            OrderBookEntry ee = (OrderBookEntry)this.bidGridView.GetRow(hi.RowHandle);

            RaiseBidRowChanged(ee);
        }
コード例 #5
0
        private void RaiseBidRowChanged(OrderBookEntry en)
        {
            SelectedOrderBookEntryChangedHandler handler = (SelectedOrderBookEntryChangedHandler)Events[selectedBidChanged];

            if (handler != null)
            {
                handler(this, new SelectedOrderBookEntryChangedEventArgs()
                {
                    Entry = en
                });
            }
        }
コード例 #6
0
        protected internal void OnModify(OrderBookUpdateInfo info)
        {
            OrderBookEntry entry = info.Type == OrderBookEntryType.Ask ?
                                   Asks.FirstOrDefault((e) => e.Value == info.Entry.Value) :
                                   Bids.FirstOrDefault((e) => e.Value == info.Entry.Value);

            if (entry == null)
            {
                OnAdd(info);
                return;
            }
            entry.Amount = info.Entry.Amount;
            info.Entry   = entry;
            RaiseOnChanged(info);
            OnChangedCore(info);
        }
コード例 #7
0
        private void bidGridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            if (e.Column == this.gcAmount2)
            {
                GridViewInfo   gvi = (GridViewInfo)this.bidGridView.GetViewInfo();
                GridRowInfo    gri = gvi.GetGridRowInfo(e.RowHandle);
                OrderBookEntry ee  = (OrderBookEntry)this.bidGridView.GetRow(e.RowHandle);
                if (ee == null)
                {
                    return;
                }

                int height = ScaleUtils.ScaleValue(3);
                int width  = (int)(gri.Bounds.Width * ee.VolumePercent + 0.5f);
                e.Cache.FillRectangle(Color.FromArgb(0x20, Exchange.BidColor), new Rectangle(gri.Bounds.Right - width, gri.Bounds.Y, width, gri.Bounds.Height));
            }
        }
コード例 #8
0
 static OrderBookAllocator()
 {
     if (!OrderBook.AllowOrderBookHistory)
     {
         return;
     }
     pool = new List <List <OrderBookEntry> >(100000);
     for (int i = 0; i < 100000; i++)
     {
         List <OrderBookEntry> list = new List <OrderBookEntry>(OrderBook.Depth);
         for (int j = 0; j < OrderBook.Depth; j++)
         {
             list[j] = new OrderBookEntry();
         }
         pool.Add(list);
     }
 }
コード例 #9
0
        void CalcVolume(List <OrderBookEntry> list, out double volume, out double exp, out double disp, int depth)
        {
            int count = Math.Min(depth, list.Count);
            int index = 0;

            volume = 0;
            exp    = 0;
            disp   = 0;
            for (int i = 0; i < list.Count; i++)
            {
                OrderBookEntry e = list[i];
                volume += e.Amount;
                exp    += e.Amount * e.Value;
                index++;
                if (index == count)
                {
                    break;
                }
            }
            exp /= list.Count;
            if (volume == 0)
            {
                exp  = 0;
                disp = 0;
                return;
            }

            index = 0;
            double invVolume = 1.0 / volume;
            double qexp      = exp * exp;

            for (int i = 0; i < list.Count; i++)
            {
                OrderBookEntry e = list[i];
                disp += (e.Value * e.Value) * e.Amount * invVolume - qexp;
                index++;
                if (index == count)
                {
                    break;
                }
            }
        }
コード例 #10
0
        public void SelectedAskChanged(object sender, FocusedRowChangedEventArgs e)
        {
            OrderBookEntry entry = (OrderBookEntry)((GridView)sender).GetRow(e.FocusedRowHandle);

            BuyPriceTextEdit.EditValue = entry.Value;
        }
コード例 #11
0
        protected void ApplyIncrementalUpdate(string rateString, string amountString, List <OrderBookEntry> list, bool ascending)
        {
            double value  = FastValueConverter.Convert(rateString);
            double value2 = Convert.ToDouble(rateString);

            if (!IsEqual(value, value2))
            {
                throw new Exception();
            }
            double amount = FastValueConverter.Convert(amountString);
            int    index  = 0;

            if (amount == 0)
            {
                foreach (OrderBookEntry e in list)
                {
                    if (IsEqual(e.Value, value))
                    {
                        list.Remove(e);
                        return;
                    }
                }
                throw new DllNotFoundException("entry not found -> with value " + value + " and amount " + amount);
            }
            if (ascending)
            {
                foreach (OrderBookEntry e in list)
                {
                    if (IsEqual(e.Value, value))
                    {
                        e.AmountString = amountString;
                        //if(!e.ValueString.StartsWith(rateString))
                        //    throw new DllNotFoundException();
                        return;
                    }
                    if (e.Value > value)
                    {
                        OrderBookEntry ee = new OrderBookEntry()
                        {
                            ValueString = rateString, AmountString = amountString
                        };
                        list.Insert(index, ee);
                        return;
                    }
                    index++;
                }
            }
            else
            {
                foreach (OrderBookEntry e in list)
                {
                    if (IsEqual(e.Value, value))
                    {
                        e.AmountString = amountString;
                        //if(!e.ValueString.StartsWith(rateString))
                        //    throw new DllNotFoundException();
                        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);
        }
コード例 #12
0
        protected void ApplyIncrementalUpdate(long id, OrderBookUpdateType type, string rateString, string amountString, List <OrderBookEntry> list, bool ascending)
        {
            int index = 0;

            if (type == OrderBookUpdateType.Remove)
            {
                foreach (OrderBookEntry e in list)
                {
                    if (e.Id == id)
                    {
                        list.Remove(e);
                        return;
                    }
                }
                //throw new DllNotFoundException("entry not found -> with value " + value + " and amount " + amount);
                return;
            }
            double amount = FastValueConverter.Convert(amountString);

            if (type == OrderBookUpdateType.Modify)
            {
                foreach (OrderBookEntry e in list)
                {
                    if (e.Id == id)
                    {
                        e.Amount = amount;
                        return;
                    }
                }
                //throw new DllNotFoundException("entry not found -> with value " + value + " and amount " + amount);
                return;
            }
            double value = FastValueConverter.Convert(rateString);

            if (ascending)
            {
                foreach (OrderBookEntry e in list)
                {
                    if (e.Value > value)
                    {
                        OrderBookEntry ee = new OrderBookEntry()
                        {
                            ValueString = rateString, AmountString = amountString, Id = id
                        };
                        list.Insert(index, ee);
                        return;
                    }
                    index++;
                }
            }
            else
            {
                foreach (OrderBookEntry e in list)
                {
                    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);
        }
コード例 #13
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);
        }
コード例 #14
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);
        }
コード例 #15
0
        public void UpdateEntries()
        {
            LastUpdateTime = DateTime.Now;
            if (Bids.Count == 0 || Asks.Count == 0)
            {
                return;
            }
            HighestBid = Bids[0].Value;
            LowestAsk  = Asks[0].Value;
            if (UpdateEntriesCount == 0)
            {
                return;
            }
            if (!AllowAdditionalCalculations)
            {
                return;
            }
            double MaxVolume = 0;
            double vt        = 0;

            for (int i = 0; i < Bids.Count; i++)
            {
                OrderBookEntry e = Bids[i];
                e.Volume      = e.Value * e.Amount;
                vt           += e.Volume;
                e.VolumeTotal = vt;
                MaxVolume     = Math.Max(MaxVolume, e.Volume);
            }
            vt = 0;
            for (int i = 0; i < Asks.Count; i++)
            {
                OrderBookEntry e = Asks[i];
                e.Volume      = e.Value * e.Amount;
                vt           += e.Volume;
                e.VolumeTotal = vt;
                MaxVolume     = Math.Max(MaxVolume, e.Volume);
            }
            double mv = Asks.Count == 0 ? 0 : Asks.Last().VolumeTotal;

            vt = 0;
            if (AllowInvertedAsks)
            {
                for (int i = 0; i < AsksInverted.Count; i++)
                {
                    OrderBookEntry e = AsksInverted[i];
                    e.Volume      = e.Value * e.Amount;
                    vt           += e.Volume;
                    e.VolumeTotal = mv - vt;
                }
            }
            if (MaxVolume == 0)
            {
                return;
            }
            MaxVolume = 1 / MaxVolume;
            for (int i = 0; i < Bids.Count; i++)
            {
                OrderBookEntry e = Bids[i];
                e.VolumePercent = e.Volume * MaxVolume;
            }
            for (int i = 0; i < Asks.Count; i++)
            {
                OrderBookEntry e = Asks[i];
                e.VolumePercent = e.Volume * MaxVolume;
            }
            if (AllowInvertedAsks)
            {
                for (int i = 0; i < AsksInverted.Count; i++)
                {
                    OrderBookEntry e = AsksInverted[i];
                    e.VolumePercent = e.Volume * MaxVolume;
                }
            }
        }