예제 #1
0
        public void AccessesByDataType()
        {
            var tradeBar = new TradeBar {
                Symbol = Symbols.SPY, Time = DateTime.UtcNow
            };
            var quandl = new Quandl {
                Symbol = Symbols.SPY, Time = DateTime.Now
            };
            var quoteBar = new QuoteBar {
                Symbol = Symbols.SPY, Time = DateTime.Now
            };
            var tick = new Tick(DateTime.Now, Symbols.SPY, 1.1m, 2.1m)
            {
                TickType = TickType.Trade
            };
            var split     = new Split(Symbols.SPY, DateTime.UtcNow, 1, 1, SplitType.SplitOccurred);
            var delisting = new Delisting(Symbols.SPY, DateTime.UtcNow, 1, DelistingType.Delisted);

            var slice = new Slice(DateTime.UtcNow, new BaseData[] { quoteBar, tradeBar, quandl, tick, split, delisting });

            Assert.AreEqual(slice.Get(typeof(TradeBar))[Symbols.SPY], tradeBar);
            Assert.AreEqual(slice.Get(typeof(Quandl))[Symbols.SPY], quandl);
            Assert.AreEqual(slice.Get(typeof(QuoteBar))[Symbols.SPY], quoteBar);
            Assert.AreEqual(slice.Get(typeof(Tick))[Symbols.SPY], tick);
            Assert.AreEqual(slice.Get(typeof(Split))[Symbols.SPY], split);
            Assert.AreEqual(slice.Get(typeof(Delisting))[Symbols.SPY], delisting);
        }
예제 #2
0
        public void AccessesByDataType()
        {
            var now      = DateTime.UtcNow;
            var tradeBar = new TradeBar {
                Symbol = Symbols.SPY, Time = now
            };
            var unlinkedData = new UnlinkedData {
                Symbol = Symbols.SPY, Time = now
            };
            var quoteBar = new QuoteBar {
                Symbol = Symbols.SPY, Time = now
            };
            var tick = new Tick(now, Symbols.SPY, 1.1m, 2.1m)
            {
                TickType = TickType.Trade
            };
            var openInterest = new OpenInterest(now, Symbols.SPY, 1);
            var split        = new Split(Symbols.SPY, now, 1, 1, SplitType.SplitOccurred);
            var delisting    = new Delisting(Symbols.SPY, now, 1, DelistingType.Delisted);

            var slice = new Slice(now, new BaseData[] { quoteBar, tradeBar, unlinkedData, tick, split, delisting, openInterest });

            Assert.AreEqual(slice.Get(typeof(TradeBar))[Symbols.SPY], tradeBar);
            Assert.AreEqual(slice.Get(typeof(UnlinkedData))[Symbols.SPY], unlinkedData);
            Assert.AreEqual(slice.Get(typeof(QuoteBar))[Symbols.SPY], quoteBar);
            Assert.AreEqual(slice.Get(typeof(Tick))[Symbols.SPY], tick);
            Assert.AreEqual(slice.Get(typeof(Split))[Symbols.SPY], split);
            Assert.AreEqual(slice.Get(typeof(Delisting))[Symbols.SPY], delisting);
            Assert.AreEqual(slice.Get(typeof(OpenInterest))[Symbols.SPY], openInterest);
        }
 public void Setup()
 {
     _config = SecurityTests.CreateTradeBarConfig();
     _tradableDayNotifier        = new TestTradableDayNotifier();
     _tradableDayNotifier.Symbol = _config.Symbol;
     _delistingEvent             = new Delisting(_config.Symbol, new DateTime(2009, 1, 1), 1, DelistingType.Delisted);
 }
예제 #4
0
        public void AlwaysOpenExchange()
        {
            var time      = new DateTime(2020, 1, 14);
            var delisting = new Delisting(Symbols.BTCUSD, time, 10, DelistingType.Warning);

            var liquidationTime = delisting.GetLiquidationTime(SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc));

            Assert.AreEqual(new DateTime(2020, 1, 14, 23, 45, 0), liquidationTime);
        }
