예제 #1
0
        static void Main(string[] args)
        {
            IServiceProvider   services = ServiceProviderBuilder.GetServiceProvider(args);
            IOptions <APIKeys> options  = services.GetRequiredService <IOptions <APIKeys> >();

            SampleData.Root gnpcaData = CallAPI.CallLatestDataAPI("GNPCA", new DateTime(2010, 1, 1), DateTime.Now, options.Value.FRED);

            Console.ReadLine();
        }
예제 #2
0
        public static SampleData.Root CallLatestDataAPI(string sereisID, DateTime startDt, DateTime endDt, string apiKey)
        {
            SampleData.Root returnObject = new SampleData.Root();
            string          content      = string.Empty;
            string          url          = string.Format("https://api.stlouisfed.org/fred/series/observations?series_id={0}&observation_start={1}&observation_end={2}&api_key={3}&file_type=json", sereisID, startDt.ToString("yyy-MM-dd"), endDt.ToString("yyyy-MM-dd"), apiKey);
            WebRequest      myReq        = WebRequest.Create(url);

            using (WebResponse wr = myReq.GetResponse())
                using (Stream receiveStream = wr.GetResponseStream())
                    using (StreamReader sReader = new StreamReader(receiveStream, Encoding.UTF8))
                        content = sReader.ReadToEnd();
            return(JsonSerializer.Deserialize <SampleData.Root>(content));
        }