Exemplo n.º 1
0
        private void GenerateBogusData(object sender, ElapsedEventArgs args)
        {
            double newPrice;
            double oldPrice;

            Random rnd = new Random();

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

                if (rnd.NextDouble() >= 0.7)
                {
                    newPrice = oldPrice - (rnd.NextDouble() * 0.5);
                }
                else
                {
                    newPrice = oldPrice + (rnd.NextDouble() * 1.4);
                }
            }
            else
            {
                newPrice = 100;
            }

            // Fake Executions
            StockTransaction newTx = new StockTransaction()
            {
                Price           = newPrice,
                Symbol          = "AAPL",
                Quantity        = rnd.Next(50) + 50,
                TimeStamp       = DateTime.Now,
                TransactionType = TransactionType.Execution
            };

            _allTransactions.Add(newTx);
            StockTransaction newTx2 = new StockTransaction()
            {
                Price           = newPrice,
                Symbol          = "IBM",
                TimeStamp       = DateTime.Now,
                Quantity        = rnd.Next(50) + 50,
                TransactionType = TransactionType.Execution
            };

            _allTransactions.Add(newTx2);
            NotifyChanged("GraphExecutions"); // this is because the graph polyline is bound to a property, not knowing it's a collection


            StockTransaction newBid = new StockTransaction()
            {
                Price           = newPrice - (newPrice * 0.05),
                TransactionType = TransactionType.Bid,
                Quantity        = rnd.Next(50) + 50,
                TimeStamp       = DateTime.Now,
                Symbol          = "AAPL"
            };

            _allTransactions.Add(newBid);

            StockTransaction newAsk = new StockTransaction()
            {
                Price           = newPrice + (newPrice * 0.05),
                TransactionType = TransactionType.Ask,
                TimeStamp       = DateTime.Now,
                Quantity        = rnd.Next(50) + 50,
                Symbol          = "AAPL"
            };

            _allTransactions.Add(newAsk);
        }