public void DeserializesProperlyUsingCSV() { var instance = new TradingEconomicsCalendar(); var csv = JsonConvert.DeserializeObject <List <TradingEconomicsCalendar> >(TestCalendarJson).First().ToCsv(); var result = instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create($"UNITED-STATES{TradingEconomics.Calendar.Delimiter}US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), csv, new DateTime(2019, 1, 1), false ); var calendar = (TradingEconomicsCalendar)result; Assert.AreEqual("0", calendar.CalendarId); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.Time.Date); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.EndTime.Date); Assert.AreEqual("United States", calendar.Country); Assert.AreEqual("PPI PCE", calendar.Category); Assert.AreEqual("producer price index personal consumption expenditure price index yoy", calendar.Event); Assert.AreEqual("Jan", calendar.Reference); Assert.AreEqual("U.S.", calendar.Source); Assert.AreEqual(0m, calendar.Actual); Assert.AreEqual(0m, calendar.Previous); Assert.AreEqual(null, calendar.Forecast); Assert.AreEqual(0m, calendar.TradingEconomicsForecast); Assert.AreEqual("0", calendar.DateSpan); Assert.AreEqual(TradingEconomicsImportance.High, calendar.Importance); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.LastUpdate.Date); Assert.AreEqual(0m, calendar.Revised); Assert.AreEqual("United States", calendar.OCountry); Assert.AreEqual("PPI PCE", calendar.OCategory); Assert.AreEqual("US", calendar.Ticker); Assert.AreEqual(true, calendar.IsPercentage); }
public void DeserializesProperlyUsingJsonStringReader() { var instance = new TradingEconomicsCalendar(); var result = instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create("UNITED-STATES//US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), TestCalendarRawAPIResponseJSON, new DateTime(2019, 1, 1), true ); var calendar = (TradingEconomicsCalendar)((BaseDataCollection)result).Data.Single(); Assert.AreEqual("0", calendar.CalendarId); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.Time.Date); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.EndTime.Date); Assert.AreEqual("United States", calendar.Country); Assert.AreEqual("PPI PCE", calendar.Category); Assert.AreEqual("producer price index personal consumption expenditure price index yoy", calendar.Event); Assert.AreEqual("Jan", calendar.Reference); Assert.AreEqual("U.S.", calendar.Source); Assert.AreEqual(0m, calendar.Actual); Assert.AreEqual(0m, calendar.Previous); Assert.AreEqual(null, calendar.Forecast); Assert.AreEqual(0m, calendar.TradingEconomicsForecast); Assert.AreEqual("0", calendar.DateSpan); Assert.AreEqual(TradingEconomicsImportance.High, calendar.Importance); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.LastUpdate.Date); Assert.AreEqual(0m, calendar.Revised); Assert.AreEqual("United States", calendar.OCountry); Assert.AreEqual("PPI PCE", calendar.OCategory); Assert.AreEqual("US", calendar.Ticker); Assert.AreEqual(true, calendar.IsPercentage); }
public void ReturnsNullOnInvalidSymbolOrDate_AndContinuesWithoutErrors() { var instance = new TradingEconomicsCalendar(); var normalLines = new List <string>(); var corruptedLines = new List <string>(); var deserialized = JsonConvert.DeserializeObject <List <TradingEconomicsCalendar> >(TestCalendarJson).First(); for (var i = 0; i < 5; i++) { normalLines.Add(deserialized.ToCsv()); } deserialized.Ticker = "Foobar" + deserialized.Ticker; for (var i = 0; i < 5; i++) { corruptedLines.Add(deserialized.ToCsv()); } var corruptedResult = instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create("UNITED-STATES//US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), corruptedLines.First(), new DateTime(2019, 1, 1), false ); var corruptedNormalResult = instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create("UNITED-STATES//US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), normalLines.First(), DateTime.MaxValue, false ); Assert.AreEqual(null, corruptedResult); Assert.AreEqual(null, corruptedNormalResult); foreach (var line in normalLines.Skip(1)) { var calendar = (TradingEconomicsCalendar)instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create("UNITED-STATES//US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), line, new DateTime(2019, 1, 1), false ); Assert.AreEqual("0", calendar.CalendarId); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.Time.Date); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.EndTime.Date); Assert.AreEqual("United States", calendar.Country); Assert.AreEqual("PPI PCE", calendar.Category); Assert.AreEqual("producer price index personal consumption expenditure price index yoy", calendar.Event); Assert.AreEqual("Jan", calendar.Reference); Assert.AreEqual("U.S.", calendar.Source); Assert.AreEqual(0m, calendar.Actual); Assert.AreEqual(0m, calendar.Previous); Assert.AreEqual(null, calendar.Forecast); Assert.AreEqual(0m, calendar.TradingEconomicsForecast); Assert.AreEqual("0", calendar.DateSpan); Assert.AreEqual(TradingEconomicsImportance.High, calendar.Importance); Assert.AreEqual(new DateTime(2019, 1, 1), calendar.LastUpdate.Date); Assert.AreEqual(0m, calendar.Revised); Assert.AreEqual("United States", calendar.OCountry); Assert.AreEqual("PPI PCE", calendar.OCategory); Assert.AreEqual("US", calendar.Ticker); Assert.AreEqual(true, calendar.IsPercentage); } }
public void ReaderDeserializationProducesSameResult() { var instance = new TradingEconomicsCalendar(); var csv = JsonConvert.DeserializeObject <List <TradingEconomicsCalendar> >(TestCalendarJson).Single().ToCsv(); var resultBacktest = instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create("UNITED-STATES//US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), csv, new DateTime(2019, 1, 1), false ); var resultLive = instance.Reader( new SubscriptionDataConfig( typeof(TradingEconomicsCalendar), Symbol.CreateBase(typeof(TradingEconomicsCalendar), Symbol.Create("UNITED-STATES//US", SecurityType.Base, QuantConnect.Market.USA), QuantConnect.Market.USA), Resolution.Daily, TimeZones.Utc, TimeZones.Utc, false, false, false, isCustom: true ), TestCalendarRawAPIResponseJSON, new DateTime(2019, 1, 1), true ); var calendarBacktest = (TradingEconomicsCalendar)resultBacktest; var calendarLive = (TradingEconomicsCalendar)((BaseDataCollection)resultLive).Data.Single(); Assert.AreEqual(calendarBacktest.CalendarId, calendarLive.CalendarId); Assert.AreEqual(calendarBacktest.Time.Date, calendarLive.Time.Date); Assert.AreEqual(calendarBacktest.EndTime.Date, calendarLive.EndTime.Date); Assert.AreEqual(calendarBacktest.Country, calendarLive.Country); Assert.AreEqual(calendarBacktest.Category, calendarLive.Category); Assert.AreEqual(calendarBacktest.Event, calendarLive.Event); Assert.AreEqual(calendarBacktest.Reference, calendarLive.Reference); Assert.AreEqual(calendarBacktest.Source, calendarLive.Source); Assert.AreEqual(calendarBacktest.Actual, calendarLive.Actual); Assert.AreEqual(calendarBacktest.Previous, calendarLive.Previous); Assert.AreEqual(calendarBacktest.Forecast, calendarLive.Forecast); Assert.AreEqual(calendarBacktest.TradingEconomicsForecast, calendarLive.TradingEconomicsForecast); Assert.AreEqual(calendarBacktest.DateSpan, calendarLive.DateSpan); Assert.AreEqual(calendarBacktest.Importance, calendarLive.Importance); Assert.AreEqual(calendarBacktest.LastUpdate.Date, calendarLive.LastUpdate.Date); Assert.AreEqual(calendarBacktest.Revised, calendarLive.Revised); Assert.AreEqual(calendarBacktest.OCountry, calendarLive.OCountry); Assert.AreEqual(calendarBacktest.OCategory, calendarLive.OCategory); Assert.AreEqual(calendarBacktest.Ticker, calendarLive.Ticker); Assert.AreEqual(calendarBacktest.IsPercentage, calendarLive.IsPercentage); }