Skip to content

Commit 164947c

Browse files
committed
Add from and to parameters for stock time series
1 parent 7631005 commit 164947c

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

FinancialModelingPrepApi/Abstractions/StockTimeSeries/IStockTimeSeriesProvider.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,31 @@ public interface IStockTimeSeriesProvider
2727
/// <returns><see cref="HistoricalPriceResponse"/></returns>
2828
Task<ApiResponse<HistoricalPriceResponse>> GetHistoricalDailyPricesAsync(string symbol);
2929

30+
/// <summary>
31+
/// Get Daily Historical Prices
32+
/// </summary>
33+
/// <param name="symbol">Ticker symbol</param>
34+
/// <param name="from">From date (YYYY-MM-DD)</param>
35+
/// <param name="to">To date (YYYY-MM-DD)</param>
36+
/// <returns><see cref="HistoricalPriceResponse"/></returns>
37+
Task<ApiResponse<HistoricalPriceResponse>> GetHistoricalDailyPricesAsync(string symbol, string from, string to);
38+
3039
/// <summary>
3140
/// Get Daily Historical Prices
3241
/// Should be used to display on a linechart
3342
/// </summary>
3443
/// <param name="symbol">Ticker symbol</param>
3544
/// <returns><see cref="HistoricalPriceForLineChartResponse"/></returns>
3645
Task<ApiResponse<HistoricalPriceForLineChartResponse>> GetHistoricalDailyPricesForLineChartAsync(string symbol);
46+
47+
/// <summary>
48+
/// Get Daily Historical Prices
49+
/// Should be used to display on a linechart
50+
/// </summary>
51+
/// <param name="symbol">Ticker symbol</param>
52+
/// <param name="from">From date (YYYY-MM-DD)</param>
53+
/// <param name="to">To date (YYYY-MM-DD)</param>
54+
/// <returns><see cref="HistoricalPriceForLineChartResponse"/></returns>
55+
Task<ApiResponse<HistoricalPriceForLineChartResponse>> GetHistoricalDailyPricesForLineChartAsync(string symbol, string from, string to);
3756
}
3857
}

FinancialModelingPrepApi/Core/StockTimeSeries/StockTimeSeriesProvider.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ public Task<ApiResponse<HistoricalPriceResponse>> GetHistoricalDailyPricesAsync(
3030

3131
return client.GetJsonAsync<HistoricalPriceResponse>(url, pathParams, null);
3232
}
33+
34+
/// <inheritdoc/>
35+
public Task<ApiResponse<HistoricalPriceResponse>> GetHistoricalDailyPricesAsync(string symbol, string from, string to)
36+
{
37+
const string url = "[version]/historical-price-full/[symbol]";
38+
39+
var pathParams = new NameValueCollection()
40+
{
41+
{ "version", ApiVersion.v3.ToString() },
42+
{ "symbol", symbol }
43+
};
44+
45+
var queryString = new QueryStringBuilder();
46+
queryString.Add("from", from);
47+
queryString.Add("to", to);
48+
49+
return client.GetJsonAsync<HistoricalPriceResponse>(url, pathParams, queryString);
50+
}
3351

3452
/// <inheritdoc/>
3553
public Task<ApiResponse<HistoricalPriceForLineChartResponse>> GetHistoricalDailyPricesForLineChartAsync(string symbol)
@@ -49,6 +67,26 @@ public Task<ApiResponse<HistoricalPriceForLineChartResponse>> GetHistoricalDaily
4967
return client.GetJsonAsync<HistoricalPriceForLineChartResponse>(url, pathParams, queryString);
5068
}
5169

70+
/// <inheritdoc/>
71+
public Task<ApiResponse<HistoricalPriceForLineChartResponse>> GetHistoricalDailyPricesForLineChartAsync(string symbol, string from, string to)
72+
{
73+
const string url = "[version]/historical-price-full/[symbol]";
74+
75+
var pathParams = new NameValueCollection()
76+
{
77+
{ "version", ApiVersion.v3.ToString() },
78+
{ "symbol", symbol }
79+
};
80+
81+
var queryString = new QueryStringBuilder();
82+
83+
queryString.Add("serietype", "line");
84+
queryString.Add("from", from);
85+
queryString.Add("to", to);
86+
87+
return client.GetJsonAsync<HistoricalPriceForLineChartResponse>(url, pathParams, queryString);
88+
}
89+
5290
/// <inheritdoc/>
5391
public Task<ApiResponse<HistoricalDividendsResponse>> GetHistoricalDividendsAsync(string symbol)
5492
{

Tests/StockTimeSeries/StockTimeSeriesTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ public async Task GetHistoricalDailyPricesAsync()
5959
Assert.Equal(123.85, split.Low, 2);
6060
}
6161

62+
[Fact]
63+
public async Task GetHistoricalDailyPricesUsingFromToAsync()
64+
{
65+
var result = await api.GetHistoricalDailyPricesAsync("AAPL", "2021-06-03", "2021-06-05");
66+
67+
result.AssertNoErrors();
68+
69+
Assert.Equal(2, result.Data.Historical.Count);
70+
71+
var split = result.Data.Historical.First(data => data.Date == "2021-06-04");
72+
73+
Assert.Equal(125.89, split.Close, 2);
74+
Assert.Equal(124.07, split.Open, 2);
75+
Assert.Equal(126.16, split.High, 2);
76+
Assert.Equal(123.85, split.Low, 2);
77+
}
78+
6279
[Fact]
6380
public async Task GetHistoricalDailyPricesForLineChartAsync()
6481
{
@@ -70,5 +87,19 @@ public async Task GetHistoricalDailyPricesForLineChartAsync()
7087

7188
Assert.Equal(125.89, split.Close, 2);
7289
}
90+
91+
[Fact]
92+
public async Task GetHistoricalDailyPricesForLineChartUsingFromToAsync()
93+
{
94+
var result = await api.GetHistoricalDailyPricesForLineChartAsync("AAPL", "2021-06-03", "2021-06-05");
95+
96+
result.AssertNoErrors();
97+
98+
Assert.Equal(2, result.Data.Historical.Count);
99+
100+
var split = result.Data.Historical.First(data => data.Date == "2021-06-04");
101+
102+
Assert.Equal(125.89, split.Close, 2);
103+
}
73104
}
74105
}

0 commit comments

Comments
 (0)