public static void LoadInMemoryExchangeFeeds(List<Exchange> exchanges) { ExchangeFakeFeeds = new List<ExchangeFeeds>(); foreach (Exchange exchange in exchanges) { ExchangeFeeds exchangeFeed = new ExchangeFeeds(); exchangeFeed.ExchangeId = Convert.ToInt32(exchange); exchangeFeed.ExchangeSymbolFeed = new List<SymbolFeeds>(); if (ExchangeSymbolList.Count == 0) LoadInMemoryExchangeSymbols(exchanges); foreach (Symbol symbol in ExchangeSymbolList.SingleOrDefault(x => x.Exchange == exchange).Symbols) { SymbolFeeds symbolFeeds = new SymbolFeeds(); symbolFeeds.SymbolId = symbol.Id; symbolFeeds.Feeds = new List<Feed>(); exchangeFeed.ExchangeSymbolFeed.Add(symbolFeeds); } ExchangeFakeFeeds.Add(exchangeFeed); } }
/// <summary> /// Method for generating fake data /// </summary> private void UpdateData() { // Method to change the values of all the stocks randomly in a fixed range List<StockModel.Symbol> symbols = InMemoryObjects.ExchangeSymbolList.SingleOrDefault(x => x.Exchange == Exchange.FAKE_NASDAQ).Symbols; Feed[] feedsArray = new Feed[symbols.Count]; List<SymbolFeeds> symbolFeeds = new List<SymbolFeeds>(); while (true) { Thread.Sleep(updateDurationTime); Parallel.ForEach(symbols, (symbol) => { SymbolFeeds feeds = new SymbolFeeds(); feeds.SymbolId = symbol.Id; double changePercent = random.NextDouble() * (Constants.MAX_CHANGE_PERC - Constants.MIN_CHANGE_PERC) + Constants.MIN_CHANGE_PERC; symbol.DefaultVal = symbol.DefaultVal + symbol.DefaultVal * changePercent / 100; Feed feed = new Feed(); feed.SymbolId = symbol.Id; feed.LTP = symbol.DefaultVal; feed.TimeStamp = Convert.ToInt64((DateTime.Now - epoch).TotalMilliseconds); if (FeedArrived != null) FeedArrived((Feed)feed.Clone()); //notify subscribers - later to be changed to only notify if there is any new data Notify(symbol.Id, feed); }); } }