In order to optmize speed and reliability and avoid code issues, I need to confirm that following below is the real consequitive way when order state changes:
OnOrderUpdate ---> OnExecution -----> OnPositionUpdate ?
My objective is pretty simple: detecting when an order state changes in the fastest and reliable way possible. For that I must code in a synchronous-events logic way and that's the reason that I need where to look first.
Reading NT7 guide I left a little confused, cause it seems there're some contradictory conclusions. Let's see:
In the IOrder section:
• CRITICAL: If you want to drive your strategy logic based on order fills you must use OnExecution() instead of OnOrderUpdate(). OnExecution() is always triggered after OnOrderUpdate(). There is internal strategy logic that is triggered after OnOrderUpdate() is called but before OnExecution() that can adversely affect your strategy if you are relying on tracking fills within OnOrderUpdate().
but later it states:
If you are relying on the OnOrderUpdate() method to trigger actions such as the submission of a stop loss order when your entry order is filled ALWAYS reference the properties on the IOrder object passed into the OnOrderUpdate() method.
then for more confusion, in the section OnExecution you find this very same statement:
If you are relying on the OnExecution() method to trigger actions such as the submission of a stop loss order when your entry order is filled ALWAYS reference the properties on the IOrder object property attached to the IExecution object passed into the OnExecution() method. So, which is it for real the more reliable ?
Another point, In the example given in the guide, we have:
As an example, the NinjaTrader core may have received "Working" and then "PartFilled" order state change events back from the broker API on thread "B" and at some point in time (milliseconds later) the NinjaTrader core will take these events and trigger the OnOrderUpdate() method in the strategy on thread "A". Thus, when the strategy receives the first "Working" state for an order, the IOrder object passed in will reflect the "Working" state although the actual order is really in a state of "Part Filled" which is truly reflected in the original IOrder object returned in any of the order methods such as EnterLong(). Of course, the OnOrderUpdate() method will subsequently receive the event for "PartFilled" state.
In that example, is it not the OnOrderUpdate ALWAYS the first method to detect the new order state ?
So, which way is more reliable, checking first always in OnExecution() or OrderUpdate() method ?
I understand the asynchronous way of IB-API and I agree that there's a queue of state changes that need to be processed by NT into those methods, until all of them are not processed, it's impossible to know what is the "real latest Order State"; however I'd like to know which method will ALWAYS AND FIRST detect the latest genuine state ?
Looking forward to clear these doubts, Thanks a lot in advance
Comment