Hello SH,
This script illustrates that the order is filled at the closing price of the next trading bar. This assumes that a custom slippage model is not applied (e.g. https://www.quantopian.com/posts/trade-at-the-open-slippage-model). With a custom model, you can shift the fulfillment price to the opening price of the next trading bar, for example.
Regarding real-time trading with Interactive Brokers (IB), I do not have hands-on experience, but Quantopian has reported that order fulfillment is asynchronous, so that as soon as an order is submitted via the algorithm, it will be sent to IB and filled immediately. Thus, it is typically well within a minute. If you are considering algorithms that rely on fussy pricing and timing at the minute or sub-minute level, I would recommend consulting with Quantopian to understand the details of their system.
Grant
def initialize(context):
context.spy = sid(8554)
set_slippage(slippage.FixedSlippage(spread=0.00))
set_commission(commission.PerTrade(cost=0.0))
context.cash_prior = context.portfolio.cash
def handle_data(context, data):
# order(context.spy,1)
print get_datetime()
print context.cash_prior - context.portfolio.cash
print data[context.spy].close_price
context.cash_prior = context.portfolio.cash
order(context.spy, 1)