Here's how I think OnPositionUpdate is supposed to work:
A. The Quantity parameter of PositionEventArgs is supposed to be the quantity of shares in the position after the latest OnExecutionUpdate.
B. When a share quantity of an instrument goes from 0 to X, Operation is set to Add.
C. When a share quantity of an instrument goes from X to Y, where neither X nor Y are 0, Operation is set to Update.
D. When a share quantity of an instrument goes from X to 0, Operation is set to Remove.
E. Since OnPositionUpdate is not guaranteed to happen after OnExecutionUpdate, you might get a non-zero position even if the position has been closed out by a forthcoming OnExecutionUpdate.
Question 1: Is everything I've said above correct? Am I missing anything?
I ask b/c when using Simulated Data against AMD, my Removes all have a Quantity of 0, which is as I would expect; you get a Remove when the position is closed out. Every time, so far.
On live on TDA against NVAX, Remove looks like it contains the number of shares that were removed to close out the trade. I.e. instead of Remove always being accompanied by a Quantity of 0, it is accompanied by the Quantity of shares sold (say 10) to close out the position. Every time, so far.
My main theory explaining the difference is that different vendors implement the Quantity value of OnPositionUpdate differently. Like, maybe TDA is treating the Quantity parameter as a delta, while NT8 treats it as a level. That would be annoying, but not terrible if it is the same for all tickers when I'm connected to TDA.
Question 2: Can you clarify here? Do vendors vary in how they implement the meaning or values of the OnPositionUpdate parameters (Quantity in particular)? Or am I seeing a timing artifact, as suggested in item E, above? (Timing seems unlikely though, given that behavior has been uniformly consistent so far.)
Question 3: Can you open an enhancement request to add these clarifications to the NT8 OnPositionUpdate doc, so everyone can benefit from this discussion without a lot of searching through the forums? The current doc for OnPositionUpdate in both the Add On and Strategy sections does not explicitly state any of this and uses language to describe Quantity that could be interpreted in different ways, thus requiring people to infer and confirm through experimentation how this stuff works.
(For instance, Strategy/OnPositionUpdate says Quantity is "An int value representing the updating quantity of a position" implying a delta, whereas Add On/Account/PositionUpdate implies in a comment "Output the new position" that the Quantity is the final updated value.)
Thanks in advance for your help! Cheers.
Comment