Files
oemanxTrader/OemanTrader.FinantialModelingPrepAPI/Services/MajorIndexService.cs
2022-05-26 15:19:31 +02:00

51 lines
1.6 KiB
C#

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.");
}
}
}
}