Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Quantopian Order Object Problem - no 'direction' attribute?

I'm new to Quantopian and am having problems with the syntax on how to get the most recent order direction. I am getting the error message...

c.order = order(symbol('AAPL'), shares)  
c.order_info = get_order(c.order)  

if c.order.direction > 0 :  
    LongPos = True  
elif c.order.direction < 0 :  
    ShortPos = True

**The debugger results are...

c.order
e2a0ee74234540f8bbef0e0970fbc185
c.order.direction
AttributeError: 'str' object has no attribute 'direction'**

According to the Quantopian API...

The order object has the following properties: amount (float), direction (1 for buy, -1 for sell), sid (int), stop and limit (float), and stop_reached and limit_reached (boolean).

So, what's the problem with the Quantopian order object, or what is the correct 'direction' syntax?

Thanks,

Mark

4 responses

Update, if I refer to the c.order_info object instead...

c.order = order(symbol('AAPL'), long_short * shares)  
c.order_info = get_order(c.order)  

if c.order_info.direction > 0 :  
    LongPos = True  
elif c.order_info.direction < 0 :  
    ShortPos = True

The debugger results are...

c,order_info.direction
'Order' object has no attribute 'direction'

The 'c,order_info.direction' debugger text was added after stepping through the 'if c.order_info.direction > 0 :' statement to help illustrate the debugger error...

Hi Mark,

I see what you mean. I'm attempting to recreate an algorithm with 'direction' in it and am running into the same error. Let me do some further explanation and can update this thread with some answers when I have them.

Thanks for your patience.

Disclaimer

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.

Hi Mark,

So what's actually happening is that this piece in the documentation:

The order object has the following properties: amount (float), direction (1 for buy, -1 for sell), sid (int), stop and limit (float), and stop_reached and limit_reached (boolean).

Only applies to the order object that's passed around in the SLIPPAGE model and is not the same as the order object that you obtain from get_order(order_id). The order object that's returned by 'get_order(order_id)' does not contain a 'direction' attribute. But you could replicate a similar functionality by doing something like

get_order(order_id).amount > 0 or get_order(order_id).amount <0

Sorry about the confusion, that piece in the documentation refers to the Slippage Model, not the general order object.

I'm here to answer any questions you have on this,

Thanks,
Seong