private void Subscribe(string ticker) { if (!_subscriptions.ContainsKey(ticker)) { var observer = new InstrumentPriceObserver(); observer.OnPriceReceived += OnPriceReceived; var subscription = _priceSource.Subscribe(ticker, observer); _subscriptions.Add(ticker, subscription); } }
static void Main(string[] args) { IInstrumentFactory instrumentFactory = new InstrumentsProvider(); IProvidePriceGenerator priceGeneratorProvider = new PriceGeneratorProvider(instrumentFactory); ISourcePrice priceSource = new CompositePriceSource(instrumentFactory, priceGeneratorProvider); // start source priceSource.Start(); var priceObserver = new InstrumentPriceObserver(); priceObserver.OnPriceReceived += OnPriceReceived; var subscription1 = priceSource.Subscribe("AAPL", priceObserver); var subscription2 = priceSource.Subscribe("MSFT", priceObserver); var subscription3 = priceSource.Subscribe("GOOG", priceObserver); Console.ReadKey(); subscription1.Dispose(); subscription2.Dispose(); subscription3.Dispose(); priceSource.Stop(); }