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

Hello everyone,

How can I get the average filled price of a market order? in the Doc order type has the attribute limit only?

Cheers,
Lucas

1 response

Lucas,
You can get the cost basis for each position via context.portfolio.positions[stock].cost_basis, that will be a weighted average of the price paid per share in that position. If you would like to access individual orders to check out what they filled at you can store the orders you place in a list and use get_order() to access the details. You will be able to access the different properties that way.

# This is what each order looks like

Event({'status': 1, 'created': datetime.datetime(2011, 1, 11, 0, 0, tzinfo=), 'limit_reached': False, 'stop': None, 'stop_reached': False, 'commission': 0.87, 'amount': 29, 'limit': None, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 8, 7, 0, 0, tzinfo=), first_traded=None), 'dt': datetime.datetime(2011, 1, 12, 0, 0, tzinfo=), 'id': '9484a4570c3a4fc6bdedd85f5a9661e9', 'filled': 29})  

Check out this example, hopefully it will get you pointed in the right direction.

David