Hello,
I have an algo where I hold a security up to n days from the time of opening its position.
I want to have a robust way of rebuilding this state in case the algo crashes and reboots.
Currently I get the filled tickets for the symbols in my portfolio:
invested = [str(k) for k, v in self.Securities.items() if v.Invested]
tickets = [ticket for ticket in self.Transactions.GetOrderTickets() if ticket.Status == OrderStatus.Filled and ticket.Symbol.Value in invested]
Then I can access ticket.Time. But I have one problem.
My algo also updates the ticket daily to create a trailing stop. This will also update ticket.Time.
What I want is a way to get the creation time of the ticket, not last updated time. Is there a way?
Shile Wen
Hi Ed,
I'd suggest creating a dict of times keyed by OrderTickets so that the OrderTickets can still be accessed by list(tickets.keys()), while the original times will stay in the values, and update this dict in OnOrderEvent. I've attached an example in the attached backtest. Furthermore, to handle algorithm crashes, I'd suggest storing information to ObjectStore so that information can be saved. This notebook and this algorithm example also provides good examples of using ObjectStore.
Best,
Shile Wen
Ed West
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!