예제 #5
0
        public void EmitsBasedOnData()
        {
            var config = new SubscriptionDataConfig(typeof(TradeBar),
                                                    Symbols.AAPL,
                                                    Resolution.Daily,
                                                    TimeZones.NewYork,
                                                    TimeZones.NewYork,
                                                    true,
                                                    true,
                                                    false);
            var       time             = new DateTime(2021, 2, 17);
            var       timeProvider     = new ManualTimeProvider(time);
            Delisting delisting        = null;
            var       autoResetEvent   = new AutoResetEvent(false);
            var       dataQueueHandler = new FuncDataQueueHandler(handler =>
            {
                autoResetEvent.Set();
                if (delisting != null)
                {
                    var result = new[] { delisting };
                    delisting  = null;
                    return(result);
                }
                return(Enumerable.Empty <BaseData>());
            }, timeProvider);
            var provider = new LiveDataBasedDelistingEventProvider(config, dataQueueHandler);
            var mapFile  = TestGlobals.MapFileProvider.Get(config.Symbol.ID.Market).ResolveMapFile(config.Symbol, config.Type);

            provider.Initialize(config, null, mapFile, time);
            Assert.IsTrue(autoResetEvent.WaitOne(TimeSpan.FromMilliseconds(100)));

            var events = provider.GetEvents(new NewTradableDateEventArgs(time, null, Symbols.AAPL, null)).ToList();

            Assert.AreEqual(0, events.Count);

            delisting = new Delisting(Symbols.AAPL, time, 1, DelistingType.Warning);
            Thread.Sleep(100);

            events = provider.GetEvents(new NewTradableDateEventArgs(time.AddDays(-1), null, Symbols.AAPL, null)).ToList();
            Assert.AreEqual(0, events.Count);

            events = provider.GetEvents(new NewTradableDateEventArgs(time, null, Symbols.AAPL, null)).ToList();
            Assert.AreEqual(1, events.Count);
            Assert.AreEqual(time, (events[0] as Delisting).Time);
            Assert.AreEqual(DelistingType.Warning, (events[0] as Delisting).Type);

            events = provider.GetEvents(new NewTradableDateEventArgs(time, null, Symbols.AAPL, null)).ToList();
            Assert.AreEqual(0, events.Count);

            events = provider.GetEvents(new NewTradableDateEventArgs(time.AddDays(1), null, Symbols.AAPL, null)).ToList();
            Assert.AreEqual(1, events.Count);
            Assert.AreEqual(time.AddDays(1), (events[0] as Delisting).Time);
            Assert.AreEqual(DelistingType.Delisted, (events[0] as Delisting).Type);

            provider.DisposeSafely();
        }
        public void DeserializesDelisting()
        {
            var delisting = new Delisting(Symbols.AAPL, new DateTime(2999, 12, 31), 100m, DelistingType.Delisted);

            var json         = JsonConvert.SerializeObject(delisting, _settings);
            var deserialized = (Delisting)JsonConvert.DeserializeObject(json, _settings);

            Assert.AreEqual(delisting.Symbol, deserialized.Symbol);
            Assert.AreEqual(delisting.Time, deserialized.Time);
            Assert.AreEqual(delisting.Type, deserialized.Type);
        }
