private static LocalMarketHours ReadCsvHours(string[] csv, int startIndex, DayOfWeek dayOfWeek)
        {
            var ex_open = csv[startIndex];

            if (ex_open == "-")
            {
                return(LocalMarketHours.ClosedAllDay(dayOfWeek));
            }
            if (ex_open == "+")
            {
                return(LocalMarketHours.OpenAllDay(dayOfWeek));
            }

            var open     = csv[startIndex + 1];
            var close    = csv[startIndex + 2];
            var ex_close = csv[startIndex + 3];

            var ex_open_time  = ParseHoursToTimeSpan(ex_open);
            var open_time     = ParseHoursToTimeSpan(open);
            var close_time    = ParseHoursToTimeSpan(close);
            var ex_close_time = ParseHoursToTimeSpan(ex_close);

            if (ex_open_time == TimeSpan.Zero &&
                open_time == TimeSpan.Zero &&
                close_time == TimeSpan.Zero &&
                ex_close_time == TimeSpan.Zero)
            {
                return(LocalMarketHours.ClosedAllDay(dayOfWeek));
            }

            return(new LocalMarketHours(dayOfWeek, ex_open_time, open_time, close_time, ex_close_time));
        }
Exemple #2
0
        /// <summary>
        /// Sets the regular market hours for the specified days If no days are specified then
        /// all days will be updated.
        /// </summary>
        /// <param name="extendedMarketOpen">The time of day the pre market opens</param>
        /// <param name="marketOpen">The time of day the market opens</param>
        /// <param name="marketClose">The time of day the market closes</param>
        /// <param name="extendedMarketClose">The time of day the post market opens</param>
        /// <param name="days">The days of the week to set these times for</param>
        public void SetMarketHours(TimeSpan extendedMarketOpen, TimeSpan marketOpen, TimeSpan marketClose, TimeSpan extendedMarketClose, params DayOfWeek[] days)
        {
            if (days.IsNullOrEmpty())
            {
                days = Enum.GetValues(typeof(DayOfWeek)).OfType <DayOfWeek>().ToArray();
            }

            // make sure extended hours are outside of regular hours
            extendedMarketOpen  = TimeSpan.FromTicks(Math.Min(extendedMarketOpen.Ticks, marketOpen.Ticks));
            extendedMarketClose = TimeSpan.FromTicks(Math.Max(extendedMarketClose.Ticks, marketClose.Ticks));

            var marketHours = _exchangeHours.MarketHours.ToDictionary();

            foreach (var day in days)
            {
                if (marketOpen == TimeSpan.Zero && marketClose == TimeSpan.Zero)
                {
                    marketHours[day] = LocalMarketHours.ClosedAllDay(day);
                }
                else if (marketOpen == TimeSpan.Zero && marketClose == Time.OneDay)
                {
                    marketHours[day] = LocalMarketHours.OpenAllDay(day);
                }
                else
                {
                    marketHours[day] = new LocalMarketHours(day, extendedMarketOpen, marketOpen, marketClose, extendedMarketClose);
                }
            }

            // create a new exchange hours instance for the new hours
            _exchangeHours = new SecurityExchangeHours(_exchangeHours.TimeZone, _exchangeHours.Holidays, marketHours);
        }
 /// <summary>
 /// Helper to extract market hours from the <see cref="_openHoursByDay"/> dictionary, filling
 /// in Closed instantes when not present
 /// </summary>
 private void SetMarketHoursForDay(DayOfWeek dayOfWeek, out LocalMarketHours localMarketHoursForDay)
 {
     if (!_openHoursByDay.TryGetValue(dayOfWeek, out localMarketHoursForDay))
     {
         // assign to our dictionary that we're closed this day, as well as our local field
         _openHoursByDay[dayOfWeek] = localMarketHoursForDay = LocalMarketHours.ClosedAllDay(dayOfWeek);
     }
 }
Exemple #4
0
        /// <summary>
        /// Sets the regular market hours for the specified days If no days are specified then
        /// all days will be updated.
        /// </summary>
        /// <param name="extendedMarketOpen">The time of day the pre market opens</param>
        /// <param name="marketOpen">The time of day the market opens</param>
        /// <param name="marketClose">The time of day the market closes</param>
        /// <param name="extendedMarketClose">The time of day the post market opens</param>
        /// <param name="days">The days of the week to set these times for</param>
        public void SetMarketHours(TimeSpan extendedMarketOpen, TimeSpan marketOpen, TimeSpan marketClose, TimeSpan extendedMarketClose, params DayOfWeek[] days)
        {
            if (days.IsNullOrEmpty())
            {
                days = Enum.GetValues(typeof(DayOfWeek)).OfType <DayOfWeek>().ToArray();
            }

            // if we specify close as 1 tick before the day rolls over, the exchange is still
            // considered to be open all day,so set it to one day and this impl will make it OpenAllDay
            if (extendedMarketOpen == marketOpen && marketOpen == TimeSpan.Zero && extendedMarketClose == marketClose && marketClose.Ticks == Time.OneDay.Ticks - 1)
            {
                marketClose = Time.OneDay;
            }

            // make sure extended hours are outside of regular hours
            extendedMarketOpen  = TimeSpan.FromTicks(Math.Min(extendedMarketOpen.Ticks, marketOpen.Ticks));
            extendedMarketClose = TimeSpan.FromTicks(Math.Max(extendedMarketClose.Ticks, marketClose.Ticks));

            var marketHours = _exchangeHours.MarketHours.ToDictionary();

            foreach (var day in days)
            {
                if (marketOpen == TimeSpan.Zero && marketClose == TimeSpan.Zero)
                {
                    marketHours[day] = LocalMarketHours.ClosedAllDay(day);
                }
                else if (marketOpen == TimeSpan.Zero && marketClose == Time.OneDay)
                {
                    marketHours[day] = LocalMarketHours.OpenAllDay(day);
                }
                else
                {
                    marketHours[day] = new LocalMarketHours(day, extendedMarketOpen, marketOpen, marketClose, extendedMarketClose);
                }
            }

            // create a new exchange hours instance for the new hours
            _exchangeHours = new SecurityExchangeHours(_exchangeHours.TimeZone, _exchangeHours.Holidays, marketHours);
        }