Add project files.
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
using OemanTrader.Domain.Exceptions;
|
||||
using OemanTrader.Domain.Services;
|
||||
using OemanTrader.FinantialModelingPrepAPI.Results;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OemanTrader.FinantialModelingPrepAPI.Services
|
||||
{
|
||||
public class StockPriceService : IStockPriceService
|
||||
{
|
||||
private readonly FinancialModelingPrepHttpClientFactory _httpClientFactory;
|
||||
|
||||
public StockPriceService(FinancialModelingPrepHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
public async Task<double> GetPrice(string symbol)
|
||||
{
|
||||
using (FinancialModelingPrepHttpClient client = _httpClientFactory.CreateHttpClient())
|
||||
{
|
||||
string uri = "stock/real-time-price/" + symbol;
|
||||
|
||||
//HttpResponseMessage response = await client.GetAsync(uri + "?apikey=2035d4934632e1d7c38f15982e39d3aa");
|
||||
StockPriceResult stockPriceResult = await client.GetAsync<StockPriceResult>(uri);
|
||||
|
||||
if (stockPriceResult.Price == 0)
|
||||
{
|
||||
throw new InvalidSymbolException(symbol);
|
||||
}
|
||||
|
||||
return stockPriceResult.Price;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user