I create a market order via account.CreateOrder() and account.Submit(order). I also create a tp and sl order via account.CreateOrder(), but then I wait for the market order to become filled before calling account.Submit(tpOrder, slOrder).
Once the tp and sl order are created and before they are submitted they end up in the Initialized state. If for some reason these order do not get placed, when I try to close my position I end up getting an error "Close operation failed". I am attempting to close my position by calling account.Flatten(Instrument) followed by account.CancelAllOrders(Instrument) when this error occurs.
With a live account a second call to my close method to call account.Flatten(Instrument) followed by account.CancelAllOrders(Instrument) then succeeds, but leaves the cancel pending orders on the UI with no way to delete them...
With a SIM account I am not able to close out the open market position and the cancel pending order also clutter the UI. I have to reset the account to get back to a good state.
How can I correctly close/delete an order that is in the Initializing state?
Comment