Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jabacrack committed May 6, 2024
1 parent 1368b5d commit 8dbd0f7
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 28 deletions.
44 changes: 44 additions & 0 deletions YahooFinanceApi.Tests/ProfileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace YahooFinanceApi.Tests;

public class ProfileTests
{
[Fact]
public async Task TestProfileAsync()
{
const string AAPL = "AAPL";

var aaplProfile = await Yahoo.QueryProfileAsync(AAPL);

Assert.NotNull(aaplProfile.Address1);
Assert.NotNull(aaplProfile.AuditRisk);
Assert.NotNull(aaplProfile.BoardRisk);
Assert.NotNull(aaplProfile.City);
Assert.NotNull(aaplProfile.CompanyOfficers);
Assert.NotNull(aaplProfile.CompensationAsOfEpochDate);
Assert.NotNull(aaplProfile.CompensationRisk);
Assert.NotNull(aaplProfile.Country);
Assert.NotNull(aaplProfile.FullTimeEmployees);
Assert.NotNull(aaplProfile.GovernanceEpochDate);
Assert.NotNull(aaplProfile.Industry);
Assert.NotNull(aaplProfile.IndustryDisp);
Assert.NotNull(aaplProfile.IndustryKey);
Assert.NotNull(aaplProfile.LongBusinessSummary);
Assert.NotNull(aaplProfile.MaxAge);
Assert.NotNull(aaplProfile.State);
Assert.NotNull(aaplProfile.Zip);
Assert.NotNull(aaplProfile.Phone);
Assert.NotNull(aaplProfile.Website);
Assert.NotNull(aaplProfile.Sector);
Assert.NotNull(aaplProfile.SectorKey);
Assert.NotNull(aaplProfile.SectorDisp);
Assert.NotNull(aaplProfile.ShareHolderRightsRisk);
Assert.NotNull(aaplProfile.OverallRisk);
}
}
26 changes: 0 additions & 26 deletions YahooFinanceApi.Tests/QuoteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,6 @@ public async Task TestQuoteAsync()
DateTime estDate = TimeZoneInfo.ConvertTimeFromUtc(date, TzEst);
}

[Fact]
public async Task TestSummaryAsync()
{
const string AAPL = "AAPL";

var quote = await Yahoo.QuerySummaryAsync(AAPL);

var aaplQuote = quote[AAPL];
var aaplOpen = aaplQuote[Field.RegularMarketOpen.ToString()];
var aaplHigh = aaplQuote[Field.RegularMarketDayHigh.ToString()];
var aaplLow = aaplQuote[Field.RegularMarketDayLow.ToString()];
var aaplCurrentPrice = aaplQuote[Field.RegularMarketPrice.ToString()];
var aaplVolume = aaplQuote[Field.RegularMarketVolume.ToString()];
var aaplTime = aaplQuote[Field.RegularMarketTime.ToString()];

// Get New York Timezone for conversion from UTC to New York Time for Yahoo Quotes
TimeZoneInfo TzEst = TimeZoneInfo
.GetSystemTimeZones()
.Single(tz => tz.Id == "Eastern Standard Time" || tz.Id == "America/New_York");

long unixDate = 1568232001; // Any unix timestamp
DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime date = start.AddSeconds(unixDate);
DateTime estDate = TimeZoneInfo.ConvertTimeFromUtc(date, TzEst);
}

[Fact]
public async Task TestSymbolsArgument()
{
Expand Down
29 changes: 29 additions & 0 deletions YahooFinanceApi/ProfileFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace YahooFinanceApi;

public enum ProfileFields
{
Address1,
City,
State,
Zip,
Country,
Phone,
Website,
Industry,
IndustryKey,
IndustryDisp,
Sector,
SectorKey,
SectorDisp,
LongBusinessSummary,
FullTimeEmployees,
CompanyOfficers,
AuditRisk,
BoardRisk,
CompensationRisk,
ShareHolderRightsRisk,
OverallRisk,
GovernanceEpochDate,
CompensationAsOfEpochDate,
MaxAge,
}
29 changes: 28 additions & 1 deletion YahooFinanceApi/SecurityProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace YahooFinanceApi;

Expand All @@ -10,4 +11,30 @@ public class SecurityProfile
internal SecurityProfile(IReadOnlyDictionary<string, dynamic> fields) => Fields = fields;

public dynamic this[string fieldName] => Fields[fieldName];
public dynamic this[ProfileFields field] => Fields[field.ToString()];

public string Address1 => this[ProfileFields.Address1];
public string City => this[ProfileFields.City];
public string State => this[ProfileFields.State];
public string Zip => this[ProfileFields.Zip];
public string Country => this[ProfileFields.Country];
public string Phone => this[ProfileFields.Phone];
public string Website => this[ProfileFields.Website];
public string Industry => this[ProfileFields.Industry];
public string IndustryKey => this[ProfileFields.IndustryKey];
public string IndustryDisp => this[ProfileFields.IndustryDisp];
public string Sector => this[ProfileFields.Sector];
public string SectorKey => this[ProfileFields.SectorKey];
public string SectorDisp => this[ProfileFields.SectorDisp];
public string LongBusinessSummary => this[ProfileFields.LongBusinessSummary];
public long FullTimeEmployees => this[ProfileFields.FullTimeEmployees];
public List<dynamic> CompanyOfficers => this[ProfileFields.CompanyOfficers];
public long AuditRisk => this[ProfileFields.AuditRisk];
public long BoardRisk => this[ProfileFields.BoardRisk];
public long CompensationRisk => this[ProfileFields.CompensationRisk];
public long ShareHolderRightsRisk => this[ProfileFields.ShareHolderRightsRisk];
public long OverallRisk => this[ProfileFields.OverallRisk];
public DateTime GovernanceEpochDate => DateTimeOffset.FromUnixTimeSeconds((long)this[ProfileFields.GovernanceEpochDate]).LocalDateTime;
public DateTime CompensationAsOfEpochDate => DateTimeOffset.FromUnixTimeSeconds((long)this[ProfileFields.CompensationAsOfEpochDate]).LocalDateTime;
public long MaxAge => this[ProfileFields.MaxAge];
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task<SecurityProfile> QueryProfileAsync(string symbol, Cance
await YahooSession.InitAsync(token);

var url = $"https://query2.finance.yahoo.com/v10/finance/quoteSummary/{symbol}"
.SetQueryParam("modules", "assetProfile")
.SetQueryParam("modules", "assetProfile,convert_dates")
.SetQueryParam("crumb", YahooSession.Crumb);

// Invalid symbols as part of a request are ignored by Yahoo.
Expand Down

0 comments on commit 8dbd0f7

Please sign in to comment.