Exemple #1
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double ActualWidth  = 300;
            double ActualHeight = 270;

            ContinuousCollection <StockSaleTick> tickCollection =
                (ContinuousCollection <StockSaleTick>)value;

            if (tickCollection.Count == 0)
            {
                return(null);
            }

            double xConst = -tickCollection.First().TimeStamp.Ticks;
            double xScale = ActualWidth / (tickCollection.Last().TimeStamp.Ticks + xConst);

            double yMin   = Math.Min(PreviousClosingPoint, tickCollection.Min(t => t.Price) - 0.1);
            double yMax   = Math.Max(PreviousClosingPoint, tickCollection.Max(t => t.Price) + 0.1);
            double yConst = -yMax;
            double yScale = ActualHeight / (yMin + yConst);

            Func <double, double>       yConvert  = tickPrice => yScale * (tickPrice + yConst);
            Func <double, double>       xConvert  = tickTime => xScale * (tickTime + xConst);
            Func <StockSaleTick, Point> ptConvert = tick => new Point(xConvert(tick.TimeStamp.Ticks),
                                                                      yConvert(tick.Price));


            PointCollection points = new PointCollection();

            for (int i = 0; i < tickCollection.Count; i++)
            {
                Point pt = ptConvert(tickCollection[i]);
                points.Add(pt);
            }

            return(points);
        }
Exemple #2
0
        void _simulationTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            double newPrice;
            double oldPrice;

            Random rnd = new Random();

            double variance = rnd.NextDouble() * 1.50; // stock can change +- 1.50

            if (_tickerData.Count > 0)
            {
                oldPrice = _tickerData.Last().Price;

                if (rnd.Next(0, 4) > 1)
                {
                    newPrice = oldPrice - variance;
                }
                else
                {
                    newPrice = oldPrice + variance;
                }
            }
            else
            {
                newPrice = 100;
            }


            // Simulation values.
            StockSaleTick newTick = new StockSaleTick()
            {
                Price     = newPrice,
                TimeStamp = DateTime.Now,
                Symbol    = "AAPL",
                Quantity  = rnd.Next(50) + 50 // QTY range: 50-100
            };

            _tickerData.Add(newTick);
            newTick = new StockSaleTick()
            {
                Price     = newPrice,
                TimeStamp = DateTime.Now,
                Symbol    = "IBM",
                Quantity  = rnd.Next(50) + 50 // QTY range: 50-100
            };
            _tickerData.Add(newTick);
            NotifyPropertyChanged("GraphWindowTicks");

            StockQuoteTick newQuote = new StockQuoteTick()
            {
                Price     = newPrice - (newPrice * 0.05),
                Side      = QuoteSide.Bid,
                Quantity  = rnd.Next(50) + 50,
                Symbol    = "AAPL",
                TimeStamp = DateTime.Now
            };

            _allQuotes.Add(newQuote);
            _allQuotes.Add(newQuote);
            newQuote = new StockQuoteTick()
            {
                Price     = newPrice + (newPrice * 0.05),
                Side      = QuoteSide.Ask,
                Quantity  = rnd.Next(50) + 50,
                Symbol    = "AAPL",
                TimeStamp = DateTime.Now
            };
            _allQuotes.Add(newQuote);
        }