Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
To get Executed price.

Hello,
I just want to know how can I get the executed price of an executed order? I got the order object shown below in return to get_order(oid) And I am unable to find the executed price in the list.

({'status': 1, 'limit_reached': False, 'created': Timestamp('2011-08-09 00:00:00+0000', tz='UTC'), 'stop': None, 'reason': None, 'stop_reached': False, 'commission': 270.0, 'amount': 9000, 'limit': None, 'sid': Security(8554, symbol='SPY', security_name='SPDR S&P 500 ETF TRUST', exchange='NYSE ARCA EXCHANGE', start_date=Timestamp('1993-01-29 00:00:00+0000', tz='UTC'), end_date=Timestamp('2015-05-04 00:00:00+0000', tz='UTC'), first_traded=None), 'id': '5b96dd265a62438eb2d00e48b282b4f7', 'dt': Timestamp('2011-08-10 00:00:00+0000', tz='UTC'), 'filled': 9000})
  • How and where can i get executed price? Or can I calculate the
    executed price using any of the values in the list?
  • Is there a method to get information about only executed orders?
  • is there any reference to understand this order object?

Thanks

3 responses

Hi Suraj,

You can access the cost basis (the volume-weighted average price per share) of a position with the cost_basis attribute of the context.portfolio.positions object.

For example:
context.portfolio.positions[sid(24)].cost_basis

Check out Gus's example algo for more details on how to work with the different components of an order: https://www.quantopian.com/posts/fill-price-of-market-orders

Andrew

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 Andrew,

I am using cost_basis however it just shows 0.0. Is there another way to get execution price or is this platform error?

Barry,

You can't get the cost_basis until the order executes, which will be on another call to handle_data.
Note I've upped your cash to $50million to show the effect of filling.

2014-04-07 PRINT 09:31:00: Ordered QQQ. 1 minute volume: 1909726  
2014-04-07 PRINT 09:32:00: QQQ filled 177268/583192, cost_basis=86.4366829587, stock price=85.87  
2014-04 07 PRINT 09:33:00: QQQ filled 259000/583192, cost_basis=86.4493839133, stock price=85.91  
2014-04-07 PRINT 09:34:00: QQQ filled 355354/583192, cost_basis=86.4786825712, stock price=85.99  
2014-04-07 PRINT 09:35:00: QQQ filled 491310/583192, cost_basis=86.5116132367, stock price=86.03  
2014-04-07 PRINT 09:36:00: QQQ filled 583192/583192, cost_basis=86.5053261367, stock price=85.91  
2014-04-11 PRINT 09:31:00: Ordered QQQ. 1 minute volume: 1184647  
2014-04-11 PRINT 09:32:00: QQQ filled 181358/583620, cost_basis=85.0782470873, stock price=84.52  
2014-04-11 PRINT 09:33:00: QQQ filled 371839/583620, cost_basis=85.0782485794, stock price=84.52  
2014-04-11 PRINT 09:34:00: QQQ filled 507409/583620, cost_basis=85.0432983557, stock price=84.39  
2014-04-11 PRINT 09:35:00: QQQ filled 583620/583620, cost_basis=84.9663182444, stock price=84.28