-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from ooples/dev
Fixed issues with csv methods since Yahoo doesn't support them
- Loading branch information
Showing
19 changed files
with
393 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
| ||
|
||
internal class CapitalGainHelper : YahooCsvBase | ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
|
||
internal class CapitalGainHelper : YahooJsonBase | ||
{ | ||
/// <summary> | ||
/// Parses the raw csv data for the Capital Gain Data | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="csvData"></param> | ||
/// <returns>Returns a IEnumerable<CapitalGainHelper> using the given csvData</returns> | ||
internal override IEnumerable<T> ParseYahooCsvData<T>(IEnumerable<string[]> csvData) | ||
internal override IEnumerable<T> ParseYahooJsonData<T>(string jsonData) | ||
{ | ||
var parsedDataList = csvData.Select(csvRow => | ||
{ | ||
// Perform a try parse for all columns per row | ||
var dateSuccess = DateTime.TryParse(csvRow[0], CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate); | ||
var capitalGainSuccess = double.TryParse(csvRow[1], NumberStyles.Number | NumberStyles.AllowDecimalPoint | NumberStyles.Float, | ||
CultureInfo.InvariantCulture, out var parsedCapitalGain); | ||
var capitalGain = JsonConvert.DeserializeObject<CapitalGainDataRoot>(jsonData); | ||
|
||
// Add either the parsed value or the default if there was a parsing error | ||
CapitalGainData capitalGainData = new() | ||
{ | ||
Date = dateSuccess ? parsedDate : default, | ||
CapitalGain = capitalGainSuccess ? parsedCapitalGain : default | ||
}; | ||
if (capitalGain != null && capitalGain.Chart?.Result != null) | ||
{ | ||
var result = capitalGain.Chart.Result.Cast<T>(); | ||
|
||
return capitalGainData; | ||
}); | ||
return result; | ||
} | ||
|
||
return (IEnumerable<T>)parsedDataList; | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,19 @@ | ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
| ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
|
||
internal class DividendHelper : YahooCsvBase | ||
internal class DividendHelper : YahooJsonBase | ||
{ | ||
/// <summary> | ||
/// Parses the raw csv data for the Dividend Data | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="csvData"></param> | ||
/// <returns>Returns a IEnumerable<DividendData> using the given csvData</returns> | ||
internal override IEnumerable<T> ParseYahooCsvData<T>(IEnumerable<string[]> csvData) | ||
internal override IEnumerable<T> ParseYahooJsonData<T>(string jsonData) | ||
{ | ||
var parsedDataList = csvData.Select(csvRow => | ||
{ | ||
// Perform a try parse for all columns per row | ||
var dateSuccess = DateTime.TryParse(csvRow[0], CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate); | ||
var dividendSuccess = double.TryParse(csvRow[1], NumberStyles.AllowDecimalPoint | NumberStyles.Float | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedDividend); | ||
var dividendData = JsonConvert.DeserializeObject<DividendRoot>(jsonData); | ||
|
||
// Add either the parsed value or the default if there was a parsing error | ||
DividendData dividendData = new() | ||
{ | ||
Date = dateSuccess ? parsedDate : default, | ||
Dividend = dividendSuccess ? parsedDividend : default | ||
}; | ||
if (dividendData != null && dividendData.Chart?.Result != null) | ||
{ | ||
var results = dividendData.Chart.Result.Cast<T>(); | ||
|
||
return dividendData; | ||
}); | ||
return results; | ||
} | ||
|
||
return (IEnumerable<T>)parsedDataList; | ||
return []; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,25 @@ | ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
| ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
|
||
internal class HistoricalHelper : YahooCsvBase | ||
internal class HistoricalHelper : YahooJsonBase | ||
{ | ||
/// <summary> | ||
/// Parses the raw csv data for the Historical Data | ||
/// Parses the raw json data for the Financial Data | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="csvData"></param> | ||
/// <returns>Returns a IEnumerable<HistoricalData> using the given csvData</returns> | ||
internal override IEnumerable<T> ParseYahooCsvData<T>(IEnumerable<string[]> csvData) | ||
/// <param name="jsonData"></param> | ||
/// <returns></returns> | ||
internal override IEnumerable<T> ParseYahooJsonData<T>(string jsonData) | ||
{ | ||
var parsedDataList = csvData.Select(csvRow => | ||
{ | ||
// Perform a try parse for all columns per row | ||
var dateSuccess = DateTime.TryParse(csvRow[0], CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate); | ||
var openSuccess = double.TryParse(csvRow[1], NumberStyles.AllowDecimalPoint | NumberStyles.Float | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedOpen); | ||
var highSuccess = double.TryParse(csvRow[2], NumberStyles.AllowDecimalPoint | NumberStyles.Float | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedHigh); | ||
var lowSuccess = double.TryParse(csvRow[3], NumberStyles.AllowDecimalPoint | NumberStyles.Float | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedLow); | ||
var closeSuccess = double.TryParse(csvRow[4], NumberStyles.AllowDecimalPoint | NumberStyles.Float | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedClose); | ||
var adjCloseSuccess = double.TryParse(csvRow[5], NumberStyles.AllowDecimalPoint | NumberStyles.Float | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedAdjClose); | ||
var volumeSuccess = double.TryParse(csvRow[6], NumberStyles.Integer | NumberStyles.Number, | ||
CultureInfo.InvariantCulture, out var parsedVolume); | ||
var historicalData = JsonConvert.DeserializeObject<HistoricalDataRoot>(jsonData); | ||
|
||
// Add either the parsed value or the default if there was a parsing error | ||
HistoricalData historicalData = new() | ||
{ | ||
Date = dateSuccess ? parsedDate : default, | ||
Open = openSuccess ? parsedOpen : default, | ||
High = highSuccess ? parsedHigh : default, | ||
Low = lowSuccess ? parsedLow : default, | ||
Close = closeSuccess ? parsedClose : default, | ||
AdjClose = adjCloseSuccess ? parsedAdjClose : default, | ||
Volume = volumeSuccess ? parsedVolume : default | ||
}; | ||
if (historicalData != null && historicalData.Chart?.Result != null) | ||
{ | ||
var result = historicalData.Chart.Result.Cast<T>(); | ||
|
||
return historicalData; | ||
}); | ||
return result; | ||
} | ||
|
||
return (IEnumerable<T>)parsedDataList; | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
| ||
namespace OoplesFinance.YahooFinanceAPI.Helpers; | ||
|
||
internal class StockSplitHelper : YahooCsvBase | ||
internal class StockSplitHelper : YahooJsonBase | ||
{ | ||
/// <summary> | ||
/// Parses the raw csv data for the Stock Split Data | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="csvData"></param> | ||
/// <returns>Returns a IEnumerable<StockSplitData> using the given csvData</returns> | ||
internal override IEnumerable<T> ParseYahooCsvData<T>(IEnumerable<string[]> csvData) | ||
internal override IEnumerable<T> ParseYahooJsonData<T>(string jsonData) | ||
{ | ||
var parsedDataList = csvData.Select(csvRow => | ||
{ | ||
// Perform a try parse for all columns per row | ||
var dateSuccess = DateTime.TryParse(csvRow[0], CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate); | ||
var stockSplitData = JsonConvert.DeserializeObject<StockSplitRoot>(jsonData); | ||
|
||
// Add either the parsed value or the default if there was a parsing error | ||
StockSplitData stockSplitData = new() | ||
{ | ||
Date = dateSuccess ? parsedDate : default, | ||
StockSplit = csvRow.Length > 1 ? csvRow[1] : string.Empty | ||
}; | ||
if (stockSplitData != null && stockSplitData.Chart?.Result != null) | ||
{ | ||
var results = stockSplitData.Chart.Result.Cast<T>(); | ||
|
||
return stockSplitData; | ||
}); | ||
return results; | ||
} | ||
|
||
return (IEnumerable<T>)parsedDataList; | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
namespace OoplesFinance.YahooFinanceAPI.Models; | ||
|
||
[Serializable] | ||
public class CapitalGainData | ||
public class CapitalGainDataRoot | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public double CapitalGain { get; set; } | ||
} | ||
[JsonProperty("chart")] | ||
public Chart? Chart { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.