Add project files.
This commit is contained in:
@ -0,0 +1,50 @@
|
||||
using Newtonsoft.Json;
|
||||
using OemanTrader.Domain.Models;
|
||||
using OemanTrader.Domain.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OemanTrader.FinantialModelingPrepAPI.Services
|
||||
{
|
||||
public class MajorIndexService : IMajorIndexService
|
||||
{
|
||||
private readonly FinancialModelingPrepHttpClientFactory _httpClientFactory;
|
||||
|
||||
public MajorIndexService(FinancialModelingPrepHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
public async Task<MajorIndex> GetMajorIndex(MajorIndexType indexType)
|
||||
{
|
||||
using (FinancialModelingPrepHttpClient client = _httpClientFactory.CreateHttpClient())
|
||||
{
|
||||
string uri = "majors-indexes/" + GetUriSuffix(indexType);
|
||||
|
||||
//HttpResponseMessage response = await client.GetAsync(uri + "?apikey=2035d4934632e1d7c38f15982e39d3aa");
|
||||
MajorIndex majorIndex = await client.GetAsync<MajorIndex>(uri);
|
||||
majorIndex.Type = indexType;
|
||||
|
||||
return majorIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetUriSuffix(MajorIndexType indexType)
|
||||
{
|
||||
switch (indexType)
|
||||
{
|
||||
case MajorIndexType.DowJones:
|
||||
return ".DJI";
|
||||
case MajorIndexType.Nasdaq:
|
||||
return ".IXIC";
|
||||
case MajorIndexType.SP500:
|
||||
return ".INX";
|
||||
default:
|
||||
throw new Exception("MajorIndexType does not have a suffix defined.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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