private void SetSymbolAndTime(TiingoNews dataPoint)
 {
     if (_symbol != null)
     {
         dataPoint.Symbol = _symbol;
         if (_liveMode)
         {
             // for live use crawl date
             dataPoint.Time = dataPoint.CrawlDate;
         }
         else
         {
             if ((dataPoint.CrawlDate - dataPoint.PublishedDate) > Time.OneDay)
             {
                 // old data (eg 2014 PublishedDate) can have newer crawl date (eg 2019)
                 // for these cases, for backtesting, use published time + 'TiingoNews.HistoricalCrawlOffset'
                 dataPoint.Time = dataPoint.PublishedDate.Add(TiingoNews.HistoricalCrawlOffset);
             }
             else
             {
                 dataPoint.Time = dataPoint.CrawlDate;
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Helper method to deserialize a single json Tiingo news
        /// </summary>
        /// <param name="token">The json token containing the Tiingo news to deserialize</param>
        /// <returns>The deserialized <see cref="TiingoNews"/> instance</returns>
        public static TiingoNews DeserializeNews(JToken token)
        {
            // just in case we add some default values for these
            var title       = token["title"]?.ToString() ?? "";
            var source      = token["source"]?.ToString() ?? "";
            var url         = token["url"]?.ToString() ?? "";
            var tags        = token["tags"]?.ToObject <List <string> >() ?? new List <string>();
            var description = token["description"]?.ToString() ?? "";

            var publishedDate = GetDateTime(token["publishedDate"]);
            var crawlDate     = GetDateTime(token["crawlDate"]);
            var articleID     = token["id"].ToString();
            var tickers       = token["tickers"];
            // 'time' is QC time which could be crawl time or published data + offset (see converter) this is not present in live
            // which will use 'crawlDate'
            var time = GetDateTime(token["time"], defaultValue: crawlDate);

            var symbols = new List <Symbol>();

            foreach (var tiingoTicker in tickers)
            {
                var rawTicker = tiingoTicker.ToString();
                if (rawTicker.Contains(" ") || rawTicker.Contains("|"))
                {
                    Log.Trace($"TiingoNewsJsonConverter.DeserializeNews(): Article ID {articleID}, ignoring ticker [{rawTicker}] because it contains space or pipe character.");
                    continue;
                }

                var ticker = TiingoSymbolMapper.GetLeanTicker(rawTicker);
                var sid    = SecurityIdentifier.GenerateEquity(
                    ticker,
                    // for now we suppose USA market
                    QuantConnect.Market.USA,
                    // we use the news date to resolve the map file to use
                    mappingResolveDate: publishedDate);
                symbols.Add(new Symbol(sid, ticker));
            }

            var dataPoint = new TiingoNews
            {
                ArticleID     = articleID,
                CrawlDate     = crawlDate,
                Description   = description,
                PublishedDate = publishedDate,
                Time          = time,
                Source        = source,
                Tags          = tags,
                Symbols       = symbols,
                Url           = url,
                Title         = title
            };

            return(dataPoint);
        }
        /// <summary>
        /// Helper method to deserialize a single json Tiingo news
        /// </summary>
        /// <param name="token">The json token containing the Tiingo news to deserialize</param>
        /// <returns>The deserialized <see cref="TiingoNews"/> instance</returns>
        public static TiingoNews DeserializeNews(JToken token)
        {
            // just in case we add some default values for these
            var title       = token["title"]?.ToString() ?? "";
            var source      = token["source"]?.ToString() ?? "";
            var url         = token["url"]?.ToString() ?? "";
            var tags        = token["tags"]?.ToObject <List <string> >() ?? new List <string>();
            var description = token["description"]?.ToString() ?? "";

            var publishedDate = GetDateTime(token["publishedDate"]);
            var crawlDate     = GetDateTime(token["crawlDate"]);
            var articleID     = token["id"].ToString();
            var tickers       = token["tickers"];

            var symbols = new List <Symbol>();

            foreach (var tiingoTicker in tickers)
            {
                var ticker = TiingoSymbolMapper.GetLeanTicker(tiingoTicker.ToString());

                var sid = SecurityIdentifier.GenerateEquity(
                    ticker,
                    // for now we suppose USA market
                    QuantConnect.Market.USA,
                    // we use the news date to resolve the map file to use
                    mappingResolveDate: publishedDate);
                symbols.Add(new Symbol(sid, ticker));
            }

            var dataPoint = new TiingoNews
            {
                ArticleID     = articleID,
                CrawlDate     = crawlDate,
                Description   = description,
                PublishedDate = publishedDate,
                Time          = publishedDate,
                Source        = source,
                Tags          = tags,
                Symbols       = symbols,
                Url           = url,
                Title         = title
            };

            return(dataPoint);
        }