I use the following code to track if my order is filled and it returns that 0 shares is filled.
if order_a_data is not None:
log.info('SPY order {amount} has {filled} shares filled'.format(amount=order_a_data.amount,filled=order_a_data.filled))
else:
log.info('SPY order is empty')
if order_b_data is not None:
log.info('Bull order {amount} has {filled} shares filled'.format(amount=order_b_data.amount,filled=order_b_data.filled))
else:
log.info('Bull order is empty')
if order_c_data is not None:
log.info('Bear order {amount} has {filled} shares filled'.format(amount=order_c_data.amount,filled=order_c_data.filled))
else:
log.info('Bear order is empty')
2009-08-03 14:15 allocate:58 INFO SPY order -1 has 0 shares filled
2009-08-03 14:15 allocate:62 INFO Bull order 1 has 0 shares filled
2009-08-03 14:15 allocate:66 INFO Bear order -3 has 0 shares filled
However, when I print portfolio.cash, portfolio.long_exposure and portfolio.short_exposure the next day, I find that they are calculated based on the order amount that I put.
log.info('Current portfolio cash:{cash}'.format(cash=context.portfolio.cash))
log.info('Current portfolio value:{value}'.format(value=context.portfolio.portfolio_value))
log.info('Capital used:{capital}'.format(capital=context.portfolio.capital_used))
context.long_exposure=context.portfolio.positions[context.shy].amount*data.current(context.shy,'price')
context.bull_exposure=context.portfolio.positions[context.bull].amount*data.current(context.bull,'price')
context.bear_exposure=context.portfolio.positions[context.bear].amount*data.current(context.bear,'price')
log.info('Current long exposure:{long_exposure}'.format(long_exposure=context.long_exposure))
log.info('Current short bull exposure:{bull_exposure}'.format(bull_exposure=context.bull_exposure))
log.info('Current short bear exposure:{bear_exposure}'.format(bear_exposure=context.bear_exposure))
2009-08-03 14:15 allocate:70 INFO Current portfolio cash:11545.878
2009-08-03 14:15 allocate:71 INFO Current portfolio value:11787.068
2009-08-03 14:15 allocate:72 INFO Capital used:1545.878
2009-08-03 14:15 allocate:77 INFO Current long exposure:10133.33
2009-08-03 14:15 allocate:78 INFO Current short bull exposure:-3441.93
2009-08-03 14:15 allocate:79 INFO Current short bear exposure:-6450.21
I'm wondering if my order is not filled at all, how come I have the correct portfolio.long_exposure and portfolio.short_exposure number.
Does anyone know how the order is handled and how the portfolio related variables are calculated?
Thanks.