Hi;
Lets say a call is made to my OnData and my code is executing in there and it's taking a bit of time (no it shouldn't, but it does in this case).
Can OnOrder fire and so I am then processing my code in there at the same time?
Or are messages queued and so OnData must return before OnOrder is called.
And if it's multi-threaded, does QC have semaphores or something similar to avoid race conditions?
thanks - dave
Varad Kabade
Hi David Thielen,
QuantConnect/Lean is multi-thread. When we place an order, the algorithm will continue until the response comes back from the brokerage. However, in backtesting, the market orders are filled immediately, so it feels like the OnData has stopped and waited for the response.
Best,
Varad Kabade
David Thielen
Hi Varad;
I think I wasn't clear in my question. I understand that order placements are by definition asynchronous. And that your app in full is multi-threaded.
My core question is, if in my OnData method it is taking 90 seconds to proocess, and the period is 60 seconds, will OnData be called again? Or will the first OnData have to complete before the second is called?
For example, if in my OnData processing I decide I want to own 100 shares of MSFT, do I need to worry I could end up with 200 shares as the first OnData has not purchased yet, but it has decided to purchase. And then the 2nd OnData purchases, completes, then the first purchases and completes.
Fred Painchaud
Hi David,
Varad can still provide an answer of course.
I was verifying something else myself but no, OnData is not called asynchronously and in fact, is most of the time not reentrant, being written by people who would, most of the time, not make sure of that.
Fred
David Thielen
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!