Headlines

This commit is contained in:
2024-04-08 13:45:42 -04:00
parent a1114661f3
commit 4b8d38ab48

View File

@@ -1659,6 +1659,13 @@ namespace MarketData.Helper
//***************************************************************** H E A D L I N E S - S E E K I N G A L P H A ***********************************************************
// ***************************************************************************************************************************************************************************
public static Headlines GetCompanyHeadlinesSeekingAlpha(String symbol)
{
Headlines headlines = GetCompanyHeadlinesSeekingAlphaV1(symbol);
if(null==headlines || 0==headlines.Count)headlines= GetCompanyHeadlinesSeekingAlphaV2(symbol);
return headlines;
}
private static Headlines GetCompanyHeadlinesSeekingAlphaV1(String symbol)
{
HttpNetResponse httpNetResponse=null;
Headlines headlines=new Headlines();
@@ -1709,6 +1716,63 @@ namespace MarketData.Helper
}
}
private static Headlines GetCompanyHeadlinesSeekingAlphaV2(String symbol)
{
HttpNetResponse httpNetResponse=null;
Headlines headlines=new Headlines();
try
{
StringBuilder sb = new StringBuilder();
String strRequest;
symbol = symbol.ToUpper();
DateTime marketDate=PremarketDA.GetLatestMarketDate();
if(Utility.IsEpoch(marketDate))marketDate=DateTime.Now;
sb.Append("https://seekingalpha.com/symbol/").Append(symbol).Append("/news?from=");
sb.Append(marketDate.Year).Append("-").Append(Utility.Pad(marketDate.Month.ToString(),'0',2)).Append("-").Append(Utility.Pad(marketDate.Day.ToString(),'0',2));
sb.Append("T04%3A00%3A00.000Z&to=");
sb.Append(marketDate.Year).Append("-").Append(Utility.Pad(marketDate.Month.ToString(),'0',2)).Append("-").Append(Utility.Pad(marketDate.Day.ToString(),'0',2));
sb.Append("T14%3A20%3A34.999Z");
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG, strRequest);
WebProxy webProxy=HttpNetRequest.GetProxy("GetCompanyHeadlinesSeekingAlpha");
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV5B(strRequest,30000,webProxy,true,null);
if(!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
return null;
}
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
List<KeyValue> keyValuePairs = MarketDataHelper.LocateJSONKeyValuePairs(httpNetResponse.ResponseString, "\"publishOn\"", "\"title\"");
if(null==keyValuePairs)return null;
foreach (KeyValue keyValue in keyValuePairs)
{
Headline headline=null;
if (keyValue.Value.StartsWith("Video")) headline = new Headline(symbol, Utility.ParseDate(keyValue.Key.Substring(0, keyValue.Key.IndexOf('T'))),Uri.UnescapeDataString(keyValue.Value));
else headline = new Headline(symbol, Utility.ParseDate(keyValue.Key.Substring(0, keyValue.Key.IndexOf('T'))), keyValue.Value);
headline.Entry=headline.Entry.Replace("\\"," ");
headline.Entry=headline.Entry.Trim();
headline.Entry=Uri.UnescapeDataString(headline.Entry);
headline.Source = "Seeking Alpha";
headlines.Add(headline);
}
return headlines;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception);
return null;
}
finally
{
if(null!=httpNetResponse)httpNetResponse.Dispose();
}
}
// ***************************************************************************************************************************************************************************
//***************************************************************** H E A D L I N E S - M A R K E T W A T C H *************************************************************
// ***************************************************************************************************************************************************************************
@@ -2924,15 +2988,11 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Morningstar Mapping:'{0}'=>'{1}'",symbol,securityId));
try{Thread.Sleep(250);}finally{;}
sb=new StringBuilder();
sb.Append("https://api-global.morningstar.com/sal-service/v1/stock/newfinancials/").Append(securityId).Append("/cashFlow/detail?dataType=A&reportType=A&locale=en&languageId=en&locale=en&clientId=MDC&component=sal-components-equity-financials-details&version=3.74.0");
strRequest=sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG,strRequest);
httpNetResponse = HttpNetRequest.GetRequestNoEncodingMStar(strRequest,webProxy);
// Fetch the equity financial details. Success often requires several attempts.
httpNetResponse=GetMStarEquityFinancialDetails(securityId);
if(!httpNetResponse.Success || String.IsNullOrEmpty(httpNetResponse.ResponseString))
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request failed : {0}",strRequest));
return null;
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Failed to retrieve MorningStar EquityFinancialDetails."));
}
Dictionary<String,MStarDataSet> dataSetsCashflowStatement=GetData(httpNetResponse.ResponseString);
httpNetResponse.Dispose();
@@ -2948,6 +3008,38 @@ namespace MarketData.Helper
return null;
}
}
private static HttpNetResponse GetMStarEquityFinancialDetails(String securityId)
{
HttpNetResponse httpNetResponse = new HttpNetResponse();
int maxRetries=10;
int retry=0;
int waitBetweenAttemptsMS=500;
StringBuilder sb=new StringBuilder();
sb.Append("https://api-global.morningstar.com/sal-service/v1/stock/newfinancials/").Append(securityId).Append("/cashFlow/detail?dataType=A&reportType=A&locale=en&languageId=en&locale=en&clientId=MDC&component=sal-components-equity-financials-details&version=3.74.0");
String strRequest=sb.ToString();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,strRequest);
WebProxy webProxy=HttpNetRequest.GetProxy("GetCashflowStatement");
while(retry<maxRetries && false==httpNetResponse.Success)
{
httpNetResponse = HttpNetRequest.GetRequestNoEncodingMStar(strRequest,webProxy);
if(httpNetResponse.Success && !String.IsNullOrEmpty(httpNetResponse.ResponseString))return httpNetResponse;
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetMStarEquityFinancialDetails Attempt {0} of {1}",retry+1,maxRetries));
try{Thread.Sleep(waitBetweenAttemptsMS);}catch(Exception){;}
retry++;
}
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request failed : {0}",strRequest));
return httpNetResponse;
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception running request: {0}, Exception:{1}",strRequest,exception.ToString()));
return httpNetResponse;
}
}
private static List<CashflowStatement> CreateCashflowStatements(String symbol,Dictionary<String,MStarDataSet> cashflowDataElements)
{