### Install FinancialModelingPrep NuGet Package Source: https://github.com/matthiware/financialmodelingprep.net/blob/master/README.md This command installs the MatthiWare.FinancialModelingPrep library into your .NET project using the NuGet Package Manager console. ```PowerShell PM> Install-Package MatthiWare.FinancialModelingPrep ``` -------------------------------- ### Get Stock Price Quote using C# Source: https://github.com/matthiware/financialmodelingprep.net/blob/master/README.md This C# code snippet demonstrates how to use the initialized API client to fetch the latest stock price quote for a given symbol (AAPL in this case) and print the price to the console. ```C# var response = await api.CompanyValuation.GetQuoteAsync("AAPL"); // Display Apple Stock Quote Console.WriteLine($"$AAPL is currently trading at: {response.Data.Price}"); ``` -------------------------------- ### Create FMP API Client using Factory Source: https://github.com/matthiware/financialmodelingprep.net/blob/master/README.md This C# code snippet shows how to create an instance of the FinancialModelingPrepApiClient directly using the factory method, without relying on a Dependency Injection container. This is useful for simple applications or scenarios where DI is not used. ```C# using MatthiWare.FinancialModelingPrep; var api = FinancialModelingPrepApiClientFactory.CreateClient(new FinancialModelingPrepOptions()); // do something with api like getting the latest Apple Stock Quote var quoteResult = await api.CompanyValuation.GetQuoteAsync("AAPL"); ``` -------------------------------- ### Register FinancialModelingPrepApiClient in Dependency Injection Source: https://github.com/matthiware/financialmodelingprep.net/blob/master/README.md This C# code snippet demonstrates how to register the FinancialModelingPrepApiClient with a .NET Dependency Injection container, typically in your application's startup configuration. It requires providing your API key via the FinancialModelingPrepOptions. ```C# using MatthiWare.FinancialModelingPrep; Services.AddFinancialModelingPrepApiClient(new FinancialModelingPrepOptions() { ApiKey = "API-KEY-HERE" }); var api = ServiceProvider.GetRequiredService(); // do something with api like getting the latest Apple Stock Quote var quoteResult = await api.CompanyValuation.GetQuoteAsync("AAPL"); ``` -------------------------------- ### ApiResponse Generic Wrapper Structure Source: https://github.com/matthiware/financialmodelingprep.net/blob/master/README.md This C# code defines the structure of the generic ApiResponse class used by the library to wrap all API responses. It includes properties for the data, error message, and a flag indicating if an error occurred. ```C# public class ApiResponse { /// /// Error message if any occured /// public string Error { get; } /// /// True if there was an error with the request otherwise false /// public bool HasError { get; } /// /// The FMP API response object /// public T Data { get; } } ``` -------------------------------- ### Handle ApiResponse Error in C# Source: https://github.com/matthiware/financialmodelingprep.net/blob/master/README.md This C# code snippet demonstrates how to check the HasError property of the ApiResponse object after making an API call and handle potential errors by checking the Error property. ```C# var response = await api.CompanyValuation.GetQuoteAsync("AAPL"); // Display Apple Stock Quote if (!quoteResult.HasError) { Console.WriteLine($"$AAPL is currently trading at: {response.Data.Price}"); } else { Console.WriteLine($"Error occured, message: {response.Error}"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.