/// <summary> /// Updates stock prices for the subscribed instruments in the internal list. /// </summary> /// <param name="updatedInstruments"></param> private void UpdateStockPrices(IList <InstrumentItem> updatedInstruments) { //Update the price or add any new items. foreach (var updatedInstrument in updatedInstruments) { var stockItemToModify = CurrentInstrumentItems.Where(item => item.Symbol == updatedInstrument.Symbol).FirstOrDefault(); if (stockItemToModify != null) { stockItemToModify.Price = updatedInstrument.Price; } else { CurrentInstrumentItems.Add(new InstrumentItem(updatedInstrument.Symbol.ToUpper(), updatedInstrument.Price)); } } //Remove any items that may not be present. foreach (var currentStockItem in CurrentInstrumentItems.ToList()) { var stockItemToRemove = updatedInstruments.FirstOrDefault(item => item.Symbol == currentStockItem.Symbol); if (stockItemToRemove == null) { CurrentInstrumentItems.Remove(currentStockItem); } } }
private void AddItem() { if (!CurrentInstrumentItems.Any(item => item.Symbol == ItemToAdd.ToUpper())) { ErrorText = ""; try { myPricingEngine.StartMonitoring(new List <string>() { ItemToAdd.ToUpper() }); } catch (InvalidDataException ex) { ErrorText = ex.Message; } } else { ErrorText = string.Format(" {0} already in the list!", ItemToAdd); } }