Is this for every element of a strategy position?
A strategy position has a market position: long, short or flat. I'm not questioning these changes.
But a strategy position also has average price and quantity.
So for example, assume the strategy position is long 10 contracts.
Strategy then calls EnterShort(10)
Managed order system submits order "Close position" to sell 10 contracts ( to get to flat )
Managed order system submits order "Sell" to sell 10 contracts ( to honor the request to be short 10 ).
Execution of 1 sell takes place making the market position long 9 contracts.
Is OnPositionUpdate called at this point?
The MarketPosition is still long but the averagePrice and quantity are different, right? Is OnPositionUpdate called with these new values at this point?
The problem I'm trying to solve...
I have a strategy that is caching execution objects passed in on OnExecutionUpdate. I have 4 execution objects for the entries:
executionLE1, executionSE1, executionLE2, executionSE2.
I have logic that uses these execution objects to make decisions. Sometimes a particular trade is only using executionLE1 or SE1 ( no 2nd entry submitted ). In this case the executionLE2 and executionSE2 would be pointing to executions that were part of a previous trade.
I'm looking for a place/event in the strategy that I can reset these execution objects to null.
I thought that if the strategy is Flat that it means the trade is over. BUT that might not be the case. The strategy might be transitioning from long to short as part of a reversal and pass through FLAT on its way.
How can I solve this? Is the only way to do it is in the logic that's deciding that it wants to become long, short or flat? But if the code performs the nulling at that point in time it is occurring before the orders actually execute. There's some chance that not all of the orders will fill and so nulling the execution objects this early would not be a good idea. That is why I'm looking to the callbacks OnPostionUpdate and/or OnExecutionUpdate to handle this.
Do you have an example that properly caches execution objects for only the current trade?
Comment