|
| 1 | +using MatthiWare.FinancialModelingPrep.Abstractions.StockMarket; |
| 2 | +using MatthiWare.FinancialModelingPrep.Core.Http; |
| 3 | +using MatthiWare.FinancialModelingPrep.Model; |
| 4 | +using MatthiWare.FinancialModelingPrep.Model.StockMarket; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Collections.Specialized; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace MatthiWare.FinancialModelingPrep.Core.StockMarket |
| 10 | +{ |
| 11 | + public sealed class StockMarketProvider : IStockMarketProvider |
| 12 | + { |
| 13 | + private const string ActivesEndpoint = "actives"; |
| 14 | + private const string GainersEndpoint = "gainers"; |
| 15 | + private const string LosersEndpoint = "losers"; |
| 16 | + |
| 17 | + private readonly FinancialModelingPrepHttpClient client; |
| 18 | + |
| 19 | + public StockMarketProvider(FinancialModelingPrepHttpClient client) |
| 20 | + { |
| 21 | + this.client = client ?? throw new System.ArgumentNullException(nameof(client)); |
| 22 | + } |
| 23 | + |
| 24 | + public Task<ApiResponse<List<StockMarketSymbolResponse>>> GetBiggestGainerStocksAsync() |
| 25 | + => GetStockMarketData(GainersEndpoint); |
| 26 | + |
| 27 | + public Task<ApiResponse<List<StockMarketSymbolResponse>>> GetBiggestLoserStocksAsync() |
| 28 | + => GetStockMarketData(LosersEndpoint); |
| 29 | + |
| 30 | + public Task<ApiResponse<List<StockMarketSymbolResponse>>> GetMostActiveStocksAsync() |
| 31 | + => GetStockMarketData(ActivesEndpoint); |
| 32 | + |
| 33 | + private Task<ApiResponse<List<StockMarketSymbolResponse>>> GetStockMarketData(string endpoint) |
| 34 | + { |
| 35 | + const string url = "[version]/[endpoint]"; |
| 36 | + |
| 37 | + var pathParams = new NameValueCollection() |
| 38 | + { |
| 39 | + { "version", ApiVersion.v3.ToString() }, |
| 40 | + { "endpoint", endpoint }, |
| 41 | + }; |
| 42 | + |
| 43 | + return client.GetJsonAsync<List<StockMarketSymbolResponse>>(url, pathParams, null); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments