public async Task <StockResult> GetStock(string symbol) { string apikey = "f39e00235a58b78bd6299026e09d244c"; string uri = $"quote/{symbol}?apikey={apikey}"; using FinancialModelingPrepHttpClient client = new FinancialModelingPrepHttpClient(); IEnumerable <StockResult> results = await client.GetJsonResponse <IEnumerable <StockResult> >(uri); // 增加异常处理 if (!results.Any()) { throw new InvalidSymbolException(symbol); } return(results.FirstOrDefault()); }
public async Task <Majorindex> GetMajorindices(MajorindexType indexType) { string apikey = "f39e00235a58b78bd6299026e09d244c"; #region 封装前 //string uri = $"https://financialmodelingprep.com/api/v3/quote/{GetUriSuffix(indexType)}?apikey={apikey}"; //using var client = new HttpClient(); //HttpResponseMessage response = await client.GetAsync(uri); //string jsonResponse = await response.Content.ReadAsStringAsync(); //// 最后结果为数组 //var result = JsonSerializer.Deserialize<IEnumerable<Majorindex>>(jsonResponse, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); #endregion string uri = $"quote/{GetUriSuffix(indexType)}?apikey={apikey}"; using FinancialModelingPrepHttpClient client = new FinancialModelingPrepHttpClient(); var results = await client.GetJsonResponse <IEnumerable <Majorindex> >(uri); // 数组中就一个对象 return(results.FirstOrDefault()); }