- In new NT8, when firing order, using SubmitOrderUnmanaged(...),
- then this method first invokes 3-4 times Strategy#OnOrderUpdate(...) method, before returning.
- In old NT7, submitting unmanaged order first returned, and after that, invoked OnOrderUpdate(...) method multiple times.
What is the problem:
I need to store the reference to Order first (before processing it), to be able to properly process it later and execute custom trading logic.
But I found, I cannot do this = I cannot store the reference to Order first (before this Order is processed), because SubmitOrderUnmanaged(...) does not return the Order immediately. It first calls Strategy#OnOrderUpdate(...) method multiple times and then (after some processing) returns the Order finally. So the Order is already processed multiple times, before I can store it. And this is the core of the problem.
(I get this is order of method invocations, when debugging historical backtest in VS)
I would expect, that SubmitOrderUnmanaged(...) should return the Order immediately (so I can store the reference to the Order, before its state changes) and the callbacks Strategy#OnOrderUpdate(...) should be invoked after returning the reference to Order.
Now, it is not clear, how I can store the reference (and custom contextual data about the order), before the processing of the order = before invocations of the Strategy#OnOrderUpdate(...) method.
I found in the docs, that it is good to store the reference in the OnOrderUpdate().
But this method is shared for all orders. I can't catch the order in this method, because I have lost the context, where I submitted the Order.
Example:
I can submit 2 orders: Each one will sell 1 contract at the same price. Plan is, that each contract will be managed differently from trader's point of view. (let's say, 1st contract is planned to be managed aggressively, 2nd conservatively).
So I need to store the reference for each one of these orders, to distinguish them and then handle them differently.
In point, when I am submitting each one of these 2 orders, I know which Order is which, so I can store the reference correctly into my variables.
But when you say to me: Wait until OnOrderUpdate(...) method is invoked to store your reference to your Order, then it is too late, because in this OnOrderUpdate(..) method all the context I need to distinguish between the orders is lost.
So how it is supposed to work please?
How can I store my orders into my variables first - before they are processed in OnOrderUpdate(..) method?
Comment