Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Loop through all orders and print Symbol and number of shares for the order

Trying to do a little debugging and having trouble with the "Order", "Equity" object model.

initially I thought get_open_orders() would return a list or dictionary of open orders as the documentation says
get_open_orders(security)
If security is None or not specified, returns all open orders. If security is specified, returns open orders for that security

but when I use:
open_orders = get_open_orders()
for ORDER in open_orders
. . .

ORDER does not have any of the properties of an "Order" object. In the debugger ORDER is reported as an "Equity" object

and strangely, open_orders is reported in the debugger to be a dictionary of Equity objects. But when I drill into one of the "Equity" objects in the debugger the only propery that shows up is an "Order" object.

I'm SO confused.

Could someone show me a code snippet that iterates through all open orders and displays the Symbol name AND all of the other order information?

Thanks

Shawn

2 responses

You will want to do something like this.

 for equity, orders in get_open_orders().items():  
     for open_order in orders:  
         debug_str = "order created on {0} for {1} shares of {2}"  
         print  debug_str.format(open_order.created,  open_order. amount,  open_order.sid)

As you noted 'open_orders' is a dictionary keyed by security id. The dictionary contains a list of orders for each security, oldest first. Using a Python for-loop to loop through a dictionary only loops through the keys of the dictionary. The key is an equity object and NOT an order object. To loop through the items in the dictionary you need to use the '.items()' method.

However, that only gets you half the way there because the items in the dictionary are lists of orders and NOT single order objects. You now need to loop through each list of orders to get all the outstanding orders for that specific security.

You can print out any of the properties of the object (only three are printed above). Look at the documentation for available properties https://www.quantopian.com/help#api-orderobj .

You may want to look at this post for a similar related question.

Good luck

Thanks Dan!