Skip to content

Commit bc8240b

Browse files
committed
Add Search by name and search by ticker endpoints
1 parent 87ad2a6 commit bc8240b

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

FinancialModelingPrepApi/Abstractions/CompanyValuation/ICompanyValuationProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public interface ICompanyValuationProvider
1010
public Task<ApiResponse<QuoteResponse>> GetQuoteAsync(string symbol);
1111
public Task<ApiResponse<List<QuoteResponse>>> GetQuotesAsync(Exchange exchange);
1212

13+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchAsync(string query, Exchange exchange, int? limit = null);
14+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchByTickerAsync(string query, Exchange exchange, int? limit = null);
15+
1316
public Task<ApiResponse<CompanyProfileResponse>> GetCompanyProfileAsync(string symbol);
1417
public Task<ApiResponse<KeyMetricsTTMResponse>> GetCompanyKeyMetricsTTMAsync(string symbol);
1518
public Task<ApiResponse<List<KeyMetricsResponse>>> GetCompanyKeyMetricsAsync(string symbol, Period period = Period.Annual, int? limit = 130);

FinancialModelingPrepApi/Core/CompanyValuation/CompanyValuationProvider.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Task<ApiResponse<List<EnterpriseValueResponse>>> GetEnterpriseValueAsync(
8787
var queryString = new QueryStringBuilder();
8888

8989
if (limit != null)
90-
{
90+
{
9191
queryString.Add("limit", limit);
9292
}
9393

@@ -410,5 +410,34 @@ public Task<ApiResponse<List<MarketCapResponse>>> GetHistoricalMarketCapitalizat
410410

411411
return client.GetJsonAsync<List<MarketCapResponse>>(url, pathParams, queryString);
412412
}
413+
414+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchAsync(string query, Exchange exchange, int? limit = null)
415+
=> SearchInternalAsync(query, exchange, false, limit);
416+
417+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchByTickerAsync(string query, Exchange exchange, int? limit = null)
418+
=> SearchInternalAsync(query, exchange, true, limit);
419+
420+
private Task<ApiResponse<List<TickerSearchResponse>>> SearchInternalAsync(string query, Exchange exchange, bool byTicker, int? limit)
421+
{
422+
const string url = "[version]/search";
423+
const string urlByTicker = "[version]/search-ticker";
424+
425+
var pathParams = new NameValueCollection()
426+
{
427+
{ "version", ApiVersion.v3.ToString() },
428+
};
429+
430+
var queryString = new QueryStringBuilder();
431+
432+
queryString.Add("query", query);
433+
queryString.Add("exchange", exchange.ToString());
434+
435+
if (limit != null)
436+
{
437+
queryString.Add("limit", limit);
438+
}
439+
440+
return client.GetJsonAsync<List<TickerSearchResponse>>(byTicker ? urlByTicker : url, pathParams, queryString);
441+
}
413442
}
414443
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrep.Model.CompanyValuation
4+
{
5+
public class TickerSearchResponse
6+
{
7+
[JsonPropertyName("symbol")]
8+
public string Symbol { get; set; }
9+
10+
[JsonPropertyName("name")]
11+
public string Name { get; set; }
12+
13+
[JsonPropertyName("currency")]
14+
public string Currency { get; set; }
15+
16+
[JsonPropertyName("stockExchange")]
17+
public string StockExchange { get; set; }
18+
19+
[JsonPropertyName("exchangeShortName")]
20+
public string ExchangeShortName { get; set; }
21+
}
22+
}

Tests/CompanyValuation/CompanyValuationTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections;
77
using System.Collections.Generic;
8+
using System.Linq;
89
using System.Threading.Tasks;
910
using Xunit;
1011
using Xunit.Abstractions;
@@ -208,6 +209,32 @@ public async Task GetQuoteAsync()
208209
Assert.Equal("AAPL", result.Data.Symbol);
209210
}
210211

212+
[Fact]
213+
public async Task SearchAsync()
214+
{
215+
var result = await api.SearchAsync("Ageas", Exchange.EURONEXT, 5);
216+
217+
result.AssertNoErrors();
218+
Assert.NotEmpty(result.Data);
219+
Assert.True(result.Data.Count <= 5);
220+
221+
var firstResult = result.Data.First(_ => _.Symbol == "AGS.BR");
222+
Assert.Equal("AGS.BR", firstResult.Symbol);
223+
}
224+
225+
[Fact]
226+
public async Task SearchByTickerAsync()
227+
{
228+
var result = await api.SearchByTickerAsync("AGS", Exchange.EURONEXT, 5);
229+
230+
result.AssertNoErrors();
231+
Assert.NotEmpty(result.Data);
232+
Assert.True(result.Data.Count <= 5);
233+
234+
var firstResult = result.Data.First(_ => _.Symbol == "AGS.BR");
235+
Assert.Equal("AGS.BR", firstResult.Symbol);
236+
}
237+
211238
[Fact]
212239
public async Task GetHistoricalMarketCapAsync()
213240
{

0 commit comments

Comments
 (0)