protected override void OnStart() { try { Log("Initialising"); Log("TimeZone Setting: {0}", TimeZone); Log("TimeZone Name: {0}", TimeZone.DisplayName); Log("Offset: {0}", TimeZone.BaseUtcOffset); Log("DST: {0}", TimeZone.SupportsDaylightSavingTime); var downloader = new DailyFxDownloader(this); var allNewsItems = downloader.Download(PastNewsLookback); Log(string.Format("{0} events loaded", allNewsItems.Count)); _symbol = new SymbolWrapper(Symbol.Code); _newsItems = NewsRepository.FilterNews(allNewsItems, ShowLow, ShowMedium, ShowHigh, SymbolFilter, _symbol); List <NewsGroup <NewsItem> > groupList = NewsRepository.GroupNews(_newsItems, _symbol); _groups = groupList.ToDictionary(x => x.Time); Log("{0} groups created", _groups.Count); } catch (Exception e) { Log("Exception1: {0}", e.Message); _newsItems = new List <NewsItem>(); } //On a new position check One Cancle Other Positions.Opened += OnPositionOpened; Timer.Start(1); //We need to catch the excpetion if the list is empty for some reason try { NI = DisplayUpcomingNews(); _triggerTimeInServerTimeZone = NI.UtcDateTime; } catch (Exception e) { Log("Exception2: {0}", e.Message); } }
public static List <NewsGroup <T> > GroupNews <T>(List <T> newsList, SymbolWrapper symbol) where T : INewsItem { var groups = newsList.GroupBy(x => x.UtcDateTime).Select(x => new NewsGroup <T> { Time = x.Key, BaseCurrencyNews = new CurrencyNews <T> { NewsList = x.Where(y => y.Currency == symbol.BaseCurrency).ToList(), Currency = symbol.BaseCurrency, Time = x.Key }, QuoteCurrencyNews = new CurrencyNews <T> { NewsList = x.Where(y => y.Currency == symbol.QuoteCurrency).ToList(), Currency = symbol.QuoteCurrency, Time = x.Key } }).ToList(); return(groups); }
public static List <T> FilterNews <T>(List <T> newsItems, bool showLow, bool showMedium, bool showHigh, bool symbolFilter, SymbolWrapper symbol) where T : INewsItem { //improtance filter var importanceFilter = new List <Importance>(); var newsI = new List <T>(); if (showLow) { importanceFilter.Add(Importance.Low); } if (showMedium) { importanceFilter.Add(Importance.Medium); } if (showHigh) { importanceFilter.Add(Importance.High); } newsI = newsItems.Where(x => x.Importance.HasValue && importanceFilter.Contains(x.Importance.Value)).OrderBy(x => x.UtcDateTime).ToList(); if (symbolFilter) { //show events only applicable to this currency var currencyFilter = new[] { symbol.BaseCurrency, symbol.QuoteCurrency }; newsI = newsI.Where(x => currencyFilter.Contains(x.Currency)).ToList(); } return(newsI); }