17 using System.Collections.Generic;
18 using System.Globalization;
80 private readonly
string _baseUrl =
@"https://api.intrinio.com/historical_data.csv?";
85 private bool _backtestingFirstTimeCallOrLiveMode =
true;
100 _dataTransformation = dataTransformation;
106 InvalidOperationException(
"Please set a valid Intrinio user and password using the 'IntrinioEconomicData.SetUserAndPassword' static method. " +
107 "For local backtesting, the user and password can be set in the 'parameters' fields from the 'config.json' file.");
132 if (_backtestingFirstTimeCallOrLiveMode)
138 _backtestingFirstTimeCallOrLiveMode =
false || isLiveMode;
139 subscription = GetIntrinioSubscription(config, isLiveMode);
162 var obs = line.Split(
',');
163 var time = DateTime.MinValue;
164 if (!DateTime.TryParseExact(obs[0],
"yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None,
165 out time))
return null;
166 var value = obs[1].ToDecimal();
179 switch (dataTransformation)
188 item =
"c_annual_roc";
191 item =
"cc_annual_roc";
203 item =
"percent_change";
206 item =
"yr_percent_change";
215 var order = isLiveMode ?
"desc" :
"asc";
216 var item = GetStringForDataTransformation(_dataTransformation);
217 var url = $
"{_baseUrl}identifier={config.Symbol.Value}&item={item}&sort_order={order}";
218 var byteKey = Encoding.ASCII.GetBytes($
"{IntrinioConfig.User}:{IntrinioConfig.Password}");
219 var authorizationHeaders =
new List<KeyValuePair<string, string>>
221 new KeyValuePair<string, string>(
"Authorization",
222 $
"Basic ({Convert.ToBase64String(byteKey)})")
226 authorizationHeaders);