When I execute a strategy, sometimes the following error occurs:
Cancellation rejected by the Order Management System - Order is complete
The provider is Rithmic for APEX.
I have read the documentation and forums on this matter and have followed the guidelines. I have even placed code in the OnOrderUpdate event to capture the error, and this is what it receives:
ErrCode: UnableToCancelOrder native: Cancellation rejected by the Order Management System - Order is complete
I have gathered more data about the error, and in this case, the following happens:
1. When an entry is executed, additional limit orders are placed. For example, we enter long, and 2 Buy Limit orders are placed at 2 different prices below.
2. Each time a Long order is executed, a Target and a Stop are also placed.
3. When the first Long (named Long1) is executed, its corresponding Target1 and Stop1 are set.
4. The price drops a bit, and the second and third Long orders are executed. Now we have Long2 and Long3, with their corresponding Target2, Target3, Stop2, and Stop3.
5. After some time, the strategy decides to exit the trade. ExitLong is sent for Long1, Long2, and Long3, and OnOrderUpdate marks them as Submitted.
6. The price moves rapidly.
7. OnOrderUpdate marks Stop3 Filled, Stop2 Filled, Stop3 Filled...
8. After that, the ERROR occurs.
9. The strategy is disabled.
10. Now there are 3 SHORT positions without a Stop Loss or anything. I deduce that NT opened 3 positions in the opposite direction to what it was before the error.
The same happens if, for example, in point 4 mentioned earlier, only 2 Long orders are executed, and then the strategy sends the Exit, i.e., ExitLong, and cancels the Long3 order. However, as the price moves very fast, OnOrderUpdate marks it as Submitted but then marks Long3 Filled. And the error occurs.
I hope the explanation is clear.
Could you help me find a solution to this error?
I think what happens is that the Exit or Cancellation order is sent but not yet filled, and in the meantime, the Filled of the Stop order or Long3 order that has already been canceled is executed, causing the error.
Thank you.
Comment