public async Task <IEXResponse <ReturnType> > SymbolLastExecuteAsync <ReturnType>(string urlPattern, string symbol, int last) where ReturnType : class { var qsb = new QueryStringBuilder(); var pathNvc = new NameValueCollection { { "symbol", symbol }, { "last", last.ToString() } }; return(await ExecuteAsync <ReturnType>(urlPattern, pathNvc, qsb)); }
public async Task <IEXResponse <ReturnType> > SymbolsExecuteAsync <ReturnType>(string urlPattern, IEnumerable <string> symbols) where ReturnType : class { var qsb = new QueryStringBuilder(); qsb.Add("symbols", string.Join(",", symbols)); var pathNvc = new NameValueCollection(); return(await ExecuteAsync <ReturnType>(urlPattern, pathNvc, qsb)); }
public async Task <ReturnType> NoParamExecute <ReturnType>(string url, string token) where ReturnType : class { var qsb = new QueryStringBuilder(); if (!string.IsNullOrEmpty(token)) { qsb.Add("token", token); } var pathNVC = new NameValueCollection(); return(await ExecuteAsyncLegacy <ReturnType>(url, pathNVC, qsb)); }
public SSEClient <T> SymbolsSubscribeSSE <T>(string urlPattern, IEnumerable <string> symbols, string token) where T : class { var qsb = new QueryStringBuilder(); if (!string.IsNullOrEmpty(token)) { qsb.Add("token", token); } qsb.Add("symbols", string.Join(",", symbols)); var pathNvc = new NameValueCollection(); return(SubscribeToSSE <T>(urlPattern, pathNvc, qsb)); }
public async Task <string> SymbolLastFieldExecuteAsync(string urlPattern, string symbol, string field, int last, string token) { var qsb = new QueryStringBuilder(); if (!string.IsNullOrEmpty(token)) { qsb.Add("token", token); } var pathNvc = new NameValueCollection { { "symbol", symbol }, { "last", last.ToString() }, { "field", field } }; return(await ExecuteAsyncLegacy <string>(urlPattern, pathNvc, qsb)); }
public async Task <ReturnType> SymbolsExecuteAsync <ReturnType>(string urlPattern, IEnumerable <string> symbols, string token) where ReturnType : class { var qsb = new QueryStringBuilder(); if (!string.IsNullOrEmpty(token)) { qsb.Add("token", token); } qsb.Add("symbols", string.Join(",", symbols)); var pathNvc = new NameValueCollection(); return(await ExecuteAsyncLegacy <ReturnType>(urlPattern, pathNvc, qsb)); }
public async Task <ReturnType> SymbolLastExecuteAsync <ReturnType>(string urlPattern, string symbol, int last, string token) where ReturnType : class { var qsb = new QueryStringBuilder(); if (!string.IsNullOrEmpty(token)) { qsb.Add("token", token); } var pathNvc = new NameValueCollection { { "symbol", symbol }, { "last", last.ToString() } }; return(await ExecuteAsyncLegacy <ReturnType>(urlPattern, pathNvc, qsb)); }
public SSEClient <T> SubscribeToSSE <T>(string urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb) { ValidateAndProcessParams(ref urlPattern, ref pathNVC, ref qsb); var url = $"{baseSSEURL}{urlPattern}{qsb.Build()}"; return(new SSEClient <T>(Configuration.Builder(new Uri(url)).Build())); }
public async Task <IEXResponse <ReturnType> > ExecuteAsync <ReturnType>( string urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb, bool forceUseSecretToken = false) where ReturnType : class { ValidateAndProcessParams(ref urlPattern, ref pathNVC, ref qsb); if (!string.IsNullOrEmpty(publishableToken) && !forceUseSecretToken) { qsb.Add("token", publishableToken); } if (!string.IsNullOrEmpty(secretToken) && forceUseSecretToken) { qsb.Add("token", secretToken); } var content = string.Empty; if (sign) { client.DefaultRequestHeaders.Remove("x-iex-date"); client.DefaultRequestHeaders.Remove("Authorization"); (string iexdate, string authorization_header)headers = signer.Sign(publishableToken, "GET", urlPattern, qsb.Build()); client.DefaultRequestHeaders.TryAddWithoutValidation("x-iex-date", headers.iexdate); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", headers.authorization_header); } using (var responseContent = await client.GetAsync($"{urlPattern}{qsb.Build()}")) { try { content = await responseContent.Content.ReadAsStringAsync(); if (content.Length > 7 && content.Substring(startIndex: 0, length: 8) == "{\"error\"") { // {"error":"child \"token\" fails because [\"token\" must be a string]"} var token = JToken.Parse(content); return(new IEXResponse <ReturnType>() { ErrorMessage = token["error"].ToString() }); } else if (content == "Forbidden" || content == "Not found") { // "Forbidden" or "Not found" return(new IEXResponse <ReturnType>() { ErrorMessage = content }); } else { return new IEXResponse <ReturnType>() { Data = JsonConvert.DeserializeObject <ReturnType>(content, jsonSerializerSettings) } }; } catch (JsonException ex) { throw new JsonException(content, ex); } } }
protected static void ValidateAndProcessParams(ref string urlPattern, ref NameValueCollection pathNVC, ref QueryStringBuilder qsb) { if (string.IsNullOrWhiteSpace(urlPattern)) { throw new ArgumentException("urlPattern cannot be null"); } else if (pathNVC == null) { throw new ArgumentException("pathNVC cannot be null"); } qsb = qsb ?? new QueryStringBuilder(); if (pathNVC.Count > 0) { foreach (string key in pathNVC.Keys) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException("pathNVC cannot be null"); } else if (string.IsNullOrWhiteSpace(pathNVC[key])) { throw new ArgumentException($"pathNVC {key} value cannot be null"); } else if (urlPattern.IndexOf($"[{key}]") < 0) { throw new ArgumentException($"urlPattern doesn't contain key [{key}]"); } else { urlPattern = urlPattern.Replace($"[{key}]", pathNVC[key]); } } } }
public async Task <ReturnType> ExecuteAsyncLegacy <ReturnType>(string urlPattern, NameValueCollection pathNVC, QueryStringBuilder qsb) where ReturnType : class { ValidateAndProcessParams(ref urlPattern, ref pathNVC, ref qsb); if (!string.IsNullOrEmpty(publishableToken)) { qsb.Add("token", publishableToken); } var content = string.Empty; if (sign) { client.DefaultRequestHeaders.Remove("x-iex-date"); client.DefaultRequestHeaders.Remove("Authorization"); (string iexdate, string authorization_header)headers = signer.Sign(publishableToken, "GET", urlPattern, qsb.Build()); client.DefaultRequestHeaders.TryAddWithoutValidation("x-iex-date", headers.iexdate); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", headers.authorization_header); } using (var responseContent = await client.GetAsync($"{urlPattern}{qsb.Build()}")) { try { content = await responseContent.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <ReturnType>(content, jsonSerializerSettings)); } catch (JsonException ex) { throw new JsonException(content, ex); } } }