public void UpdateForexFactory() { List <DateTimeUTC> query_date_list = new List <DateTimeUTC>(); if (LastUpdateDateTime < ToolsForexFactory.InitialDate) { LastUpdateDateTime = ToolsForexFactory.InitialDate; } DateTimeUTC current_time = DateTimeUTC.Now; query_date_list.Add(LastUpdateDateTime.GetDayEqualOrBefore(DayOfWeek.Monday)); while (query_date_list[query_date_list.Count - 1] <= current_time) { query_date_list.Add(query_date_list[query_date_list.Count - 1].AddDays(7)); } foreach (DateTimeUTC query_date in query_date_list) { List <TradingCalenderEvent> trading_calendar_event_list = ToolsForexFactory.GetTradingCalendarEvents(query_date); foreach (TradingCalenderEvent trading_calender_event in trading_calendar_event_list) { event_list.Add(trading_calender_event); } } }
public static List <TradingCalenderEvent> GetTradingCalendarEvents(DateTimeUTC week_start) { List <TradingCalenderEvent> trading_callender_event_list = new List <TradingCalenderEvent>(); List <ForexFactoryEvent> forex_factory_event_list = GetForexFactoryEvents(week_start); foreach (ForexFactoryEvent forex_factory_event in forex_factory_event_list) { DateTime event_time_local = DateTime.Now; bool is_all_day = false; if (!forex_factory_event.TimeString.Contains(":")) { is_all_day = true; } int year = forex_factory_event.WeekStartDay.Year; int month = MonthToInt(forex_factory_event.DateString.Split(' ')[0]); int day = int.Parse(forex_factory_event.DateString.Split(' ')[1]); if (is_all_day) { event_time_local = new DateTime(year, month, day, 0, 0, 0); } else { int hour = int.Parse(forex_factory_event.TimeString.Split(':')[0]); int minutes = int.Parse(forex_factory_event.TimeString.Split(':')[1].Substring(0, 2)); if (forex_factory_event.TimeString.Split(':')[1].Substring(2).Equals("pm")) { hour += 12; } if (24 <= hour) { event_time_local = new DateTime(year, month, day, hour - 24, minutes, 0); event_time_local.AddDays(1); } else { event_time_local = new DateTime(year, month, day, hour, minutes, 0); } } Dictionary <string, string> tags = new Dictionary <string, string>(); tags.Add(TradingCalenderEvent.TagImpact, forex_factory_event.Impact); tags.Add(TradingCalenderEvent.TagActual, forex_factory_event.Actual); tags.Add(TradingCalenderEvent.TagPrevious, forex_factory_event.Previous); tags.Add(TradingCalenderEvent.TagForecast, forex_factory_event.Forecast); //Here is some daylight savings time bullshit //if ("Daylight Saving Time Shift".Equals(forex_factory_event.Description)) // { // event_time_local = event_time_local.AddSeconds(-1); //} try { TimeZoneInfo.ConvertTimeToUtc(event_time_local, time_zone_est); } catch (Exception) { Console.WriteLine("Illigal Date time"); event_time_local = event_time_local.AddHours(1); tags.Add(TradingCalenderEvent.TagIllegalDateTime, TradingCalenderEvent.TagIllegalDateTime); } DateTimeUTC event_time_utc = new DateTimeUTC(event_time_local, time_zone_est); if (event_time_utc.GetDayEqualOrBefore(DayOfWeek.Monday).Year < event_time_utc.Year) { event_time_utc = event_time_utc.AddYears(1); } trading_callender_event_list.Add(new TradingCalenderEvent( event_time_utc, forex_factory_event.Symbol, forex_factory_event.Description, is_all_day, tags)); } return(trading_callender_event_list); }