I was informed that fetching orders is not possible after a reboot. So, I was wondering how can we handle orders being filled while the algorithm is offline? Say we needed to redeploy the algorithm and in that time period a couple of orders were filled. What happens now?
Thanks
Mia Alissi
In QuantConnect, orders fill asynchronously. When you send an order, it is sent to the API of your brokerage and the system waits for their response to update the state of your algorithm and portfolio. The timing of live order fills doesn't depend on the resolution of your security subscriptions. When your order fills, the fill price and fee is set by your brokerage. You can add event handlers to your algorithm to monitor the brokerage connection and brokerage messages.
If a split event occurs before your order is filled, the unfilled portion of the order is adjusted automatically, where its quantity is multiplied by the split factor and the limit/stop/trigger price (if any) is divided by the split factor.
In the case of a system reboot or redeployment, the state of your orders would be maintained by the brokerage. When your algorithm comes back online, it would receive updates about the status of your orders from the brokerage.
For example, the brokerage notifies LEAN when your order fills (
OrderStatus.Filled
), partially fills (OrderStatus.PartiallyFilled
) or is canceled (OrderStatus.Canceled
). The brokerage can cancel your order before it completely fills.You can monitor the fills of your order by saving a reference to the order ticket. For example, in Python:
For more information, you can refer to the QuantConnect Documentation.
Sources:
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.
Alexandre Catarino
Hi Gorkem ,
On deployment, the algorithm fetches the cashbook, open positions, and open orders. We need this information to create a portfolio representing your account. We don't need past order, so we don't fetch this information (assuming the Brokerage' API provide it). The open positions represent the orders that were filled while the algorithm was offline.
If you want that information, you can save the orders to the Object Store. We have an example for Insights:
Preserve Insights Between Deployments
Best regards,
AlexÂ
Gorkem
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!