When my live algo starts up, these messages appear in the log:
20230912 17:25:36.194 TRACE:: Debug: BrokerageSetupHandler.Setup(): Open order detected. Creating order tickets for open order EURNZD with quantity -112. Beware that this order ticket may not accurately reflect the quantity of the order if the open order is partially filled.
20230912 17:25:36.325 TRACE:: Debug: BrokerageSetupHandler.Setup(): Open order detected. Creating order tickets for open order EURNZD with quantity -338. Beware that this order ticket may not accurately reflect the quantity of the order if the open order is partially filled.
20230912 17:25:36.326 TRACE:: Debug: BrokerageSetupHandler.Setup(): Open order detected. Creating order tickets for open order EURGBP with quantity -53. Beware that this order ticket may not accurately reflect the quantity of the order if the open order is partially filled.
20230912 17:25:36.326 TRACE:: Debug: BrokerageSetupHandler.Setup(): Open order detected. Creating order tickets for open order EURGBP with quantity -160. Beware that this order ticket may not accurately reflect the quantity of the order if the open order is partially filled.
But this code returns an empty list:
open_orders = self.Transactions.GetOpenOrders()
I have tried several variations of that - GetOrders(), passing symbol as a parameter - but it always comes back empty.
What am I doing wrong?
Mia Alissi
The
GetOpenOrders()
method should return a list of all open orders. If it's returning an empty list, it might be due to the timing of when you're calling this method.If you're calling
GetOpenOrders()
immediately after placing an order, it's possible that the order hasn't been processed yet, hence it's not appearing in the list of open orders.You can also try using the
GetOrderTickets()
orGetOpenOrderTickets()
methods to fetch the order tickets, which might give you more information about the state of your orders. Here's how you can do it:If you want to get the order tickets for a specific symbol, you can pass the symbol as a parameter:
If you want to filter the order tickets, you can pass a filter function:
If none of these methods work, it might be a good idea to check if there's an issue with the brokerage connection or if there's a delay in order processing.
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.
Lee Allen
I found the problem while researching your suggestion: apparently I can't GetOpenOrder() in the Initialize function. I moved it to OnData and now it works. Thank you.
Follow-up question? I am having difficulty finding things in the documentation. For instance where would I find the reference for GetOpenOrders() ?
Thank you!
Mia Alissi
I'm glad to hear that your issue with
GetOpenOrders()
has been resolved!As for your question about finding things in the documentation, the
GetOpenOrders()
method is part of theSecurityTransactionManager
class, which is accessed through theTransactions
property of your algorithm.You can find the reference for
GetOpenOrders()
in the Transaction Manager section of the QuantConnect documentation.In this section, you'll find information about the
GetOpenOrders()
method, as well as other methods for managing orders, such asGetOrderById()
,GetOrderTickets()
, andGetOpenOrderTickets()
.Here's an example of how to use
GetOpenOrders()
:And here's how to use
GetOrderById()
:I hope this helps! Let me know if you have any other questions.
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.
Lee Allen
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!