/// <summary> /// Returns the number of trading days needed to update a specifiy security /// </summary> /// <param name="ticker">string</param> /// <returns>int</returns> private static int DaysToUpdate(string symbol) { int daysToUpdate = TradingTime.GetNumTradingDays(GetLastTradingDay(symbol), DateTime.Now.Date); if (daysToUpdate == 0) { daysToUpdate = 1; } return(daysToUpdate); }
public static void RedoByYear() { int counter = 1; int routeId = 0; int numUpdated = 0; DateTime cutoffDate = new DateTime(2015, 1, 1); DateTime startDate = new DateTime(2017, 01, 01); DateTime endDate = new DateTime(2017, 12, 31); DateTime startTime = DateTime.Now; DateTime currentTime; TimeSpan elapsedTime; string duration = TradingTime.GetNumTradingDays(startDate, endDate).ToString() + " D"; int numberSecurities = IB.masterSecurityList.Contracts.Count(); Log.Info(3, string.Format("Start RedoByYear")); foreach (Security tempSecurity in IB.masterSecurityList.Contracts.ToList()) { #region Calculate Time Remaining currentTime = DateTime.Now; elapsedTime = currentTime - startTime; string elapsed = string.Format("E={0:D2}:{1:D2}:{2:D2}", elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds); TimeSpan timeLeft = (numberSecurities - counter) * (elapsedTime / counter); string Remaining = string.Format("Remaining={0:D2}:{1:D2}:{2:D2}", timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds); double percentCompleted = counter / numberSecurities; Log.Data(1, string.Format("{0,-10} {1,-10} ActiveReq={2,2} OpenReq={2,2} " + elapsed + " " + Remaining, tempSecurity.Symbol, tempSecurity.ConId, Program.myIB.myRequests.NumActiveRequests, Program.myIB.myRequests.NumOpenRequests)); counter++; #endregion Calculate Time Remaining BarDataList myBDL = new BarDataList(); myBDL = DataRequests.GetAllBars(tempSecurity.Symbol); int numBadEditDates = myBDL.getNumBadEditDates(startDate, endDate, cutoffDate); if (numBadEditDates > 14) { numUpdated++; Program.myIB.RequestBarIB(routeId, tempSecurity.ConId, tempSecurity.Symbol, endDate.ToString("yyyyMMdd hh:MM:ss"), duration); Log.Info(3, string.Format("RedoByYear Requesting Symbol= {0,-10} Bad Edits={1,-5}", tempSecurity.Symbol, numBadEditDates)); Thread.Sleep(Program.myIB.myRequests.DelayTime); } else { Log.Info(3, string.Format("RedoByYear Skipping Symbol={0,-10} Bad Edits={1,-5}", tempSecurity.Symbol, numBadEditDates)); } } Log.Info(3, string.Format("End RedoByYear - Updated={0} Total={1}", numUpdated, numberSecurities)); }
public static void Main(string[] args) { // Third Branch myIB = new IB(); //myIB.myScanner.ScanOn(); string previousDay = TradingTime.PreviousTradingDay(DateTime.Now).ToString("yyyy-MM-dd"); string currentDay = DateTime.Now.ToString("yyyy-MM-dd"); while (TradingTime.IsPreOpening) { TradingTime.Display(); MSQL.DailyUpdate(); DataRequests.GetMostActive(previousDay, 150).Reverse().DisplayScreen(); Console.WriteLine("MaxActiveRequests= {0} MaxOpenRequests= {1} OldestRequest= {2}", myIB.myRequests.MaxActiveRequests, myIB.myRequests.MaxOpenRequests, myIB.myRequests.OldestRequest); } while (TradingTime.IsMarketOpen) { TradingTime.Display(); MSQL.DailyUpdate(); DataRequests.GetMostActive(currentDay, 150).Reverse().DisplayScreen(); Console.WriteLine("MaxActiveRequests= {0} MaxOpenRequests= {1} OldestRequest= {2}", myIB.myRequests.MaxActiveRequests, myIB.myRequests.MaxOpenRequests, myIB.myRequests.OldestRequest); } while (TradingTime.IsAfterClose) { TradingTime.Display(); MSQL.RedoByEditdate(); MSQL.CheckAllTradingDays(); MSQL.DeleteVolume(1200); MSQL.DailyUpdate(); DataRequests.GetMostActive(currentDay, 150).Reverse().DisplayScreen(); Console.WriteLine("MaxActiveRequests= {0} MaxOpenRequests= {1} OldestRequest= {2}", myIB.myRequests.MaxActiveRequests, myIB.myRequests.MaxOpenRequests, myIB.myRequests.OldestRequest); } myIB.ShutDown(); }