/// <summary> /// For backtesting returns the index source for a date /// For live trading will return the source url to use, not using the index mechanism /// </summary> /// <param name="config">Configuration object</param> /// <param name="date">Date of this source file</param> /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param> /// <returns>The <see cref="SubscriptionDataSource"/> instance to use</returns> public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { if (isLiveMode) { if (!Tiingo.IsAuthCodeSet) { throw new InvalidOperationException("TiingoNews API token has to be set using Tiingo.SetAuthCode(). See https://api.tiingo.com/about/pricing"); } var tiingoTicker = TiingoSymbolMapper.GetTiingoTicker(config.Symbol); var url = Invariant($"https://api.tiingo.com/tiingo/news?tickers={tiingoTicker}&startDate={date:yyyy-MM-dd}&token={Tiingo.AuthCode}&sortBy=crawlDate"); return(new SubscriptionDataSource(url, SubscriptionTransportMedium.Rest, FileFormat.Collection)); } var source = Path.Combine( Globals.DataFolder, "alternative", "tiingo", $"{config.MappedSymbol.ToLowerInvariant()}", $"{date.ToStringInvariant(DateFormat.EightCharacter)}.csv" ); return(new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile, FileFormat.Index)); }
/// <summary> /// Return the URL string source of the file. This will be converted to a stream /// </summary> /// <param name="config">Configuration object</param> /// <param name="date">Date of this source file</param> /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param> /// <returns>String URL of source file.</returns> public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { DateTime startDate; if (!_startDates.TryGetValue(config.Symbol.Value, out startDate)) { startDate = date; _startDates.TryAdd(config.Symbol.Value, startDate); } var tiingoTicker = TiingoSymbolMapper.GetTiingoTicker(config.Symbol); var source = Invariant($"https://api.tiingo.com/tiingo/daily/{tiingoTicker}/prices?startDate={startDate:yyyy-MM-dd}&token={Tiingo.AuthCode}"); return(new SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile, FileFormat.Collection)); }