Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forex, Futures, Crypto and Stock updates #51

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ public interface IAdvancedDataProvider
Task<ApiResponse<SharesFloatResponse>> GetSharesFloatAsync(string symbol);

Task<ApiResponse<List<ESGScoreResponse>>> GetESGScoreAsync(string symbol);

Task<ApiResponse<List<FinancialScoreResponse>>> GetFinancialScore(string symbol);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.Crypto;
using MatthiWare.FinancialModelingPrep.Model.StockMarket;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MatthiWare.FinancialModelingPrep.Abstractions.StockMarket
namespace MatthiWare.FinancialModelingPrep.Abstractions.Crypto
{
public interface ICryptoMarketProvider
{
public Task<ApiResponse<List<CryptoItem>>> GetAvilableCryptocurrencies();
Task<ApiResponse<List<CryptoItem>>> GetAvilableCryptocurrenciesAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task<ApiResponse<List<CryptoItem>>> GetAvailableCryptocurrenciesAsync();


public Task<ApiResponse<List<CryptoHistoricalPricePeriodListing>>> GetHistoricalPrices(string symbol, HistoricalPricingPeriod period);
Task<ApiResponse<List<CryptoHistoricalPricePeriodListing>>> GetHistoricalQuoteAsync(string symbol, HistoricalPricingPeriod period);

public Task<ApiResponse<CryptoHistoricalPriceDailyItem>> GetDailyPrices(string symbol);
Task<ApiResponse<CryptoHistoricalPriceDailyItem>> GetDailyPricesAsync(string symbol);

Task<ApiResponse<List<CryptoQuoteResponse>>> GetQuoteAsync(string symbol);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.Forex;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MatthiWare.FinancialModelingPrep.Abstractions.Forex
{
public interface IForexMarketProvider
{
Task<ApiResponse<List<ForexBookResponse>>> GetBookAsync(string symbol);

Task<ApiResponse<List<ForexQuoteResponse>>> GetQuoteAsync(string symbol);

Task<ApiResponse<List<ForexHistoricalQuoteResponse>>> GetHistoricalQuoteAsync(string symbol, HistoricalPricingPeriod period);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.Futures;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace MatthiWare.FinancialModelingPrep.Abstractions.Futures
{
public interface IFuturesMarketProvider
{
Task<ApiResponse<List<FuturesQuoteResponse>>> GetQuoteAsync(string symbol);

Task<ApiResponse<List<FuturesHistoricalQuoteResponse>>> GetHistoricalQuoteAsync(string symbol, HistoricalPricingPeriod period);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using MatthiWare.FinancialModelingPrep.Abstractions.AdvancedData;
using MatthiWare.FinancialModelingPrep.Abstractions.Calendars;
using MatthiWare.FinancialModelingPrep.Abstractions.CompanyValuation;
using MatthiWare.FinancialModelingPrep.Abstractions.Crypto;
using MatthiWare.FinancialModelingPrep.Abstractions.Forex;
using MatthiWare.FinancialModelingPrep.Abstractions.Fund;
using MatthiWare.FinancialModelingPrep.Abstractions.Futures;
using MatthiWare.FinancialModelingPrep.Abstractions.InstitutionalFund;
using MatthiWare.FinancialModelingPrep.Abstractions.MarketIndexes;
using MatthiWare.FinancialModelingPrep.Abstractions.Statistics;
Expand Down Expand Up @@ -61,6 +64,16 @@ public interface IFinancialModelingPrepApiClient
/// </summary>
ICryptoMarketProvider Crypto { get; }

/// <summary>
/// Forex related enpoints
/// </summary>
IForexMarketProvider Forex { get; }

/// <summary>
/// Futures related enpoints
/// </summary>
IFuturesMarketProvider Futures { get; }

/// <summary>
/// ETF/Mutual Fund related enpoints
/// </summary>
Expand Down
70 changes: 70 additions & 0 deletions FinancialModelingPrepApi/Abstractions/Model/ICurrentQuote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Text.Json.Serialization;

namespace MatthiWare.FinancialModelingPrep.Abstractions.Model
{
public interface ICurrentQuote
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have this interface, just create the different models with the properties that they have.
Futures/Forex Quote models should not be forced to implement the Eps or PE properties

{
[JsonPropertyName("symbol")]
public string Symbol { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("exchange")]
public string Exchange { get; set; }

[JsonPropertyName("open")]
public decimal Open { get; set; }

[JsonPropertyName("price")]
public decimal Price { get; set; }

[JsonPropertyName("previousclose")]
public decimal PreviousClose { get; set; }

[JsonPropertyName("daylow")]
public decimal DayLow { get; set; }

[JsonPropertyName("dayhigh")]
public decimal DayHigh { get; set; }

[JsonPropertyName("yearlow")]
public decimal YearlyLow { get; set; }

[JsonPropertyName("yearhigh")]
public decimal YearlyHigh { get; set; }

[JsonPropertyName("priceavg50")]
public decimal PriceAvg50 { get; set; }

[JsonPropertyName("priceavg200")]
public decimal PriceAvg200 { get; set; }

[JsonPropertyName("change")]
public decimal Change { get; set; }

[JsonPropertyName("changespercentage")]
public decimal ChangesPercentage { get; set; }

[JsonPropertyName("timestamp")]
public long Timestamp { get; set; }

// Not used by Forex or Futures.

[JsonPropertyName("eps")]
public decimal? Eps { get; set; }

[JsonPropertyName("pe")]
public decimal? Pe { get; set; }

[JsonPropertyName("earningsAnnouncement")]
public string? EarningsAnnouncement { get; set; }

[JsonPropertyName("sharesOutstanding")]
public long? SharesOutstanding { get; set; }

[JsonPropertyName("marketCap")]
public decimal? MarketCap { get; set; }
}
}
33 changes: 33 additions & 0 deletions FinancialModelingPrepApi/Abstractions/Model/IHistoricalQuote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace MatthiWare.FinancialModelingPrep.Abstractions.Model
{
public interface IHistoricalQuote
{
[JsonPropertyName("date")]
public string Date { get; set; }

[JsonPropertyName("open")]
public decimal Open { get; set; }

[JsonPropertyName("high")]
public decimal High { get; set; }

[JsonPropertyName("low")]
public decimal Low { get; set; }

[JsonPropertyName("close")]
public decimal Close { get; set; }

[JsonPropertyName("change")]
public decimal? Change { get; set; }

[JsonPropertyName("changePercent")]
public decimal? ChangePercent { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.StockMarket;
using MatthiWare.FinancialModelingPrep.Model.StockTimeSeries;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -7,6 +8,12 @@ namespace MatthiWare.FinancialModelingPrep.Abstractions.StockTimeSeries
{
public interface IStockTimeSeriesProvider
{
/// <summary>
/// Get the latest quote for given stock.
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public Task<ApiResponse<List<StockQuoteResponse>>> GetQuoteAsync(string symbol);
/// <summary>
/// Get Daily Historical Dividends
/// </summary>
Expand Down
28 changes: 25 additions & 3 deletions FinancialModelingPrepApi/Core/AdvancedData/AdvancedDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,29 @@ private async Task<ApiResponse<StandardIndustrialClassificationResponse>> GetSta
return ApiResponse.FromError<StandardIndustrialClassificationResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public async Task<ApiResponse<List<FinancialScoreResponse>>> GetFinancialScore(string symbol)
{
const string url = "[version]/score";

var pathParams = new NameValueCollection()
{
{ "version", ApiVersion.v4.ToString() }
};

var queryString = new QueryStringBuilder();
queryString.Add("symbol", symbol);

var result = await client.GetJsonAsync<List<FinancialScoreResponse>>(url, pathParams, queryString);

if (result.HasError)
{
return ApiResponse.FromError<List<FinancialScoreResponse>>(result.Error);
}

return ApiResponse.FromSuccess(result.Data);
}

public async Task<ApiResponse<CompanyPeersResponse>> GetStockPeersAsync(string symbol)
Expand All @@ -99,7 +121,7 @@ public async Task<ApiResponse<CompanyPeersResponse>> GetStockPeersAsync(string s
return ApiResponse.FromError<CompanyPeersResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<SectorPEResponse>>> GetSectorsPriceEarningsRatioAsync(string date, string exchange)
Expand Down Expand Up @@ -156,7 +178,7 @@ public async Task<ApiResponse<SharesFloatResponse>> GetSharesFloatAsync(string s
return ApiResponse.FromError<SharesFloatResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<ESGScoreResponse>>> GetESGScoreAsync(string symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<ApiResponse<CompanyProfileResponse>> GetCompanyProfileAsync(st
return ApiResponse.FromError<CompanyProfileResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<SymbolResponse>>> GetETFListAsync()
Expand Down Expand Up @@ -264,7 +264,7 @@ public async Task<ApiResponse<CompanyRatingResponse>> GetCompanyRatingAsync(stri
return ApiResponse.FromError<CompanyRatingResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<CompanyRatingResponse>>> GetHistoricalCompanyRatingAsync(string symbol, int? limit = 140)
Expand Down Expand Up @@ -304,7 +304,7 @@ public async Task<ApiResponse<DCFResponse>> GetDiscountedCashFlowAsync(string sy
return ApiResponse.FromError<DCFResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<HistoricalDCFResponse>>> GetHistoricalDiscountedCashFlowAsync(string symbol, Period period = Period.Annual)
Expand Down Expand Up @@ -364,7 +364,7 @@ public async Task<ApiResponse<RatiosTTMResponse>> GetRatiosTTMAsync(string symbo
return ApiResponse.FromError<RatiosTTMResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public async Task<ApiResponse<KeyMetricsTTMResponse>> GetCompanyKeyMetricsTTMAsync(string symbol)
Expand All @@ -384,7 +384,7 @@ public async Task<ApiResponse<KeyMetricsTTMResponse>> GetCompanyKeyMetricsTTMAsy
return ApiResponse.FromError<KeyMetricsTTMResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<KeyMetricsResponse>>> GetCompanyKeyMetricsAsync(string symbol, Period period = Period.Annual, int? limit = 130)
Expand Down Expand Up @@ -429,7 +429,7 @@ public async Task<ApiResponse<QuoteResponse>> GetQuoteAsync(string symbol)
return ApiResponse.FromError<QuoteResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<QuoteResponse>>> GetQuotesAsync(IEnumerable<string> symbols)
Expand Down Expand Up @@ -482,7 +482,7 @@ public async Task<ApiResponse<MarketCapResponse>> GetMarketCapitalizationAsync(s
return ApiResponse.FromError<MarketCapResponse>(result.Error);
}

return ApiResponse.FromSucces(result.Data.First());
return ApiResponse.FromSuccess(result.Data.First());
}

public Task<ApiResponse<List<MarketCapResponse>>> GetHistoricalMarketCapitalizationAsync(string symbol, int? limit = 100)
Expand Down
31 changes: 21 additions & 10 deletions FinancialModelingPrepApi/Core/Crypto/CryptoMarketProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using MatthiWare.FinancialModelingPrep.Abstractions.StockMarket;
using MatthiWare.FinancialModelingPrep.Abstractions.Crypto;
using MatthiWare.FinancialModelingPrep.Abstractions.StockMarket;
using MatthiWare.FinancialModelingPrep.Core.Http;
using MatthiWare.FinancialModelingPrep.Model;
using MatthiWare.FinancialModelingPrep.Model.Crypto;
using MatthiWare.FinancialModelingPrep.Model.StockMarket;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading.Tasks;
Expand All @@ -18,7 +18,7 @@ public CryptoMarketProvider(FinancialModelingPrepHttpClient client)
this.client = client ?? throw new System.ArgumentNullException(nameof(client));
}

public Task<ApiResponse<List<CryptoItem>>> GetAvilableCryptocurrencies()
public async Task<ApiResponse<List<CryptoItem>>> GetAvilableCryptocurrenciesAsync()
{

const string url = "[version]/symbol/available-cryptocurrencies";
Expand All @@ -28,10 +28,23 @@ public Task<ApiResponse<List<CryptoItem>>> GetAvilableCryptocurrencies()
{ "version", ApiVersion.v3.ToString() }
};

return client.GetJsonAsync<List<CryptoItem>>(url, pathParams, null);
return await client.GetJsonAsync<List<CryptoItem>>(url, pathParams, null);
}

public Task<ApiResponse<CryptoHistoricalPriceDailyItem>> GetDailyPrices(string symbol)
public async Task<ApiResponse<List<CryptoQuoteResponse>>> GetQuoteAsync(string symbol)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just await the Task without doing anything with it you can remove the async/await keywords here.
Only the first caller in the call stack that needs to do something with the result needs to await it.

{
const string url = "[version]/quote/[symbol]";

var pathParams = new NameValueCollection()
{
{ "version", ApiVersion.v3.ToString() },
{ "symbol", symbol },
};

return await client.GetJsonAsync<List<CryptoQuoteResponse>>(url, pathParams, null);
}

public async Task<ApiResponse<CryptoHistoricalPriceDailyItem>> GetDailyPricesAsync(string symbol)
{
const string url = "[version]/historical-price-full/[symbol]";

Expand All @@ -41,10 +54,10 @@ public Task<ApiResponse<CryptoHistoricalPriceDailyItem>> GetDailyPrices(string s
{ "symbol", symbol }
};

return client.GetJsonAsync<CryptoHistoricalPriceDailyItem>(url, pathParams, null);
return await client.GetJsonAsync<CryptoHistoricalPriceDailyItem>(url, pathParams, null);
}

public Task<ApiResponse<List<CryptoHistoricalPricePeriodListing>>> GetHistoricalPrices(string symbol, HistoricalPricingPeriod period)
public async Task<ApiResponse<List<CryptoHistoricalPricePeriodListing>>> GetHistoricalQuoteAsync(string symbol, HistoricalPricingPeriod period)
{
const string url = "[version]/historical-chart/[pricePeriod]/[symbol]";

Expand All @@ -57,9 +70,7 @@ public Task<ApiResponse<List<CryptoHistoricalPricePeriodListing>>> GetHistorical
{ "pricePeriod", pricePeriod }
};

var queryString = new QueryStringBuilder();

return client.GetJsonAsync<List<CryptoHistoricalPricePeriodListing>>(url, pathParams, queryString);
return await client.GetJsonAsync<List<CryptoHistoricalPricePeriodListing>>(url, pathParams, null);
}
}
}
Loading