Beispiel #1
0
        protected override void Initialize()
        {
            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(e.Message);
                _newsItems = new List <NewsItem>();
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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>();

            if (showLow)
            {
                importanceFilter.Add(Importance.Low);
            }

            if (showMedium)
            {
                importanceFilter.Add(Importance.Medium);
            }

            if (showHigh)
            {
                importanceFilter.Add(Importance.High);
            }

            newsItems = 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
                };

                newsItems = newsItems.Where(x => currencyFilter.Contains(x.Currency)).ToList();
            }

            return(newsItems);
        }