diff --git a/MarketData/MarketData/Services/MainService.cs b/MarketData/MarketData/Services/MainService.cs index 6cb2622..c1d8cfe 100755 --- a/MarketData/MarketData/Services/MainService.cs +++ b/MarketData/MarketData/Services/MainService.cs @@ -33,6 +33,7 @@ namespace MarketData.Services tasks.Add("UPDATELATESTANALYSTRATINGS",TaskUpdateLatestAnalystRatings); tasks.Add("UPDATEANALYSTRATINGS",TaskUpdateAnalystRatings); tasks.Add("UPDATESECFILINGSWATCHLIST",TaskUpdateSECFilingsWatchList); + tasks.Add("UPDATECOMPANYPROFILES",TaskUpdateCompanyProfiles); tasks.Add("ECHO",TaskEcho); GlobalConfig.Instance.Configuration = configuration; // This call sets up configuration stuff so it needs to be first. @@ -85,8 +86,15 @@ namespace MarketData.Services MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Done, total took {profiler.End()}(ms)"); } +// ********************************************************************************************************************************************************** +// ********************************************************* T A S K S ************************************************************************************* +// ********************************************************************************************************************************************************** + public async Task TaskUpdateCompanyProfiles(CommandArgs commandArgs) + { + UpdateCompanyProfiles(); + await Task.FromResult(true); + } -// ********************************************************************************************************************************************************************************* public async Task TaskUpdateSECFilingsWatchList(CommandArgs commandArgs) { if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("UPDATESECFILINGSWATCHLIST REQUIRES WATCHLIST");return;} @@ -157,6 +165,10 @@ namespace MarketData.Services await Task.FromResult(true); } +// ********************************************************************************************************************************************************* +// ********************************************************************************************************************************************************* +// ********************************************************************************************************************************************************* + private static bool CreateLogging(String task) { if(String.IsNullOrEmpty(task))return false; @@ -192,6 +204,7 @@ namespace MarketData.Services MDTrace.WriteLine(LogLevel.DEBUG,"UPDATELATESTPRICEWATCHLIST /WATCHLIST:"); MDTrace.WriteLine(LogLevel.DEBUG,"UPDATELATESTPRICEOPENPOSITIONS"); MDTrace.WriteLine(LogLevel.DEBUG,"UPDATESECFILINGSWATCHLIST /WATCHLIST:"); + MDTrace.WriteLine(LogLevel.DEBUG,"UPDATECOMPANYPROFILES"); } // ********************************************************************************************************************************************** diff --git a/MarketData/MarketDataLib/DataAccess/CompanyProfileDA.cs b/MarketData/MarketDataLib/DataAccess/CompanyProfileDA.cs index 56a8fe2..d502cce 100755 --- a/MarketData/MarketDataLib/DataAccess/CompanyProfileDA.cs +++ b/MarketData/MarketDataLib/DataAccess/CompanyProfileDA.cs @@ -68,6 +68,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static CompanyProfiles GetCompanyProfiles() { CompanyProfiles companyProfiles=new CompanyProfiles(); @@ -113,6 +114,7 @@ namespace MarketData.DataAccess if (null != sqlConnection) sqlConnection.Close(); } } + public static CompanyProfile GetCompanyProfile(String symbol) { MySqlConnection sqlConnection = null; @@ -186,6 +188,7 @@ namespace MarketData.DataAccess if(null!=sqlDataReader){sqlDataReader.Close();sqlDataReader.Dispose();} } } + private static bool InsertCompanyProfileDescription(CompanyProfile companyProfile,MySqlConnection sqlConnection,MySqlTransaction sqlTransaction) { MySqlCommand sqlCommand=null; @@ -215,6 +218,7 @@ namespace MarketData.DataAccess if(null!=sqlCommand)sqlCommand.Dispose(); } } + private static bool UpdateCompanyProfileDescription(CompanyProfile companyProfile,MySqlConnection sqlConnection,MySqlTransaction sqlTransaction) { MySqlCommand sqlCommand=null; diff --git a/MarketData/MarketDataLib/Helper/BollingerBandHelperSheet.cs b/MarketData/MarketDataLib/Helper/BollingerBandHelperSheet.cs deleted file mode 100755 index f341c81..0000000 --- a/MarketData/MarketDataLib/Helper/BollingerBandHelperSheet.cs +++ /dev/null @@ -1,144 +0,0 @@ -// using System; -// using System.IO; -// using Microsoft.Office.Interop.Excel; -// using MarketData.DataAccess; -// using MarketData.MarketDataModel; -// using MarketData.Generator; -// using MarketData.Utils; - -// namespace MarketData.Helper -// { -// public class BollingerBandSheetHelper -// { -// public BollingerBandSheetHelper() -// { -// } -// public static bool GenerateBollingerBandSheet(String strPathTemplateFile,String symbol,int movingAverageDays,int historicalDays) -// { -// Microsoft.Office.Interop.Excel.Application excelApp = null; -// Microsoft.Office.Interop.Excel.Workbook workbook = null; -// Microsoft.Office.Interop.Excel.Worksheet worksheet = null; -// Microsoft.Office.Interop.Excel.Sheets worksheets = null; -// int rowOffset = 1; -// try -// { -// String currentWorkingDirectory = Directory.GetCurrentDirectory(); -// if (!File.Exists(strPathTemplateFile)) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,"Cannot locate "+strPathTemplateFile); -// return false; -// } -// DateGenerator dateGenerator = new DateGenerator(); -// DateTime startDate = dateGenerator.GetPrevBusinessDay(DateTime.Now); -// Prices prices = PricingDA.GetPrices(symbol,startDate,historicalDays); -// if (null == prices || 0 == prices.Count) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,"No prices for "+symbol); -// return false; -// } -// Price price = prices[0]; -// String pathOutputFile = currentWorkingDirectory + "\\" + symbol + "-BB-" + Utility.DateTimeToStringMMHDDHYYYY(price.Date); -// MDTrace.WriteLine(LogLevel.DEBUG,"Generating "+pathOutputFile); -// String companyName = PricingDA.GetNameForSymbol(symbol); -// File.Delete(pathOutputFile+".xlsx"); -// excelApp = new Microsoft.Office.Interop.Excel.Application(); -// excelApp.ScreenUpdating=false; -// workbook = excelApp.Workbooks.Open(strPathTemplateFile, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); -// worksheets = workbook.Worksheets; -// worksheet = (Microsoft.Office.Interop.Excel.Worksheet)worksheets.get_Item("Sheet1"); -// Microsoft.Office.Interop.Excel.ChartObjects chartObjects = worksheet.ChartObjects(); -// Microsoft.Office.Interop.Excel.ChartObject chartObject = chartObjects.Item(1); -// chartObject.Chart.ChartTitle.Text = companyName + " (" + symbol + ") "+Utility.DateTimeToStringMMHDDHYYYY(prices[prices.Count-1].Date)+" Thru "+Utility.DateTimeToStringMMHDDHYYYY(price.Date); -// BollingerBands bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices, movingAverageDays); -// Axis vertAxis = (Axis)chartObject.Chart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary); -// vertAxis.MaximumScaleIsAuto = false; -// vertAxis.MaximumScale = GetMaxData(bollingerBands); -// vertAxis.MinimumScaleIsAuto = false; -// vertAxis.MinimumScale = GetMinData(bollingerBands); -// vertAxis.HasMajorGridlines = true; -// Axis horzAxis = (Axis)chartObject.Chart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary); -// horzAxis.HasMajorGridlines = true; -// for (int index = 0; index < bollingerBands.Count; index++) -// { -// BollingerBandElement bollingerBandElement = bollingerBands[index]; -// worksheet.Cells[index + 1 + rowOffset, 1] = bollingerBandElement.Date; -// worksheet.Cells[index + 1 + rowOffset, 2] = bollingerBandElement.Symbol; -// worksheet.Cells[index + 1 + rowOffset, 3] = bollingerBandElement.Open; -// worksheet.Cells[index + 1 + rowOffset, 4] = bollingerBandElement.High; -// worksheet.Cells[index + 1 + rowOffset, 5] = bollingerBandElement.Low; -// worksheet.Cells[index + 1 + rowOffset, 6] = bollingerBandElement.Close; -// worksheet.Cells[index + 1 + rowOffset, 7] = bollingerBandElement.Volume; -// worksheet.Cells[index + 1 + rowOffset, 8] = bollingerBandElement.SMAN; -// worksheet.Cells[index + 1 + rowOffset, 9] = bollingerBandElement.StDevN; -// worksheet.Cells[index + 1 + rowOffset, 10] = bollingerBandElement.K; -// worksheet.Cells[index + 1 + rowOffset, 11] = bollingerBandElement.L; -// worksheet.Cells[index + 1 + rowOffset, 12] = bollingerBandElement.KL1; -// worksheet.Cells[index + 1 + rowOffset, 13] = bollingerBandElement.LP1; -// } -// workbook.SaveAs(pathOutputFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution, true, Type.Missing, Type.Missing, Type.Missing); -// return true; -// } -// catch (Exception exception) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); -// return false; -// } -// finally -// { -// if (null != worksheet) ReleaseObject(worksheet); -// if (null != worksheets) ReleaseObject(worksheets); -// if (null != workbook) ReleaseObject(workbook); -// excelApp.Quit(); -// } -// } -// private static double GetMinData(BollingerBands bollingerBands) -// { -// double minData = double.MaxValue; -// for (int index = 0; index < bollingerBands.Count; index++) -// { -// BollingerBandElement bollingerBandElement = bollingerBands[index]; -// if(bollingerBandElement.Open maxData) maxData = bollingerBandElement.Open; -// if (bollingerBandElement.High > maxData) maxData = bollingerBandElement.High; -// if (bollingerBandElement.Low > maxData) maxData = bollingerBandElement.Low; -// if (bollingerBandElement.K > maxData) maxData = bollingerBandElement.K; -// if (bollingerBandElement.L > maxData) maxData = bollingerBandElement.L; -// if (bollingerBandElement.KL1 > maxData) maxData = bollingerBandElement.KL1; -// if (bollingerBandElement.LP1 > maxData) maxData = bollingerBandElement.LP1; -// } -// return maxData+(maxData*.05); -// } -// private static void ReleaseObject(object obj) -// { -// try -// { -// System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); -// obj = null; -// } -// catch (Exception ex) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,ex.ToString()); -// obj = null; -// } -// finally -// { -// GC.Collect(); -// } -// } -// } -// } \ No newline at end of file diff --git a/MarketData/MarketDataLib/Helper/CompanyProfileMarketDataHelper.cs b/MarketData/MarketDataLib/Helper/CompanyProfileMarketDataHelper.cs index 6e07cb3..4a48c02 100755 --- a/MarketData/MarketDataLib/Helper/CompanyProfileMarketDataHelper.cs +++ b/MarketData/MarketDataLib/Helper/CompanyProfileMarketDataHelper.cs @@ -1,6 +1,4 @@ -using System; -using System.Threading; -using MarketData.MarketDataModel; +using MarketData.MarketDataModel; using MarketData.DataAccess; using MarketData.Utils; @@ -19,111 +17,106 @@ namespace MarketData.Helper ResetEvent=resetEvent; } } - public class CompanyProfileMarketDataHelper + + public class CompanyProfileMarketDataHelper : MarketDataHelperBase { private static int MaxThreads = (int)ThreadHelperEnum.MaxThreads; - private CompanyProfiles companyProfiles; - private int currentIndex = 0; + private static int SLEEP_TIME_MS = 500; public CompanyProfileMarketDataHelper() { } - public bool UpdateCompanyProfile(String symbol) - { - Profiler profiler=new Profiler(); - try - { - companyProfiles=new CompanyProfiles(); - CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol); - if(null==companyProfile)return false; - companyProfiles.Add(companyProfile); - currentIndex = 0; - while (true) - { - CompanyProfiles queueProfiles = GetQueueProfiles(); - if (null == queueProfiles || 0 == queueProfiles.Count) break; - ManualResetEvent[] resetEvents = new ManualResetEvent[queueProfiles.Count]; - for (int eventIndex = 0; eventIndex < resetEvents.Length; eventIndex++) - { - resetEvents[eventIndex] = new ManualResetEvent(false); - } - for (int index = 0; index < queueProfiles.Count; index++) - { - CompanyProfileThreadHelper companyProfileThreadHelper = new CompanyProfileThreadHelper(queueProfiles[index],resetEvents[index]); - ThreadPool.QueueUserWorkItem(ThreadPoolCallback, companyProfileThreadHelper); - } - MDTrace.WriteLine(LogLevel.DEBUG,"Load company profile, waiting for queued items to complete."); - WaitHandle.WaitAll(resetEvents); - } - return true; - } - finally - { - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfiles]End, total took {0}(ms)",profiler.End())); - } - } + public bool UpdateCompanyProfiles() + { + return UpdateCompanyProfile(); + } + + public bool UpdateCompanyProfile(String symbol=null) { - Profiler profiler=new Profiler(); - try - { - companyProfiles=CompanyProfileDA.GetCompanyProfiles(); - currentIndex = 0; - while (true) - { - CompanyProfiles queueProfiles = GetQueueProfiles(); - if (null == queueProfiles || 0 == queueProfiles.Count) break; - ManualResetEvent[] resetEvents = new ManualResetEvent[queueProfiles.Count]; - for (int eventIndex = 0; eventIndex < resetEvents.Length; eventIndex++) - { - resetEvents[eventIndex] = new ManualResetEvent(false); - } - for (int index = 0; index < queueProfiles.Count; index++) - { - CompanyProfileThreadHelper companyProfileThreadHelper = new CompanyProfileThreadHelper(queueProfiles[index],resetEvents[index]); - ThreadPool.QueueUserWorkItem(ThreadPoolCallback, companyProfileThreadHelper); - } - MDTrace.WriteLine(LogLevel.DEBUG,"Load company profile, waiting for queued items to complete."); - WaitHandle.WaitAll(resetEvents); - } - return true; - } - finally - { - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfiles]End, total took {0}(ms)",profiler.End())); - } - } - private CompanyProfiles GetQueueProfiles() - { - CompanyProfiles queueProfiles = new CompanyProfiles(); - int index = currentIndex; - for (; index < currentIndex + MaxThreads && index < companyProfiles.Count; index++) + Profiler profiler=new Profiler(); + try { - queueProfiles.Add(companyProfiles[index]); + if(null==symbol) + { + Queue=CompanyProfileDA.GetCompanyProfiles(); + } + else + { + CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol); + if(null==companyProfile)return false; + Queue = new CompanyProfile[]{companyProfile}.ToList(); + } + Index=-1; + ManualResetEvent[] resetEvents = new ManualResetEvent[MaxThreads]; + for (int eventIndex = 0; eventIndex < resetEvents.Length; eventIndex++)resetEvents[eventIndex] = new ManualResetEvent(true); + MDTrace.WriteLine(String.Format("[UpdateCompanyProfile] Queuing company profile fetches ...")); + DateTime modified=DateTime.Now; + while (true) + { + ManualResetEvent[] availableEvents=GetAvailableEvents(resetEvents); + ManualResetEvent[] busyEvents=GetBusyEvents(resetEvents); + if (null == PeekQueueItem() && 0==busyEvents.Length) + { + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfile] queue contains {0} items, busy events {1}, all done.",0,busyEvents.Length)); + break; + } + for (int index = 0; index < availableEvents.Length; index++) + { + CompanyProfile queueItem=GetQueueItem(); + if (null != queueItem) + { + availableEvents[index].Reset(); + CompanyProfileThreadHelper companyProfileThreadHelper = new CompanyProfileThreadHelper(queueItem,resetEvents[index]); + ThreadPool.QueueUserWorkItem(ThreadPoolCallback, companyProfileThreadHelper); + try { Thread.Sleep(SLEEP_TIME_MS); }catch (Exception) { ;} + } + else + { + busyEvents=GetBusyEvents(resetEvents); + if(busyEvents.Length!=availableEvents.Length) + { + ManualResetEvent[] resizedEvents=new ManualResetEvent[busyEvents.Length]; + Array.Copy(busyEvents, resizedEvents,busyEvents.Length); + resetEvents = resizedEvents; + } + break; + } + } // for + MDTrace.WriteLine(LogLevel.DEBUG,"[UpdateCompanyProfile] waiting for free slots..."); + if(resetEvents.Length>0)WaitHandle.WaitAny(resetEvents); + if(null==PeekQueueItem())resetEvents=ResizeEvents(resetEvents); + } // while + MDTrace.WriteLine(LogLevel.DEBUG,"[UpdateCompanyProfile] completed."); + return true; } - currentIndex = index; - return queueProfiles; - } + finally + { + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfile] End, total took {0}(ms)",profiler.End())); + } + } + public void ThreadPoolCallback(Object companyProfileThreadHelperContext) { CompanyProfileThreadHelper companyProfileThreadHelper = (CompanyProfileThreadHelper)companyProfileThreadHelperContext; - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load profile, Thread {0} started for {1}...", Thread.CurrentThread.ManagedThreadId, companyProfileThreadHelper.CompanyProfile.Symbol)); + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfile] Thread {0} started for {1}...", Thread.CurrentThread.ManagedThreadId, companyProfileThreadHelper.CompanyProfile.Symbol)); LoadCompanyProfileEx(companyProfileThreadHelper.CompanyProfile); - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load profile, Thread {0} ended for {1}", Thread.CurrentThread.ManagedThreadId, companyProfileThreadHelper.CompanyProfile.Symbol)); + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfile] Thread {0} ended for {1}", Thread.CurrentThread.ManagedThreadId, companyProfileThreadHelper.CompanyProfile.Symbol)); companyProfileThreadHelper.ResetEvent.Set(); } + private static void LoadCompanyProfileEx(CompanyProfile companyProfile) { CompanyProfile marketCompanyProfile = MarketDataHelper.GetCompanyProfile(companyProfile.Symbol); if (null == marketCompanyProfile) { - MDTrace.WriteLine(LogLevel.DEBUG,"No company profile for symbol '" + companyProfile.Symbol + "'"); + MDTrace.WriteLine(LogLevel.DEBUG,"[[UpdateCompanyProfile]] No company profile for symbol '" + companyProfile.Symbol + "'"); return; } if(!String.IsNullOrEmpty(marketCompanyProfile.Sector) && !marketCompanyProfile.Sector.Equals("N/A"))companyProfile.Sector=marketCompanyProfile.Sector; if(!String.IsNullOrEmpty(marketCompanyProfile.Industry) && !marketCompanyProfile.Industry.Equals("N/A"))companyProfile.Industry=marketCompanyProfile.Industry; if(!String.IsNullOrEmpty(marketCompanyProfile.Description) && !marketCompanyProfile.Description.Equals("N/A"))companyProfile.Description=marketCompanyProfile.Description; - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("LoadCompanyProfileEx: Updating company profile.....Symbol:{0} Sector:{1} Industry:{2}",companyProfile.Symbol,companyProfile.Sector, companyProfile.Industry)); + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdateCompanyProfile] Updating company profile.....Symbol:{0} Sector:{1} Industry:{2}",companyProfile.Symbol,companyProfile.Sector, companyProfile.Industry)); CompanyProfileDA.UpdateCompanyProfile(companyProfile); } } diff --git a/MarketData/MarketDataLib/Helper/MarketDataHelper.cs b/MarketData/MarketDataLib/Helper/MarketDataHelper.cs index 59fecb4..9b7e8dd 100755 --- a/MarketData/MarketDataLib/Helper/MarketDataHelper.cs +++ b/MarketData/MarketDataLib/Helper/MarketDataHelper.cs @@ -1428,10 +1428,11 @@ namespace MarketData.Helper { String nasdaq = "xnas"; String nyse = "xnys"; + CompanyProfile companyProfile = null; - companyProfile = GetCompanyProfileYahoo(symbol); - if (null==companyProfile)companyProfile=GetCompanyProfileMorningStar(symbol,nasdaq); - if (null == companyProfile) companyProfile = GetCompanyProfileMorningStar(symbol, nyse); + companyProfile = GetCompanyProfileMorningStar(symbol,nasdaq); + if (null == companyProfile)companyProfile = GetCompanyProfileMorningStar(symbol, nyse); + if (null == companyProfile)companyProfile = GetCompanyProfileYahoo(symbol); return companyProfile; } @@ -1511,11 +1512,19 @@ namespace MarketData.Helper } } + /// + /// Retrieve company profile information from MorningStar + /// + /// The Symbol + /// XNAS or XNYS + /// public static CompanyProfile GetCompanyProfileMorningStar(String symbol,String exchange) { HttpNetResponse httpNetResponse=null; try { + if(null==exchange)return default; + exchange=exchange.ToLower(); StringBuilder sb = new StringBuilder(); String strRequest; symbol = symbol.ToUpper(); @@ -1523,7 +1532,7 @@ namespace MarketData.Helper sb.Append(String.Format("https://www.morningstar.com/stocks/{0}/{1}/quote",exchange,symbol)); strRequest = sb.ToString(); MDTrace.WriteLine(LogLevel.DEBUG,strRequest); - httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5A(strRequest, 10000, webProxy); + httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5A(strRequest, 15000, webProxy); if(!httpNetResponse.Success) { diff --git a/MarketData/MarketDataLib/Helper/MovingAverageHelperSheet.cs b/MarketData/MarketDataLib/Helper/MovingAverageHelperSheet.cs deleted file mode 100755 index fd8f2e9..0000000 --- a/MarketData/MarketDataLib/Helper/MovingAverageHelperSheet.cs +++ /dev/null @@ -1,133 +0,0 @@ -// using System; -// using System.IO; -// using System.Collections.Generic; -// using Microsoft.Office.Interop.Excel; -// using MarketData.DataAccess; -// using MarketData.MarketDataModel; -// using MarketData.Generator; -// using MarketData.Utils; -// using MarketData.Generator.MovingAverage; - -// namespace MarketData.Helper -// { -// public class MovingAverageHelperSheet -// { -// public MovingAverageHelperSheet() -// { -// } -// public static bool GenerateMovingAverageSheet(String strPathTemplateFile, String symbol) -// { -// Microsoft.Office.Interop.Excel.Application excelApp = null; -// Microsoft.Office.Interop.Excel.Workbook workbook = null; -// Microsoft.Office.Interop.Excel.Worksheet worksheet = null; -// Microsoft.Office.Interop.Excel.Sheets worksheets = null; -// int rowOffset = 1; -// try -// { -// String companyName = PricingDA.GetNameForSymbol(symbol); -// DateGenerator dateGenerator = new DateGenerator(); -// DateTime startDate = dateGenerator.GetPrevBusinessDay(DateTime.Now); -// String currentWorkingDirectory = Directory.GetCurrentDirectory(); -// if (!File.Exists(strPathTemplateFile)) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,"Cannot locate " + strPathTemplateFile); -// return false; -// } -// MovingAverages movingAverages = MovingAverageGenerator.GenerateMovingAverages(symbol); -// String pathOutputFile = currentWorkingDirectory + "\\" + symbol + "-MA-" + Utility.DateTimeToStringMMHDDHYYYY(movingAverages.ThruDate); -// MDTrace.WriteLine(LogLevel.DEBUG,"Generating " + pathOutputFile); -// File.Delete(pathOutputFile + ".xlsx"); -// excelApp = new Microsoft.Office.Interop.Excel.Application(); -// excelApp.ScreenUpdating = false; -// workbook = excelApp.Workbooks.Open(strPathTemplateFile, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); -// worksheets = workbook.Worksheets; -// worksheet = (Microsoft.Office.Interop.Excel.Worksheet)worksheets.get_Item("Sheet1"); -// Microsoft.Office.Interop.Excel.ChartObjects chartObjects = worksheet.ChartObjects(); -// Microsoft.Office.Interop.Excel.ChartObject movingAverageChartObject = chartObjects.Item(1); // yes, chart 1 is the fast line -// movingAverageChartObject.Chart.ChartTitle.Text = companyName + " (" + symbol + ") " + Utility.DateTimeToStringMMHDDHYYYY(movingAverages.FromDate) + " - " + Utility.DateTimeToStringMMHDDHYYYY(movingAverages.ThruDate) + " MA(55,21,5)"; -// Axis vertAxis = (Axis)movingAverageChartObject.Chart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary); -// vertAxis.MaximumScaleIsAuto = false; -// vertAxis.MaximumScale = GetMaxData(movingAverages); -// vertAxis.MinimumScaleIsAuto = false; -// vertAxis.MinimumScale = GetMinData(movingAverages); -// vertAxis.HasMajorGridlines = true; -// Axis horzAxis = (Axis)movingAverageChartObject.Chart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary); -// horzAxis.HasMajorGridlines = true; -// for (int index = 0; index < movingAverages.Count; index++) -// { -// MovingAverageElement movingAverageElement = movingAverages[index]; -// worksheet.Cells[index + 1 + rowOffset, 1] = movingAverageElement.Symbol; -// worksheet.Cells[index + 1 + rowOffset, 2] = movingAverageElement.Date; -// worksheet.Cells[index + 1 + rowOffset, 3] = movingAverageElement.Close; -// worksheet.Cells[index + 1 + rowOffset, 4] = movingAverageElement.High; -// worksheet.Cells[index + 1 + rowOffset, 5] = movingAverageElement.Low; -// worksheet.Cells[index + 1 + rowOffset, 6] = movingAverageElement.MA55; -// worksheet.Cells[index + 1 + rowOffset, 7] = movingAverageElement.MA21; -// worksheet.Cells[index + 1 + rowOffset, 8] = movingAverageElement.MA5; -// } -// workbook.SaveAs(pathOutputFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution, true, Type.Missing, Type.Missing, Type.Missing); -// return true; -// } -// catch (Exception exception) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); -// return false; -// } -// finally -// { -// if (null != worksheet) ReleaseObject(worksheet); -// if (null != worksheets) ReleaseObject(worksheets); -// if (null != workbook) ReleaseObject(workbook); -// excelApp.Quit(); -// } -// } -// private static double GetMinData(MovingAverages movingAverages) -// { -// double minData = double.MaxValue; -// for (int index = 0; index < movingAverages.Count; index++) -// { -// MovingAverageElement movingAverageElement = movingAverages[index]; -// if (movingAverageElement.Close < minData) minData = movingAverageElement.Close; -// if (movingAverageElement.High < minData) minData = movingAverageElement.High; -// if (movingAverageElement.Low < minData) minData = movingAverageElement.Low; -// if (movingAverageElement.MA55 < minData) minData = movingAverageElement.MA55; -// if (movingAverageElement.MA21 < minData) minData = movingAverageElement.MA21; -// if (movingAverageElement.MA5 < minData) minData = movingAverageElement.MA5; -// } -// return minData - (minData * .05); -// } -// private static double GetMaxData(MovingAverages movingAverages) -// { -// double maxData = 0; -// for (int index = 0; index < movingAverages.Count; index++) -// { -// MovingAverageElement movingAverageElement = movingAverages[index]; -// if (movingAverageElement.Close > maxData) maxData = movingAverageElement.Close; -// if (movingAverageElement.High > maxData) maxData = movingAverageElement.High; -// if (movingAverageElement.Low > maxData) maxData = movingAverageElement.Low; -// if (movingAverageElement.MA55 > maxData) maxData = movingAverageElement.MA55; -// if (movingAverageElement.MA21 > maxData) maxData = movingAverageElement.MA21; -// if (movingAverageElement.MA5 > maxData) maxData = movingAverageElement.MA5; -// } -// return maxData + (maxData * .05); -// } -// private static void ReleaseObject(object obj) -// { -// try -// { -// System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); -// obj = null; -// } -// catch (Exception ex) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,ex.ToString()); -// obj = null; -// } -// finally -// { -// GC.Collect(); -// } -// } -// } -// } - diff --git a/MarketData/MarketDataLib/Helper/StochasticsHelperSheet.cs b/MarketData/MarketDataLib/Helper/StochasticsHelperSheet.cs deleted file mode 100755 index c21bd17..0000000 --- a/MarketData/MarketDataLib/Helper/StochasticsHelperSheet.cs +++ /dev/null @@ -1,112 +0,0 @@ -// using System; -// using System.IO; -// using Microsoft.Office.Interop.Excel; -// using MarketData.DataAccess; -// using MarketData.MarketDataModel; -// using MarketData.Generator; -// using MarketData.Utils; - -// namespace MarketData.Helper -// { -// public class StochasticsSheetHelper -// { -// public StochasticsSheetHelper() -// { -// } -// public static bool GenerateStochasticsSheet(String strPathTemplateFile, String symbol, int dayCount,int periodN,int periodK) -// { -// Microsoft.Office.Interop.Excel.Application excelApp = null; -// Microsoft.Office.Interop.Excel.Workbook workbook = null; -// Microsoft.Office.Interop.Excel.Worksheet worksheet = null; -// Microsoft.Office.Interop.Excel.Sheets worksheets = null; -// int rowOffset = 1; -// try -// { -// String currentWorkingDirectory = Directory.GetCurrentDirectory(); -// if (!File.Exists(strPathTemplateFile)) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,"Cannot locate " + strPathTemplateFile); -// return false; -// } -// DateGenerator dateGenerator = new DateGenerator(); -// DateTime startDate = dateGenerator.GetPrevBusinessDay(DateTime.Now); -// Prices prices = PricingDA.GetPrices(symbol, startDate, dayCount); -// if (null == prices || 0 == prices.Count) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,"No prices for " + symbol); -// return false; -// } -// Price price = prices[0]; -// String pathOutputFile = currentWorkingDirectory + "\\" + symbol + "-ST-" + Utility.DateTimeToStringMMHDDHYYYY(price.Date); -// MDTrace.WriteLine(LogLevel.DEBUG,"Generating " + pathOutputFile); -// String companyName = PricingDA.GetNameForSymbol(symbol); -// File.Delete(pathOutputFile + ".xlsx"); -// excelApp = new Microsoft.Office.Interop.Excel.Application(); -// excelApp.ScreenUpdating = false; -// workbook = excelApp.Workbooks.Open(strPathTemplateFile, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); -// worksheets = workbook.Worksheets; -// worksheet = (Microsoft.Office.Interop.Excel.Worksheet)worksheets.get_Item("Sheet1"); -// Microsoft.Office.Interop.Excel.ChartObjects chartObjects = worksheet.ChartObjects(); -// Microsoft.Office.Interop.Excel.ChartObject chartObject = chartObjects.Item(1); -// chartObject.Chart.ChartTitle.Text = companyName + " (" + symbol + ") " + Utility.DateTimeToStringMMHDDHYYYY(prices[prices.Count - 1].Date) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(price.Date)+" N="+periodN+", K="+periodK; -// Stochastics stochastics = StochasticsGenerator.GenerateStochastics(prices, periodN, periodK); -// if (null == stochastics) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,"Error generating stochastics."); -// return false; -// } -// Axis vertAxis = (Axis)chartObject.Chart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary); -// vertAxis.HasMajorGridlines = true; -// Axis horzAxis = (Axis)chartObject.Chart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary); -// horzAxis.HasMajorGridlines = true; -// for (int index = 0; index < stochastics.Count; index++) -// { -// StochasticElement stochasticElement = stochastics[index]; -// worksheet.Cells[index + 1 + rowOffset, 1] = stochasticElement.Date; -// worksheet.Cells[index + 1 + rowOffset, 2] = stochasticElement.Symbol; -// worksheet.Cells[index + 1 + rowOffset, 3] = stochasticElement.Open; -// worksheet.Cells[index + 1 + rowOffset, 4] = stochasticElement.High; -// worksheet.Cells[index + 1 + rowOffset, 5] = stochasticElement.Low; -// worksheet.Cells[index + 1 + rowOffset, 6] = stochasticElement.Close; -// worksheet.Cells[index + 1 + rowOffset, 7] = stochasticElement.LN; -// worksheet.Cells[index + 1 + rowOffset, 8] = stochasticElement.HN; -// worksheet.Cells[index + 1 + rowOffset, 9] = stochasticElement.HX; -// worksheet.Cells[index + 1 + rowOffset, 10] = stochasticElement.LX; -// worksheet.Cells[index + 1 + rowOffset, 11] = stochasticElement.PK; -// worksheet.Cells[index + 1 + rowOffset, 12] = stochasticElement.PD; -// } -// workbook.SaveAs(pathOutputFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution, true, Type.Missing, Type.Missing, Type.Missing); -// return true; -// } -// catch (Exception exception) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); -// return false; -// } -// finally -// { -// if (null != worksheet) ReleaseObject(worksheet); -// if (null != worksheets) ReleaseObject(worksheets); -// if (null != workbook) ReleaseObject(workbook); -// excelApp.Quit(); -// } -// } -// private static void ReleaseObject(object obj) -// { -// try -// { -// System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); -// obj = null; -// } -// catch (Exception ex) -// { -// MDTrace.WriteLine(LogLevel.DEBUG,ex.ToString()); -// obj = null; -// } -// finally -// { -// GC.Collect(); -// } -// } -// } -// } \ No newline at end of file diff --git a/MarketData/MarketDataLib/Integration/HttpNetRequest.cs b/MarketData/MarketDataLib/Integration/HttpNetRequest.cs index a4082d1..fd2d618 100755 --- a/MarketData/MarketDataLib/Integration/HttpNetRequest.cs +++ b/MarketData/MarketDataLib/Integration/HttpNetRequest.cs @@ -1143,10 +1143,6 @@ namespace MarketData.Integration int charCount = 0; byte[] buffer = new byte[8192]; StringBuilder sb = new StringBuilder(); - // bool expect100Condition = ServicePointManager.Expect100Continue; - // SecurityProtocolType securityProtocolType = ServicePointManager.SecurityProtocol; - // ServicePointManager.Expect100Continue = true; - // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(strRequest)); if(null!=webProxy)webRequest.Proxy=webProxy; webRequest.Timeout = webRequestTimeoutMS; @@ -1177,8 +1173,6 @@ namespace MarketData.Integration if (0 == charCount) break; sb.Append(Encoding.ASCII.GetString(buffer, 0, charCount)); } - // ServicePointManager.Expect100Continue = expect100Condition; - // ServicePointManager.SecurityProtocol = securityProtocolType; return new HttpNetResponse(sb.ToString(), strRequest, webResponse, webResponse.Cookies, true); } catch (WebException webException)