Example #1
0
        public void CanConsumePriceStream()
        {
            var gate = new ManualResetEvent(false);

            var streamingClient = BuildStreamingClient();


            // odd - 80905 returns null values for the first update and then subsequently returns values - indicative of a spin-up process?
            // 71442
            // 400740080
            var priceListener = streamingClient.BuildPricesListener(400740080);
            var recorder      = StreamingRecorder.Create(priceListener);

            recorder.Start();
            PriceDTO actual = null;

            //Trap the Price given by the update event for checking


            priceListener.MessageReceived += (s, e) =>
            {
                actual = e.Data;
                Console.WriteLine("got data {0}", e.Data.Change);
                gate.Set();
            };


            bool gotPriceInTime = true;

            if (!gate.WaitOne(TimeSpan.FromSeconds(15)))
            {
                gotPriceInTime = false;
                // don't want to throw while client is listening, hangs test
            }

            recorder.Stop();

            streamingClient.TearDownListener(priceListener);

            streamingClient.Dispose();


            Assert.IsTrue(gotPriceInTime, "A price update wasn't received in time");
            Assert.IsNotNull(actual);
            // i think the demo price stream may be delayed?
            // anyway, this assertion is arbitrary and irrelevant to the test.
            // Assert.Greater(actual.TickDate, DateTime.UtcNow.AddMinutes(-10), "We're expecting a recent price");

            var messages = recorder.GetMessages();

            recorder.Dispose();
        }
        public void CanConsumeDefaultPricesStream()
        {
            var rpcClient       = this.BuildRpcClient();
            var streamingClient = rpcClient.CreateStreamingClient();

            var priceListener = streamingClient.BuildDefaultPricesListener(IFX_POLAND_ACCOUNT_OPERATOR_ID);
            var recorder      = StreamingRecorder.Create(priceListener);

            recorder.Start();
            var tableOfPrices = new Dictionary <int, PriceDTO>();

            //A collection of different prices will stream in.
            //You need to collect a few before you get an idea of which prices you will get
            priceListener.MessageReceived += (s, e) =>
            {
                var newPrice = e.Data;
                Console.WriteLine(e.Data.Price);
                if (tableOfPrices.ContainsKey(newPrice.MarketId))
                {
                    tableOfPrices[newPrice.MarketId] = newPrice;
                }
                else
                {
                    tableOfPrices.Add(newPrice.MarketId, newPrice);
                }
            };

            Thread.Sleep(15000); //Wait for some prices to come in
            recorder.Stop();
            recorder.Dispose();
            List <MessageEventArgs <PriceDTO> > messages = recorder.GetMessages();
            string serializedMessages = rpcClient.Serializer.SerializeObject(messages);

            streamingClient.TearDownListener(priceListener);
            streamingClient.Dispose();

            tableOfPrices.Values.ToList().ForEach(p => Console.WriteLine(" ############ {0} - {1}", p.MarketId, p.Bid));

            Assert.Greater(tableOfPrices.Values.Count, 1, "We're expecting at least one price");
        }