I am attempting to create my own class to create and manage BracketOrder (One-cancels-all) - would love to share it with you when I get it working.
So far, I have just come to the point of creating a stop market order and a profit order when placing the initial trade. I am having a problem with it, however, because the ticket for the initial (parent) order is not created and stored in my self.bracketOrders dictionary before the OnOrderEvent is called for the first time - I am assuming that is because order placements are asynchronous. It makes for a big problem because I can't fetch the correct BracketOrder object in OnOrderEvent. I am also placing a stop market order and a profit stop limit order in the BracketOrder object itself, and I will surely get the same problem there.
Please see the backtest - the log displays the following length of the bracketOrder dictionary (notice it has a length of 0 the first time around:
Length: 0 Length: 1 Length: 2 Length: 3 Length: 4
I tried creating the BracketOrder object in OnOrderEvent, but I don't think it's possible to fetch the order ticket from an OrderEvent. Also don't think it would work because OnOrderEvent may fire on the stop order created inside the BracketOrder object BEFORE the ticket for the stop order is stored in the self.bracketOrders dictionary.
The only solution I can think of is making the order placement and insert into dictionary synchronous, so OnOrderEvent can't fire until the BracketOrder object is created and stored in the dictionary. Is that possible? Other solutions would be appreciated as well.
Louis Szeto
Hi Haakon
When the StopLimitOrder is submitted, it will immediate illicit an OrderEvent with the status of Submitted, which happened before the next line
So, it is not in the dictionary. Given that you want to add other orders after the parentOrder is submitted, you could add a condition check in OnOrderEvent method:
Best
Louis
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.
Haakon
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!