Beispiel #1
0
        public void CreateTimeSeriesSubscriptionTest()
        {
            var symbol = "SYMA";
            var s      = DXEndpoint.Create().Feed.CreateTimeSeriesSubscription <IDxCandle>();

            s.AddSymbols(symbol);
            TestListener eventListener = new TestListener();

            s.AddEventListener(eventListener);

            var playedCandle = new PlayedCandle(symbol, Tools.DateToUnixTime(DateTime.Now), 123, 100, 12.34, 56.78, 9.0, 43.21, 1000, 999, 1001, 1002, 1, 777, 888, EventFlag.RemoveSymbol);

            EventPlayer <IDxCandle> eventPlayer = new EventPlayer <IDxCandle>(s as DXFeedSubscription <IDxCandle>);

            eventPlayer.PlayEvents(symbol, playedCandle);
            Assert.AreEqual(eventListener.GetEventCount <IDxCandle>(symbol), 1);
            IDxCandle receivedCandle = eventListener.GetLastEvent <IDxCandle>().Event;

            Assert.AreEqual(symbol, receivedCandle.EventSymbol.ToString());
            CompareCandles(playedCandle, receivedCandle);

            //thread-safety case
            DXEndpoint.Create();
            Parallel.For(ParallelFrom, ParallelTo, i =>
            {
                Assert.DoesNotThrow(() =>
                {
                    DXEndpoint.GetInstance().Feed.CreateTimeSeriesSubscription <IDxCandle>();
                });
            });
        }
Beispiel #2
0
        public void CreateTimeSeriesSubscriptionTypesTest()
        {
            //create default endpoint
            DXEndpoint.Create();

            //try to create subscription with invalid event types parameters
            //all attempts to create subscription in this block must be failed with exception
            Assert.Catch(typeof(ArgumentException), () =>
            {
                DXFeed.GetInstance().CreateTimeSeriesSubscription <IDxTimeSeriesEvent>(typeof(IDxCandle), typeof(IDxQuote));
            });
            Assert.Catch(typeof(ArgumentException), () =>
            {
                DXFeed.GetInstance().CreateTimeSeriesSubscription <IDxTimeSeriesEvent>(typeof(IDxOrder), typeof(IDxQuote));
            });
            Assert.Catch(typeof(ArgumentException), () =>
            {
                DXFeed.GetInstance().CreateTimeSeriesSubscription <IDxTimeSeriesEvent>(typeof(string));
            });

            var symbol = "SYMA";
            var s      = DXFeed.GetInstance().CreateTimeSeriesSubscription <IDxTimeSeriesEvent>(typeof(IDxCandle), typeof(IDxGreeks));

            s.AddSymbols(symbol);
            TestListener eventListener = new TestListener();

            s.AddEventListener(eventListener);

            EventPlayer <IDxTimeSeriesEvent> eventPlayer = new EventPlayer <IDxTimeSeriesEvent>(s as DXFeedSubscription <IDxTimeSeriesEvent>);
            var playedCandle = new PlayedCandle(symbol, Tools.DateToUnixTime(DateTime.Now), 123, 100, 12.34, 56.78, 9.0, 43.21, 1000, 999, 1001, 1002, 1, 777, 888, EventFlag.RemoveSymbol);

            eventPlayer.PlayEvents(symbol, playedCandle);
            var playedGreeks = new PlayedGreeks(symbol, EventFlag.RemoveSymbol, 1, Tools.DateToUnixTime(DateTime.Now), 456.789, 11, 555, 666, 777, 888, 999);

            eventPlayer.PlayEvents(symbol, playedGreeks);

            Assert.AreEqual(eventListener.GetEventCount <IDxCandle>(symbol), 1);
            Assert.AreEqual(eventListener.GetEventCount <IDxGreeks>(symbol), 1);

            //thread-safety case
            DXEndpoint.Create();
            Parallel.For(ParallelFrom, ParallelTo, i =>
            {
                Assert.DoesNotThrow(() =>
                {
                    DXFeed.GetInstance().CreateTimeSeriesSubscription <IDxTimeSeriesEvent>(typeof(IDxCandle), typeof(IDxGreeks));
                });
            });
        }
        public void ResetFromTimeStampTest()
        {
            string       symbol        = "SYMA";
            TestListener eventListener = new TestListener();
            var          s             = DXEndpoint.Create().Feed.CreateTimeSeriesSubscription <IDxCandle>();

            s.OnSubscriptionClosed += OnSubscriptionClosed;
            s.OnSymbolsAdded       += OnSymbolsAdded;
            s.OnSymbolsRemoved     += OnSymbolsRemoved;
            s.AddEventListener(eventListener);
            s.AddSymbols(symbol);
            Assert.AreEqual(long.MaxValue, s.FromTimeStamp);

            //try to change FromTimeStamp property
            isFiresOnSubscriptionClosed = false;
            isFiresOnSymbolsAdded       = false;
            isFiresOnSymbolsRemoved     = false;
            long fromTime = Tools.DateToUnixTime(DateTime.Now.AddMonths(-1));

            s.FromTimeStamp = fromTime;
            Assert.AreEqual(fromTime, s.FromTimeStamp);
            Assert.True(s.GetSymbols().SetEquals(new object[] { symbol }));
            Assert.True(s.EventTypes.SetEquals(new Type[] { typeof(IDxCandle) }));
            Assert.False(isFiresOnSubscriptionClosed);
            Assert.False(isFiresOnSymbolsAdded);
            Assert.False(isFiresOnSymbolsRemoved);

            var playedCandle = new PlayedCandle(symbol, Tools.DateToUnixTime(DateTime.Now), 123, 100, 12.34, 56.78, 9.0, 43.21, 1000, 999, 1001, 1002, 1, 777, 888, EventFlag.RemoveSymbol);

            EventPlayer <IDxCandle> eventPlayer = new EventPlayer <IDxCandle>(s as DXFeedSubscription <IDxCandle>);

            eventPlayer.PlayEvents(symbol, playedCandle);
            Assert.AreEqual(eventListener.GetEventCount <IDxCandle>(symbol), 1);
            IDxCandle receivedCandle = eventListener.GetLastEvent <IDxCandle>().Event;

            Assert.AreEqual(symbol, receivedCandle.EventSymbol.ToString());
            DXFeedTest.CompareCandles(playedCandle, receivedCandle);
        }