Hi I am scheduling the orders 1 minute after market open
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SPY", 1), self.Rebalance)
and it shows this error
[ERROR] FATAL UNHANDLED EXCEPTION:Engine.Run(): Error running algorithm System.ArgumentException: Unable to locate next market open within two weeks., at QuantConnect.Securities.SecurityExchangeHours.GetNextMarketOpen(DateTime localDateTime, Boolean extendedMarketHours) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Common/Securities/SecurityExchangeHours.cs:line 320, at QuantConnect.Scheduling.TimeRules.<>c__DisplayClass14_0.b__1(DateTime date) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Common/Scheduling/TimeRules.cs:line 172, at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext(), at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext(), at QuantConnect.Scheduling.ScheduledEvent.get_NextEventUtcTime() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Common/Scheduling/ScheduledEvent.cs:line 80, at QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler.<>c.b__11_0(KeyValuePair`2 x) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/RealTime/BacktestingRealTimeHandler.cs:line 158, at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count), at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count), at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count), at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext(), at System.Linq.Enumerable.SelectIPartitionIterator`2.ToList(), at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source), at QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler.GetScheduledEventsSortedByTime() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/RealTime/BacktestingRealTimeHandler.cs:line 156, at QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler.Setup(IAlgorithm algorithm, AlgorithmNodePacket job, IResultHandler resultHandler, IApi api, IIsolatorLimitResultProvider isolatorLimitProvider) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/RealTime/BacktestingRealTimeHandler.cs:line 52, at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Engine/Engine.cs:line 295
How should I place orders after market open
Mia Alissi
The error message you're seeing is indicating that the system is unable to locate the next market open within two weeks. This could be due to a variety of reasons, such as a problem with the data or a misconfiguration in your algorithm.
The code you've provided for scheduling an event 1 minute after the market opens for "SPY" seems correct:
This code should schedule the
self.Rebalance
method to run 1 minute after the market opens for "SPY" every day.However, the error might be occurring within the
self.Rebalance
method. Without seeing the rest of your code, it's difficult to pinpoint the exact issue. I would recommend checking theself.Rebalance
method and ensuring that it's correctly implemented.If you're still having trouble, you might find it helpful to post a more complete code snippet or reach out to the QuantConnect community for further assistance. They have a forum where you can ask questions and get help from other QuantConnect users and staff.
Source: QuantConnect Forum
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jayakumar Munuswamy
for reference to other folks running into this in the future.. I just ran into this, and looks like its happening becasue the algorithim does not access to the symbol to calculate the close or open time. just need to add the following line and that fixes it.
Tushar Verma
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!