FlexGrid for WinForms | ComponentOne
In This Topic
    FinancialDataList
    In This Topic
    
            public class FinancialDataList :BindingList<FinancialData>
            {
            // fields
            Timer _timer;
            Random _rnd = new Random(0);
    
            // object model
            public int UpdateInterval 
            { 
                get { return (int)_timer.Interval; }
                set { _timer.Interval = value; }
            }
            public int BatchSize { get; set; }
            public bool AutoUpdate
            {
                get { return _timer.Enabled; }
                set { _timer.Enabled = value; }
            }
    
            // ctor
            public FinancialDataList()
            {
                _timer = new Timer();
                _timer.Tick += _timer_Tick;
                UpdateInterval = 1000;
                BatchSize = 100;
            }
    
            //change data on timer tick to simulare live changes
            void _timer_Tick(object sender, EventArgs e)
            {
                if (this.Count > 0)
                {
                    for (int i = 0; i < BatchSize; i++)
                    {
                        int index = _rnd.Next() % this.Count;
                        var data = this[index];
                        data.Bid = (data.Bid == 0 ? 1: data.Bid) * (decimal)(1 + (_rnd.NextDouble() * .11 - .05));
                        data.Ask = (data.Ask == 0 ? 1 : data.Ask) * (decimal)(1 + (_rnd.NextDouble() * .11 - .05));
                        data.BidSize = _rnd.Next(10, 1000);
                        data.AskSize = _rnd.Next(10, 1000);
                        var sale = (data.Ask + data.Bid) / 2;
                        data.LastSale = sale;
                        data.LastSize = (data.AskSize + data.BidSize) / 2;
                        data.QuoteTime = DateTime.Now;
                        data.TradeTime = DateTime.Now.AddSeconds(-_rnd.Next(0, 60));
                    }
                }
            }
        }