Esempio n. 1
0
        public void DoesNotSetRunTimeErrorWhenReconnectMessageComesThrough()
        {
            var algorithm = new AlgorithmStub(equities: new List <string> {
                "SPY"
            });
            var referenceTime = DateTime.UtcNow;

            algorithm.SetDateTime(referenceTime);
            var localReferencTime = referenceTime.ConvertFromUtc(TimeZones.NewYork);
            var open        = localReferencTime.AddSeconds(1).TimeOfDay;
            var closed      = TimeSpan.FromDays(1);
            var marketHours = new MarketHoursSegment(MarketHoursState.Market, open, closed);

            algorithm.Securities[Symbols.SPY].Exchange.SetMarketHours(new [] { marketHours }, localReferencTime.DayOfWeek);
            var job     = new LiveNodePacket();
            var results = new TestResultHandler();//packet => Console.WriteLine(FieldsToString(packet)));
            var api     = new Api.Api();
            var handler = new DefaultBrokerageMessageHandler(algorithm, job, results, api, TimeSpan.FromMinutes(15), TimeSpan.FromSeconds(.25));

            Assert.IsNull(algorithm.RunTimeError);

            handler.Handle(BrokerageMessageEvent.Disconnected("Disconnection!"));

            Thread.Sleep(100);

            handler.Handle(BrokerageMessageEvent.Reconnected("Reconnected!"));

            Thread.Sleep(500);

            Assert.IsNull(algorithm.RunTimeError);

            results.Exit();
        }
Esempio n. 2
0
        public void GetMarketHoursWithEarlyCloseAndLateOpen()
        {
            var exchangeHours = CreateUsEquitySecurityExchangeHours();

            var startTime                  = new DateTime(2016, 11, 25);
            var marketHoursSegment         = exchangeHours.GetMarketHours(startTime).Segments.FirstOrDefault();
            var expectedMarketHoursSegment = new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(10, 0, 0), new TimeSpan(13, 0, 0));

            Assert.AreEqual(expectedMarketHoursSegment.Start, marketHoursSegment.Start);
            Assert.AreEqual(expectedMarketHoursSegment.End, marketHoursSegment.End);
            Assert.AreEqual(expectedMarketHoursSegment.State, marketHoursSegment.State);
        }
Esempio n. 3
0
        public void GetMarketHoursWithEarlyClose()
        {
            var exchangeHours = CreateSecurityExchangeHoursWithMultipleOpeningHours();

            var startTime                  = new DateTime(2018, 12, 31);
            var marketHoursSegment         = exchangeHours.GetMarketHours(startTime).Segments.FirstOrDefault();
            var expectedMarketHoursSegment = new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(3, 0, 0), new TimeSpan(3, 30, 0));

            Assert.AreEqual(expectedMarketHoursSegment.Start, marketHoursSegment.Start);
            Assert.AreEqual(expectedMarketHoursSegment.End, marketHoursSegment.End);
            Assert.AreEqual(expectedMarketHoursSegment.State, marketHoursSegment.State);
        }
Esempio n. 4
0
        /// <summary>
        /// Get the calendar open hours for the date.
        /// </summary>
        private IEnumerable <MarketHoursSegment> MarketToday(DateTime time, Symbol symbol)
        {
            if (Config.GetBool("force-exchange-always-open"))
            {
                yield return(MarketHoursSegment.OpenAllDay());

                yield break;
            }

            var hours = _marketHoursDatabase.GetExchangeHours(symbol.ID.Market, symbol, symbol.ID.SecurityType);

            foreach (var segment in hours.MarketHours[time.DayOfWeek].Segments)
            {
                yield return(segment);
            }
        }