In my case Oanda Brokerage Model (for CFD) returned Market On Open as Invalid, Is there a way to catch invalid orders so that I can cancel submitted stop loss and take profit orders.
Order = self.Transactions.GetOrderById(OrderEvent.OrderId)
# Cancel Stop loss and take profit pending orders if market order is invalid
if OrderEvent.Status == OrderStatus.Invalid:
if Order.Tag == "Long_Entry":
self.long_tp_order.Cancel()
self.long_sl_order.Cancel()
elif Order.Tag == "Short_Entry":
self.short_tp_order.Cancel()
self.short_sl_order.Cancel()
I am doing this but unable to catch it, I think the OrderStatus.Invalid string does not match with OrderEvent.Status,
Alexandre Catarino
Hi AbirJ ,
The best way to address the invalid order, in this case, is to avoid it since we know why it's happening: the algorithm is placing an order when the market is closed.
Please use:
to get whether the market is open and, if not, the algorithm should not place orders.
Best regards,
Alex
AbirJ
Thank you, Alex.
AbirJ
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!