Skip to content

Commit 24ea29a

Browse files
walterfranssenWalter Franssen
andauthored
Add nullalbe exchange on company search search (#35)
* Add nullalbe exchange on company search search * fixed unit test Co-authored-by: Walter Franssen <walter.franssen@centric.eu>
1 parent 937088e commit 24ea29a

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

FinancialModelingPrepApi/Abstractions/CompanyValuation/ICompanyValuationProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public interface ICompanyValuationProvider
1111
public Task<ApiResponse<List<QuoteResponse>>> GetQuotesAsync(IEnumerable<string> symbols);
1212
public Task<ApiResponse<List<QuoteResponse>>> GetQuotesAsync(Exchange exchange);
1313

14-
public Task<ApiResponse<List<TickerSearchResponse>>> SearchAsync(string query, Exchange exchange, int? limit = null);
15-
public Task<ApiResponse<List<TickerSearchResponse>>> SearchByTickerAsync(string query, Exchange exchange, int? limit = null);
14+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchAsync(string query, Exchange? exchange, int? limit = null);
15+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchByTickerAsync(string query, Exchange? exchange, int? limit = null);
1616

1717
public Task<ApiResponse<CompanyProfileResponse>> GetCompanyProfileAsync(string symbol);
1818
public Task<ApiResponse<RatiosTTMResponse>> GetRatiosTTMAsync(string symbol);

FinancialModelingPrepApi/Core/CompanyValuation/CompanyValuationProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,13 @@ public Task<ApiResponse<List<MarketCapResponse>>> GetHistoricalMarketCapitalizat
504504
return client.GetJsonAsync<List<MarketCapResponse>>(url, pathParams, queryString);
505505
}
506506

507-
public Task<ApiResponse<List<TickerSearchResponse>>> SearchAsync(string query, Exchange exchange, int? limit = null)
507+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchAsync(string query, Exchange? exchange, int? limit = null)
508508
=> SearchInternalAsync(query, exchange, false, limit);
509509

510-
public Task<ApiResponse<List<TickerSearchResponse>>> SearchByTickerAsync(string query, Exchange exchange, int? limit = null)
510+
public Task<ApiResponse<List<TickerSearchResponse>>> SearchByTickerAsync(string query, Exchange? exchange, int? limit = null)
511511
=> SearchInternalAsync(query, exchange, true, limit);
512512

513-
private Task<ApiResponse<List<TickerSearchResponse>>> SearchInternalAsync(string query, Exchange exchange, bool byTicker, int? limit)
513+
private Task<ApiResponse<List<TickerSearchResponse>>> SearchInternalAsync(string query, Exchange? exchange, bool byTicker, int? limit)
514514
{
515515
const string url = "[version]/search";
516516
const string urlByTicker = "[version]/search-ticker";
@@ -523,7 +523,7 @@ private Task<ApiResponse<List<TickerSearchResponse>>> SearchInternalAsync(string
523523
var queryString = new QueryStringBuilder();
524524

525525
queryString.Add("query", query);
526-
queryString.Add("exchange", exchange.ToString());
526+
if (exchange.HasValue) queryString.Add("exchange", exchange.Value.ToString());
527527

528528
if (limit != null)
529529
{

Tests/CompanyValuation/CompanyValuationTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ public async Task SearchByTickerAsync()
363363
Assert.Equal("AGS.BR", firstResult.Symbol);
364364
}
365365

366+
[Fact]
367+
public async Task SearchByTickerWithoutExchangeAsync()
368+
{
369+
var result = await api.SearchByTickerAsync("AAPL", null, 5);
370+
371+
result.AssertNoErrors();
372+
Assert.NotEmpty(result.Data);
373+
Assert.True(result.Data.Count >= 1);
374+
375+
var firstResult = result.Data.First(_ => _.Symbol == "AAPL");
376+
Assert.Equal("AAPL", firstResult.Symbol);
377+
}
378+
366379
[Fact]
367380
public async Task GetHistoricalMarketCapAsync()
368381
{

0 commit comments

Comments
 (0)