예제 #7
0
        /// <summary>
        /// Gets the history for the requested securities
        /// </summary>
        /// <param name="requests">The historical data requests</param>
        /// <param name="sliceTimeZone">The time zone used when time stamping the slice instances</param>
        /// <returns>An enumerable of the slices of data covering the span specified in each request</returns>
        public override IEnumerable <Slice> GetHistory(IEnumerable <HistoryRequest> requests, DateTimeZone sliceTimeZone)
        {
            List <Slice> result     = new();
            var          slice1Date = new DateTime(2008, 01, 03, 5, 0, 0);
            var          slice2Date = new DateTime(2013, 06, 28, 13, 32, 0);

            TradeBar tradeBar1 = new TradeBar {
                Symbol = Symbols.SPY, Time = DateTime.Now
            };
            TradeBar tradeBar2 = new TradeBar {
                Symbol = Symbols.AAPL, Time = DateTime.Now
            };
            var quoteBar1 = new QuoteBar {
                Symbol = Symbols.SPY, Time = DateTime.Now
            };
            var tick1 = new Tick(DateTime.Now, Symbols.SPY, 1.1m, 2.1m)
            {
                TickType = TickType.Trade
            };
            var   split1              = new Split(Symbols.SPY, DateTime.Now, 1, 1, SplitType.SplitOccurred);
            var   dividend1           = new Dividend(Symbols.SPY, DateTime.Now, 1, 1);
            var   delisting1          = new Delisting(Symbols.SPY, DateTime.Now, 1, DelistingType.Delisted);
            var   symbolChangedEvent1 = new SymbolChangedEvent(Symbols.SPY, DateTime.Now, "SPY", "SP");
            Slice slice1              = new Slice(slice1Date, new BaseData[] { tradeBar1, tradeBar2,
                                                                               quoteBar1, tick1, split1, dividend1, delisting1, symbolChangedEvent1 }, slice1Date);

            TradeBar tradeBar3 = new TradeBar {
                Symbol = Symbols.MSFT, Time = DateTime.Now
            };
            TradeBar tradeBar4 = new TradeBar {
                Symbol = Symbols.SBIN, Time = DateTime.Now
            };
            var quoteBar2 = new QuoteBar {
                Symbol = Symbols.SBIN, Time = DateTime.Now
            };
            var tick2 = new Tick(DateTime.Now, Symbols.SBIN, 1.1m, 2.1m)
            {
                TickType = TickType.Trade
            };
            var   split2              = new Split(Symbols.SBIN, DateTime.Now, 1, 1, SplitType.SplitOccurred);
            var   dividend2           = new Dividend(Symbols.SBIN, DateTime.Now, 1, 1);
            var   delisting2          = new Delisting(Symbols.SBIN, DateTime.Now, 1, DelistingType.Delisted);
            var   symbolChangedEvent2 = new SymbolChangedEvent(Symbols.SBIN, DateTime.Now, "SBIN", "BIN");
            Slice slice2              = new Slice(slice2Date, new BaseData[] { tradeBar3, tradeBar4,
                                                                               quoteBar2, tick2, split2, dividend2, delisting2, symbolChangedEvent2 }, slice2Date);

            result.Add(slice1);
            result.Add(slice2);
            return(result);
        }
예제 #8
0
        public void EquityAndOption(SecurityType securityType)
        {
            var symbol = Symbols.AAPL;

            if (securityType == SecurityType.Option)
            {
                symbol = Symbols.SPY_C_192_Feb19_2016;
            }
            var time      = new DateTime(2020, 1, 14);
            var delisting = new Delisting(symbol, time, 10, DelistingType.Warning);

            var exchangeHours   = MarketHoursDatabase.FromDataFolder().GetExchangeHours(delisting.Symbol.ID.Market, delisting.Symbol, delisting.Symbol.SecurityType);
            var liquidationTime = delisting.GetLiquidationTime(exchangeHours);

            Assert.AreEqual(new DateTime(2020, 1, 14, 15, 45, 0), liquidationTime);
        }
예제 #9
0
        public void FuturesAndOption(SecurityType securityType)
        {
            var time   = new DateTime(2020, 1, 14);
            var symbol = Symbols.Future_CLF19_Jan2019;

            if (securityType == SecurityType.FutureOption)
            {
                symbol = Symbol.CreateOption(symbol, symbol.ID.Market, OptionStyle.American, OptionRight.Call, 1, time);
            }

            var delisting = new Delisting(symbol, time, 10, DelistingType.Warning);

            var exchangeHours   = MarketHoursDatabase.FromDataFolder().GetExchangeHours(delisting.Symbol.ID.Market, delisting.Symbol, delisting.Symbol.SecurityType);
            var liquidationTime = delisting.GetLiquidationTime(exchangeHours);

            Assert.AreEqual(new DateTime(2020, 1, 14, 16, 45, 0), liquidationTime);
        }
예제 #10
0
        public void ThrowsIfNotDelistingWarning()
        {
            var delisting = new Delisting(Symbols.AAPL, DateTime.UtcNow, 19, DelistingType.Delisted);

            Assert.Throws <ArgumentException>(() => delisting.GetLiquidationTime(SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc)));
        }