private void Subscribe(string symbol) { if (quotesMap.ContainsKey(symbol)) { return; } quotesMap[symbol] = new QuoteC(symbol); // Market data simluator.... put some random price info in QuoteC quote = quotesMap[symbol]; int quoteTimesHundred = (int)(2000 + (rand.NextDouble() * 8000)); quote.Ask = new decimal(quoteTimesHundred) / new decimal(100.0); quote.Bid = quote.Ask - new decimal(0.05); quote.Last = quote.Ask; quote.Open = quote.Ask; }
void throttleTimer_Elapsed(object sender, ElapsedEventArgs e) { QuoteC[] changedQuoteArray = null; bool update = false; int ticks = Environment.TickCount; #region Temporary market data simulator QuoteCList list = new QuoteCList(); foreach (string symbol in TypeSystemC.Symbols) { QuoteC quote = quotesMap[symbol]; if (gotFirstQuote) { if (rand.NextDouble() > 0.9) { update = true; if (rand.NextDouble() > 0.5) { quote.Ask += new decimal(0.01); } else { quote.Ask -= new decimal(0.01); } if (rand.NextDouble() > 0.5) { quote.Bid = quote.Ask - new decimal(0.05); } else { quote.Bid = quote.Ask - new decimal(0.10); } if (rand.NextDouble() > 0.5) { if (rand.NextDouble() > 0.5) { quote.Last = quote.Bid; } else { quote.Last = quote.Ask; } } list.Add(quote); } } else { list.Add(quote); } } if (!gotFirstQuote && QuotesUpdate != null) { gotFirstQuote = true; update = true; } changedQuoteArray = new QuoteC[list.Count]; list.CopyTo(changedQuoteArray, 0); #endregion if (update && QuotesUpdate != null) { QuotesUpdate(changedQuoteArray); } count++; tickCounter += Environment.TickCount - ticks; if (count > 10) { if (tickCounter / count > throttleTimer.Interval) { // if painting is too slow avoid locking up computer with backlog of timer events throttleTimer.Interval = tickCounter / count + 10; Console.WriteLine("Changed interval to {0}", throttleTimer.Interval); } count = 0; tickCounter = 0; } }