示例#1
0
        public void ResetTests(SecurityCache cache, SecuritySeedData seedType)
        {
            switch (seedType)
            {
            case SecuritySeedData.None:
            case SecuritySeedData.OpenInterest:
            case SecuritySeedData.OpenInterestTick:
                break;

            case SecuritySeedData.QuoteTick:
                Assert.IsNotNull(cache.GetData());
                Assert.Greater(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Quote), 0);
                cache.Reset();
                Assert.IsFalse(cache.HasData(typeof(Tick)));
                Assert.AreEqual(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Quote), 0);
                break;

            case SecuritySeedData.TradeTick:
                Assert.IsNotNull(cache.GetData());
                Assert.Greater(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Trade), 0);
                cache.Reset();
                Assert.IsFalse(cache.HasData(typeof(Tick)));
                Assert.AreEqual(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Trade), 0);
                break;

            default:
                Assert.IsNotNull(cache.GetData());
                cache.Reset();
                break;
            }
        }
示例#2
0
        public void StoreData_SecurityCacheHasTradeAndQuoteTick()
        {
            // Arrange
            var securityCache = new SecurityCache();
            var time          = DateTime.Now;

            var quote = new Tick(time, Symbol.Empty, 100, 102)
            {
                TickType = TickType.Quote
            };

            securityCache.StoreData(new[] { quote }, typeof(Tick));

            var trade = new Tick(time.AddMilliseconds(1), Symbol.Empty, 100, 100, 102)
            {
                TickType = TickType.Trade
            };

            securityCache.StoreData(new[] { trade }, typeof(Tick));

            // Adding OpenInterest as Tick or OpenInterest should not matter
            var openInterest = new OpenInterest(time, Symbol.Empty, 1000);

            securityCache.StoreData(new[] { openInterest }, typeof(Tick));           // Add as Tick
            securityCache.StoreData(new[] { openInterest }, typeof(OpenInterest));   // Add as OI

            // Assert
            Assert.IsTrue(securityCache.HasData(typeof(Tick)));
            Assert.True(securityCache.GetData <Tick>().Equals(trade));
            Assert.True(securityCache.GetData <OpenInterest>().Equals(openInterest));

            Assert.True(securityCache.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Quote).Equals(quote));
            Assert.True(securityCache.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Trade).Equals(trade));
        }
示例#3
0
        public void StoreData_TargetToModify_SecurityCacheHasTradeAndQuoteTick()
        {
            // Arrange
            var sourceToShare = new SecurityCache();
            var time          = DateTime.Now;

            var quote = new Tick(time, Symbol.Empty, 100, 102)
            {
                TickType = TickType.Quote
            };

            sourceToShare.StoreData(new[] { quote }, typeof(Tick));

            var trade = new Tick(time, Symbol.Empty, 100, 100, 102)
            {
                TickType = TickType.Trade
            };

            sourceToShare.StoreData(new[] { trade }, typeof(Tick));

            // Adding OpenInterest as Tick or OpenInterest should not matter
            var openInterest = new OpenInterest(time, Symbol.Empty, 1000);

            sourceToShare.StoreData(new[] { openInterest }, typeof(Tick));           // Add as Tick
            sourceToShare.StoreData(new[] { openInterest }, typeof(OpenInterest));   // Add as OI

            var targetToModify = new SecurityCache();

            SecurityCache.ShareTypeCacheInstance(sourceToShare, targetToModify);

            // Assert
            Assert.IsTrue(targetToModify.HasData(typeof(Tick)));
            Assert.True(targetToModify.GetData <Tick>().Equals(trade));
            Assert.True(targetToModify.GetData <OpenInterest>().Equals(openInterest));

            Assert.True(targetToModify.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Quote).Equals(quote));
            Assert.True(targetToModify.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Trade).Equals(trade));
        }