From 761d90a8f5a185a6fc60c6ddea3ff4bb4554249d Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 12 Apr 2025 20:46:09 -0400 Subject: [PATCH] Fix ETF Holdings feed --- .../MarketDataLib/Helper/MarketDataHelper.cs | 31 ++++++++++++++++--- .../MarketDataLib/Utility/FeedParser.cs | 8 ----- MarketData/MarketDataLib/Utility/Sections.cs | 3 -- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/MarketData/MarketDataLib/Helper/MarketDataHelper.cs b/MarketData/MarketDataLib/Helper/MarketDataHelper.cs index b1ddb6e..c971d7d 100755 --- a/MarketData/MarketDataLib/Helper/MarketDataHelper.cs +++ b/MarketData/MarketDataLib/Helper/MarketDataHelper.cs @@ -1380,7 +1380,6 @@ namespace MarketData.Helper ETFHoldings etfHoldings = new ETFHoldings(); try { - WriteToDisk(responseString,$"{etfSymbol}_etfholdings.txt"); DateTime modified = DateTime.Now; int groupBy=3; List sections = Sections.GetAllItemsInSections(responseString,"section"); @@ -1408,15 +1407,37 @@ namespace MarketData.Helper ETFHolding etfHolding = new ETFHolding(); if(index+2>=spans.Count())continue; List subSectionsSymbol = Sections.GetSections(spans[index]); + List subSectionsCompanyName = Sections.GetSections(spans[index+1]); List subSectionsPercentOfAssets = Sections.GetSections(spans[index+2]); + etfHolding.ETFSymbol = etfSymbol; etfHolding.HoldingSymbolShareClass = null; - etfHolding.HoldingCompanyName = Utility.BetweenString(spans[index+1],">","<"); - if(null!=subSectionsSymbol && subSectionsSymbol.Count>0)etfHolding.HoldingSymbol = subSectionsSymbol.Where(x => !String.IsNullOrEmpty(x)).FirstOrDefault(); - if (null == etfHolding.HoldingSymbol || "N/A".Equals(etfHolding.HoldingSymbol) || "".Equals(etfHolding.HoldingSymbol)) continue; + + if(null!=subSectionsSymbol && subSectionsSymbol.Count>0) + { + etfHolding.HoldingSymbol = subSectionsSymbol.Where(x => !String.IsNullOrEmpty(x)).FirstOrDefault(); + } + + if (null == etfHolding.HoldingSymbol || "N/A".Equals(etfHolding.HoldingSymbol) || "".Equals(etfHolding.HoldingSymbol)) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"ETFHolding Symbol was not provided in the response for {etfSymbol}"); + break; // we always expect to have a symbol, otherewise something is wrong with the collection. + } + + if(null!=subSectionsCompanyName && subSectionsCompanyName.Count>0) + { + etfHolding.HoldingCompanyName = subSectionsCompanyName.Where(x => !String.IsNullOrEmpty(x)).FirstOrDefault(); + } + etfHolding.PercentOfAssets = FeedParser.ParseValue(subSectionsPercentOfAssets.Where(x => !String.IsNullOrEmpty(x)).FirstOrDefault()); + + if(double.IsNaN(etfHolding.PercentOfAssets)) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"ETFHolding Unable to parse PercentOfAssets for Symbol {etfSymbol}."); + } + etfHolding.Modified = modified; - if(FeedParser.IsNumeric(etfHolding.HoldingSymbol))continue; + etfHolding.HoldingSymbol=etfHolding.HoldingSymbol.Trim().ToUpper(); etfHoldings.Add(etfHolding); } } diff --git a/MarketData/MarketDataLib/Utility/FeedParser.cs b/MarketData/MarketDataLib/Utility/FeedParser.cs index e22fe62..7028e74 100755 --- a/MarketData/MarketDataLib/Utility/FeedParser.cs +++ b/MarketData/MarketDataLib/Utility/FeedParser.cs @@ -304,14 +304,6 @@ namespace MarketData.Utils } } - public static bool IsNumeric(String strText) - { - strText=strText.Replace("%", ""); - strText = strText.Replace("$", ""); - double value = 0.00; - return double.TryParse(strText, out value); - } - public static long ParseValueLong(String strText) { long value; diff --git a/MarketData/MarketDataLib/Utility/Sections.cs b/MarketData/MarketDataLib/Utility/Sections.cs index 2057e78..474dc7e 100755 --- a/MarketData/MarketDataLib/Utility/Sections.cs +++ b/MarketData/MarketDataLib/Utility/Sections.cs @@ -42,9 +42,6 @@ namespace MarketDataLib.Utility } return sectionItems; } - - - public static List GetSections(String strInput) { try