Exemplo n.º 1
0
        static void TestAggregatedOrderBookStreamOnMocks()
        {
            IExchangeClient exchangeA = new MockClient(0);
            IExchangeClient exchangeB = new MockClient(1);
            IExchangeClient exchangeC = new MockClient(2);

            IObservable <IOrderBook> mergedOrderBookStream = Observable.Merge(exchangeA.OrderBookStream,
                                                                              exchangeB.OrderBookStream,
                                                                              exchangeC.OrderBookStream);

            IObservable <AggregatedOrderBook> aggregatedOrderBookStream = mergedOrderBookStream.Scan(
                new AggregatedOrderBook(),
                (aob, orderBook) => aob.InsertBook(orderBook));

            using (var consoleSubscription = aggregatedOrderBookStream.Subscribe(Console.WriteLine))
            {
                Console.WriteLine("press any key to stop");
                var exchanges = new IExchangeClient[3] {
                    exchangeA, exchangeB, exchangeC
                };
                exchanges.ToList().ForEach(ex => { ex.Connect(); ((MockClient)ex).StartRandomOrders(); });
                Console.ReadKey();
                exchanges.ToList().ForEach(ex => { ex.Disconnect(); ((MockClient)ex).StopRandomOrders(); });
            }

            Console.WriteLine("stopped. Press any key to close window");
            Console.ReadKey();
        }