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));
        }
示例#2
0
        public void Setup()
        {
            var sunday      = new LocalMarketHours(DayOfWeek.Sunday, new TimeSpan(17, 0, 0), TimeSpan.FromTicks(Time.OneDay.Ticks - 1));
            var monday      = LocalMarketHours.OpenAllDay(DayOfWeek.Monday);
            var tuesday     = LocalMarketHours.OpenAllDay(DayOfWeek.Tuesday);
            var wednesday   = LocalMarketHours.OpenAllDay(DayOfWeek.Wednesday);
            var thursday    = LocalMarketHours.OpenAllDay(DayOfWeek.Thursday);
            var friday      = new LocalMarketHours(DayOfWeek.Friday, TimeSpan.Zero, new TimeSpan(17, 0, 0));
            var earlyCloses = new Dictionary <DateTime, TimeSpan>();

            _exchangeHours = new SecurityExchangeHours(TimeZones.NewYork, USHoliday.Dates.Select(x => x.Date), new[]
            {
                sunday, monday, tuesday, wednesday, thursday, friday
            }.ToDictionary(x => x.DayOfWeek), earlyCloses);

            _liveTradingDataFeed = new TestableLiveTradingDataFeed();

            var jobPacket = new LiveNodePacket()
            {
                DeployId         = "",
                Brokerage        = BrokerageName.OandaBrokerage.ToString(),
                DataQueueHandler = "LiveDataQueue"
            };

            var algo        = new TestAlgorithm();
            var dataManager = new DataManager(_liveTradingDataFeed, new UniverseSelection(_liveTradingDataFeed, algo),
                                              algo.Settings, algo.TimeKeeper);

            algo.SubscriptionManager.SetDataManager(dataManager);

            _liveTradingDataFeed.Initialize(algo, jobPacket, new LiveTradingResultHandler(), new LocalDiskMapFileProvider(),
                                            null, new DefaultDataProvider(), dataManager);

            algo.Initialize();
        }
        public static SecurityExchangeHours CreateForexSecurityExchangeHours()
        {
            var sunday    = new LocalMarketHours(DayOfWeek.Sunday, new TimeSpan(17, 0, 0), TimeSpan.FromTicks(Time.OneDay.Ticks - 1));
            var monday    = LocalMarketHours.OpenAllDay(DayOfWeek.Monday);
            var tuesday   = LocalMarketHours.OpenAllDay(DayOfWeek.Tuesday);
            var wednesday = LocalMarketHours.OpenAllDay(DayOfWeek.Wednesday);
            var thursday  = LocalMarketHours.OpenAllDay(DayOfWeek.Thursday);
            var friday    = new LocalMarketHours(DayOfWeek.Friday, TimeSpan.Zero, new TimeSpan(17, 0, 0));
            var saturday  = LocalMarketHours.ClosedAllDay(DayOfWeek.Saturday);

            var holidays = USHoliday.Dates.Select(x => x.Date).ToList();

            holidays.Remove(new DateTime(2019, 1, 1));  // not a forex holiday

            var earlyCloses = new Dictionary <DateTime, TimeSpan> {
                { new DateTime(2018, 12, 31), new TimeSpan(17, 0, 0) }
            };
            var lateOpens = new Dictionary <DateTime, TimeSpan> {
                { new DateTime(2019, 1, 1), new TimeSpan(17, 0, 0) }
            };
            var exchangeHours = new SecurityExchangeHours(TimeZones.NewYork, holidays, new[]
            {
                sunday, monday, tuesday, wednesday, thursday, friday//, saturday
            }.ToDictionary(x => x.DayOfWeek), earlyCloses, lateOpens);

            return(exchangeHours);
        }
        public static SecurityExchangeHours CreateSecurityExchangeHoursWithMultipleOpeningHours()
        {
            var sunday = LocalMarketHours.OpenAllDay(DayOfWeek.Sunday);
            var monday = new LocalMarketHours(
                DayOfWeek.Monday,
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(3, 0, 0), new TimeSpan(3, 30, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(17, 0, 0), new TimeSpan(17, 30, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(18, 0, 0), new TimeSpan(18, 30, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(19, 0, 0), TimeSpan.FromTicks(Time.OneDay.Ticks - 1))
                );
            var tuesday   = LocalMarketHours.OpenAllDay(DayOfWeek.Tuesday);
            var wednesday = LocalMarketHours.OpenAllDay(DayOfWeek.Wednesday);
            var thursday  = LocalMarketHours.OpenAllDay(DayOfWeek.Thursday);
            var friday    = LocalMarketHours.OpenAllDay(DayOfWeek.Friday);
            var saturday  = LocalMarketHours.ClosedAllDay(DayOfWeek.Saturday);

            var holidays    = new List <DateTime>();
            var earlyCloses = new Dictionary <DateTime, TimeSpan> {
                { new DateTime(2018, 12, 31), new TimeSpan(17, 0, 0) }
            };
            var lateOpens = new Dictionary <DateTime, TimeSpan> {
                { new DateTime(2019, 01, 01), new TimeSpan(2, 0, 0) },
                { new DateTime(2018, 12, 10), new TimeSpan(4, 0, 0) }
            };
            var exchangeHours = new SecurityExchangeHours(TimeZones.NewYork, holidays, new[]
            {
                sunday, monday, tuesday, wednesday, thursday, friday//, saturday
            }.ToDictionary(x => x.DayOfWeek), earlyCloses, lateOpens);

            return(exchangeHours);
        }
示例#5
0
        public void CorrectlyReadFxcmForexMarketHours()
        {
            string file          = Path.Combine("TestData", "SampleMarketHoursDatabase.csv");
            var    exchangeHours = GetMarketHoursDatabase(file);

            var equityHours = exchangeHours.GetExchangeHours(Market.FXCM, null, SecurityType.Forex);

            foreach (var day in equityHours.MarketHours.Keys)
            {
                var marketHours = equityHours.MarketHours[day];
                if (day == DayOfWeek.Saturday)
                {
                    Assert.AreEqual(LocalMarketHours.ClosedAllDay(day), marketHours);
                }
                else if (day != DayOfWeek.Sunday && day != DayOfWeek.Friday)
                {
                    Assert.AreEqual(LocalMarketHours.OpenAllDay(day), marketHours);
                }
                else if (day == DayOfWeek.Sunday)
                {
                    Assert.AreEqual(new TimeSpan(17, 0, 0), marketHours.ExtendedMarketOpen);
                    Assert.AreEqual(new TimeSpan(17, 0, 0), marketHours.MarketOpen);
                    Assert.AreEqual(new TimeSpan(24, 0, 0), marketHours.MarketClose);
                    Assert.AreEqual(new TimeSpan(24, 0, 0), marketHours.ExtendedMarketClose);
                }
                else
                {
                    Assert.AreEqual(new TimeSpan(0, 0, 0), marketHours.ExtendedMarketOpen);
                    Assert.AreEqual(new TimeSpan(0, 0, 0), marketHours.MarketOpen);
                    Assert.AreEqual(new TimeSpan(17, 0, 0), marketHours.MarketClose);
                    Assert.AreEqual(new TimeSpan(17, 0, 0), marketHours.ExtendedMarketClose);
                }
            }
        }
示例#6
0
        public void CorrectlyReadsOpenAllDayHours()
        {
            string file          = Path.Combine("TestData", "SampleMarketHoursDatabase.csv");
            var    exchangeHours = GetMarketHoursDatabase(file);

            var hours = exchangeHours.GetExchangeHours(Market.FXCM, null, SecurityType.Forex);

            Assert.IsNotNull(hours);

            Assert.AreEqual(LocalMarketHours.OpenAllDay(DayOfWeek.Monday), hours.MarketHours[DayOfWeek.Monday]);
        }
示例#7
0
        public void Setup()
        {
            var sunday      = new LocalMarketHours(DayOfWeek.Sunday, new TimeSpan(17, 0, 0), TimeSpan.FromTicks(Time.OneDay.Ticks - 1));
            var monday      = LocalMarketHours.OpenAllDay(DayOfWeek.Monday);
            var tuesday     = LocalMarketHours.OpenAllDay(DayOfWeek.Tuesday);
            var wednesday   = LocalMarketHours.OpenAllDay(DayOfWeek.Wednesday);
            var thursday    = LocalMarketHours.OpenAllDay(DayOfWeek.Thursday);
            var friday      = new LocalMarketHours(DayOfWeek.Friday, TimeSpan.Zero, new TimeSpan(17, 0, 0));
            var earlyCloses = new Dictionary <DateTime, TimeSpan>();
            var lateOpens   = new Dictionary <DateTime, TimeSpan>();

            _exchangeHours = new SecurityExchangeHours(TimeZones.NewYork, USHoliday.Dates.Select(x => x.Date), new[]
            {
                sunday, monday, tuesday, wednesday, thursday, friday
            }.ToDictionary(x => x.DayOfWeek), earlyCloses, lateOpens);

            _liveTradingDataFeed = new TestableLiveTradingDataFeed();

            var jobPacket = new LiveNodePacket()
            {
                DeployId         = "",
                Brokerage        = BrokerageName.OandaBrokerage.ToString(),
                DataQueueHandler = "LiveDataQueue"
            };

            var algo = new TestAlgorithm();
            var marketHoursDatabase      = MarketHoursDatabase.FromDataFolder();
            var symbolPropertiesDataBase = SymbolPropertiesDatabase.FromDataFolder();
            var dataPermissionManager    = new DataPermissionManager();
            var dataProvider             = new DefaultDataProvider();
            var dataManager = new DataManager(_liveTradingDataFeed,
                                              new UniverseSelection(
                                                  algo,
                                                  new SecurityService(algo.Portfolio.CashBook, marketHoursDatabase, symbolPropertiesDataBase, algo, RegisteredSecurityDataTypesProvider.Null, new SecurityCacheProvider(algo.Portfolio)),
                                                  dataPermissionManager,
                                                  dataProvider),
                                              algo,
                                              algo.TimeKeeper,
                                              marketHoursDatabase,
                                              true,
                                              RegisteredSecurityDataTypesProvider.Null,
                                              dataPermissionManager);

            algo.SubscriptionManager.SetDataManager(dataManager);
            _liveSynchronizer = new LiveSynchronizer();
            _liveSynchronizer.Initialize(algo, dataManager);
            _liveTradingDataFeed.Initialize(algo, jobPacket, new LiveTradingResultHandler(), new LocalDiskMapFileProvider(),
                                            null, dataProvider, dataManager, _liveSynchronizer, new DataChannelProvider());
            algo.Initialize();

            _config = SecurityTests.CreateTradeBarConfig();
        }
        public static SecurityExchangeHours CreateUsFutureSecurityExchangeHours()
        {
            var sunday = LocalMarketHours.OpenAllDay(DayOfWeek.Sunday);
            var monday = new LocalMarketHours(
                DayOfWeek.Monday,
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(0, 0, 0), new TimeSpan(16, 15, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(16, 30, 0), new TimeSpan(17, 0, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(18, 0, 0), new TimeSpan(24, 0, 0))
                );
            var tuesday = new LocalMarketHours(
                DayOfWeek.Tuesday,
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(0, 0, 0), new TimeSpan(16, 15, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(16, 30, 0), new TimeSpan(17, 0, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(18, 0, 0), new TimeSpan(24, 0, 0))
                );
            var wednesday = new LocalMarketHours(
                DayOfWeek.Wednesday,
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(0, 0, 0), new TimeSpan(16, 15, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(16, 30, 0), new TimeSpan(17, 0, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(18, 0, 0), new TimeSpan(24, 0, 0))
                );
            var thursday = new LocalMarketHours(
                DayOfWeek.Thursday,
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(0, 0, 0), new TimeSpan(16, 15, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(16, 30, 0), new TimeSpan(17, 0, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(18, 0, 0), new TimeSpan(24, 0, 0))
                );
            var friday = new LocalMarketHours(
                DayOfWeek.Friday,
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(0, 0, 0), new TimeSpan(16, 15, 0)),
                new MarketHoursSegment(MarketHoursState.Market, new TimeSpan(16, 30, 0), new TimeSpan(17, 0, 0))
                );
            var saturday = LocalMarketHours.ClosedAllDay(DayOfWeek.Saturday);

            var earlyCloses = new Dictionary <DateTime, TimeSpan> {
                { new DateTime(2013, 11, 28), new TimeSpan(10, 30, 0) },
                { new DateTime(2013, 11, 29), new TimeSpan(12, 15, 0) }
            };
            var lateOpens     = new Dictionary <DateTime, TimeSpan>();
            var exchangeHours = new SecurityExchangeHours(TimeZones.NewYork, USHoliday.Dates.Select(x => x.Date), new[]
            {
                sunday, monday, tuesday, wednesday, thursday, friday, saturday
            }.ToDictionary(x => x.DayOfWeek), earlyCloses, lateOpens);

            return(exchangeHours);
        }
示例#9
0
        public static SecurityExchangeHours CreateForexSecurityExchangeHours()
        {
            var sunday    = new LocalMarketHours(DayOfWeek.Sunday, new TimeSpan(17, 0, 0), TimeSpan.FromTicks(Time.OneDay.Ticks - 1));
            var monday    = LocalMarketHours.OpenAllDay(DayOfWeek.Monday);
            var tuesday   = LocalMarketHours.OpenAllDay(DayOfWeek.Tuesday);
            var wednesday = LocalMarketHours.OpenAllDay(DayOfWeek.Wednesday);
            var thursday  = LocalMarketHours.OpenAllDay(DayOfWeek.Thursday);
            var friday    = new LocalMarketHours(DayOfWeek.Friday, TimeSpan.Zero, new TimeSpan(17, 0, 0));
            var saturday  = LocalMarketHours.ClosedAllDay(DayOfWeek.Saturday);

            var exchangeHours = new SecurityExchangeHours(TimeZones.NewYork, USHoliday.Dates.Select(x => x.Date), new[]
            {
                sunday, monday, tuesday, wednesday, thursday, friday//, saturday
            }.ToDictionary(x => x.DayOfWeek));

            return(exchangeHours);
        }