public static void CheckAllTradingDays() { Log.Info(3, string.Format("Start CheckAllTradingDays")); foreach (Security tempSecurity in IB.masterSecurityList.Contracts.ToList()) { DataRequests.GetAllBars(tempSecurity.Symbol).CheckTradingDays(); } Log.Info(3, string.Format("End CheckAllTradingDays")); }
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 RedoByEditdate() { int counter = 1; int numUpdated = 0; int routeId = 0; DateTime startTime = DateTime.Now; DateTime currentTime; DateTime cutoffDate; TimeSpan elapsedTime; //foreach (Security tempSecurity in IB.masterSecurityList.Contracts.AsEnumerable().Reverse().ToList()) Log.Info(3, string.Format("Start RedoByEditdate")); int numberSecurities = IB.masterSecurityList.Contracts.Count(); foreach (Security tempSecurity in IB.masterSecurityList.Contracts.ToList()) { #region Calculate Time Remaining currentTime = DateTime.Now; elapsedTime = currentTime - startTime; string Elapsed = string.Format("Elapsed={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}:{3:D2}", timeLeft.Days, timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds); double percentCompleted = counter / numberSecurities; Log.Data(1, string.Format("Symbol={0,-10} ConId={1,-10} requests={2,2} " + Elapsed + " " + Remaining, tempSecurity.Symbol, tempSecurity.ConId, Program.myIB.myRequests.NumOpenRequests)); counter++; #endregion Calculate Time Remaining BarDataList myBDL = new BarDataList(); myBDL = DataRequests.GetAllBars(tempSecurity.Symbol); foreach (BarDataItem tempBar in myBDL.Items) { cutoffDate = tempBar.Time.AddDays(7); if (tempBar.EditTime < cutoffDate && DateTime.Now > cutoffDate) { Program.myIB.RequestBarIB(routeId, myBDL.ConId, tempBar.Time); numUpdated++; Thread.Sleep(Program.myIB.myRequests.DelayTime); } } } Log.Info(3, string.Format("End RedoByEditdate - {0} Updated", numUpdated)); }
private static void SaveData(string symbol) { string dataFileName = symbol + ".txt"; // Set a variable to the Documents path. string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // Set a variable to the Stocks path. myDocumentsPath = "D:\\OneDrive\\Stocks\\Deleted\\"; // Use full path to create a handle to the error file System.IO.StreamWriter dataFile = new StreamWriter(Path.Combine(myDocumentsPath, dataFileName), false); BarDataList mBarDataList = new BarDataList(); mBarDataList = DataRequests.GetAllBars(symbol); foreach (BarDataItem mItem in mBarDataList.Items) { dataFile.WriteLine(string.Format("{0:MM/dd/yyyy} {1:0.000} {2:0.000} {3:0.000} {4:0.000} {5,-8} {6:yyyyMMdd HH:mm:ss}", mItem.Time, mItem.Open, mItem.High, mItem.Low, mItem.Close, mItem.Volume, mItem.EditTime)); } dataFile.Close(); }