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; } }
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)); }
public void AddData_SecurityCacheHasTradeAndQuoteTick() { // Arrange var securityCache = new SecurityCache(); var time = DateTime.Now; var quote = new Tick(time, Symbol.Empty, 100, 102) { TickType = TickType.Quote }; securityCache.AddData(quote); var trade = new Tick(time, Symbol.Empty, 100, 100, 102) { TickType = TickType.Trade }; securityCache.AddData(trade); var openInterest = new OpenInterest(time, Symbol.Empty, 1000); securityCache.AddData(openInterest); // Assert Assert.True(securityCache.GetData().Equals(trade)); Assert.True(securityCache.GetData <Tick>().Equals(trade)); 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)); }
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)); }
public void GetAllData_ReturnsListOfData() { var cache = new SecurityCache(); cache.StoreData(new [] { new CustomDataBitcoinAlgorithm.Bitcoin { Ask = 1m }, new CustomDataBitcoinAlgorithm.Bitcoin { Ask = 2m } }, typeof(CustomDataBitcoinAlgorithm.Bitcoin)); var data = cache.GetAll <CustomDataBitcoinAlgorithm.Bitcoin>().ToList(); Assert.AreEqual(2, data.Count); Assert.AreEqual(1m, data[0].Ask); Assert.AreEqual(2m, data[1].Ask); }
public void GetAllData_ReturnsListOfDataOnTargetCache() { var cache = new SecurityCache(); cache.StoreData(new[] { new CustomDataBitcoinAlgorithm.Bitcoin { Ask = 1m }, new CustomDataBitcoinAlgorithm.Bitcoin { Ask = 2m } }, typeof(CustomDataBitcoinAlgorithm.Bitcoin)); var targetToModify = new SecurityCache(); SecurityCache.ShareTypeCacheInstance(cache, targetToModify); var data = targetToModify.GetAll <CustomDataBitcoinAlgorithm.Bitcoin>().ToList(); Assert.AreEqual(2, data.Count); Assert.AreEqual(1m, data[0].Ask); Assert.AreEqual(2m, data[1].Ask); }