Back to Community
Question about get_order()

Firstly - this is an amazing community and project. I look forward to being heavily involved. Big congrats to all those that have made Quantopian what it is today.

I need to get the status of my orders, I know that I need to call get_order( orderId ), but I couldn't find the API to know how to access the returned order object. Is there a state field to know if the order has been cancelled, partially filled, pending or filled ? I've gone through most of the docs, and know this is a new feature so it doesn't surprise me there isn't documentation yet.

I'm also assuming that when I call order( sid, 100), that that returns the orderId.

Are there plans to also include a get_filled_orders, or get_all_orders ?

5 responses

The backend Zipline is open source so we can simply look at the code to discover parts of the system that are not in the API documentation.

        order = Order(**{  
            'dt': self.current_dt,  
            'sid': sid,  
            'amount': amount,  
            'filled': 0,  
            'stop': stop_price,  
            'limit': limit_price,  
            'id': order_id  

Thank you for the quick reply.
I've now downloaded zipline's source.

Exciting times ahead

Need a bit more help...

I have the following:

orderId = order(sid(5061), 100)
orderObj = get_order( orderId ) orderObj.filled )

The strategy builds fine, but I get the following Runtime exception:

Runtime exception: AttributeError: 'NoneType' object has no attribute 'filled'

Sorry if I'm missing something obvious here, Python is not my strongest language (obviously :) )


Do a check on the order object before accessing the fields.

orderId = order(sid(5061), 100)  
orderObj = get_order( orderId )  
if orderObj is not None: orderObj.filled )  

I am not well versed in Python either so I don't know why it throws an error. We can also do orderObj ) which will print a string representation of all the fields within the object. Doing this without the if statement does not throw an error and the object does not appear to be None type. Trying to access the fields without doing a None check does throw an error though.

I've attached a backtest sample which makes an order that gets filled over multiple days and tracks the order status in the debug log.

Clone Algorithm
Total Returns
Max Drawdown
Benchmark Returns
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
import as blotter

def initialize(context): = sid(5601)
    context.order_id = None
def handle_data(context, data):
    current_amount = context.portfolio.positions[].amount
    if current_amount == 0 and in data:
        # Send an order
        size = 2 * data[].volume    # Place a very large order which will fill over multiple days
        order_id = order(, size)
        context.order_id = order_id
        # Log the opening order
        current_order = get_order(order_id)
        if current_order is not None:            
            log.debug("Sent order on {0} - Order amount: {1}, Status: {2}".format(
    # Check the status of the order
    if context.order_id != None:
        current_order = get_order(context.order_id)
        if current_order is None:
        elif current_order.status == blotter.ORDER_STATUS.OPEN:
            log.debug("Open order on {0} - Order amount: {1}, Fill amount: {2}".format(
        elif current_order.status == blotter.ORDER_STATUS.FILLED:    
            log.debug("Filled Order on {0} - Order amount: {1}, Fill amount: {2}".format(
            if current_order.amount == current_order.filled:
                context.order_id = None
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

Mike, check out the various order commands here: We do have a get_open_orders() command.

For the other question - you can't see the properties for something that doesn't exist yet, so Brent's code is good protection.

We don't have a "get all orders." Is there something in particular you're after? The results of that command could be ginormous! I'd like to find some other way to find what you're after.


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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.