For all of us attempting to learn / understand both quantopian and python, I find the following to be helpful.
print len(context.portfolio.positions), context.portfolio.positions
PrintedResult=
4
printed blank line here
{
Equity(
49131,
symbol=u'OESX',
asset_name=u'ORION ENERGY SYSTEMS INC COM STK (WI)',
exchange=u'NASDAQ',
start_date=Timestamp('2015-06-12 00:00:00+0000', tz='UTC'),
end_date=Timestamp('2016-11-07 00:00:00+0000', tz='UTC'),
first_traded=None,
auto_close_date=Timestamp('2016-11-10 00:00:00+0000', tz='UTC'),
exchange_full=u'NASDAQ CAPITAL MARKET'
):Position({
'last_sale_date': Timestamp('2016-10-27 17:37:00+0000', tz='UTC'),
'amount': 351,
'last_sale_price': 1.22,
'cost_basis': 1.23,
'sid': Equity(
49131,
symbol=u'OESX',
asset_name=u'ORION ENERGY SYSTEMS INC COM STK (WI)',
exchange=u'NASDAQ',
start_date=Timestamp('2015-06-12 00:00:00+0000', tz='UTC'),
end_date=Timestamp('2016-11-07 00:00:00+0000', tz='UTC'),
first_traded=None,
auto_close_date=Timestamp('2016-11-10 00:00:00+0000', tz='UTC'),
exchange_full=u'NASDAQ CAPITAL MARKET'
)
}),
Equity(
48635,
...
):Position({
...
'sid': Equity(
48635,
...
)
}),
...
}
for stock in context.portfolio.positions:
print stock
PrintedResult=
2016-10-28 07:45 PRINT Equity(49131 [OESX])
2016-10-28 07:45 PRINT Equity(48635 [BLPH])
2016-10-28 07:45 PRINT Equity(49452 [MIRN])
2016-10-28 07:45 PRINT Equity(33103 [PFIE])