Hello Sheridan,
I've thought a bit about this problem in the context of Quantopian. If you want to buy a security when the market opens on Day 1, you have to submit an order when the market closes on Day 0. This means that in the last minute of Day 0, your order needs to be submitted. It will then be fulfilled in the first minute of Day 1. Alternatively, you could submit the order during the first minute of Day 1, and it will be fulfilled in the second minute of Day 1. The latter option is probably the easiest to implement (see paragraph below for an explanation). The above assumes that the security has entries in the Quantopian database for every minute the market is open (not generally true, since some securities are thinly traded).
Getting out of the market at close is kinda tricky. Your sell order has to be submitted in the minute prior to the closing minute, to be fulfilled in the closing minute. So, ahead of time, you need to know the datetime stamp of the closing minute. You can do a study (in Quantopian) to determine the datetime stamps of all of the closing minutes for your securitie(s) over the backtest period (the same could be done for opening minutes). For liquid securities, I suspect that you'll just flag the days the market closes early, according to schedule. However for thinly traded securities (or for ones that have had trading suspended during the day), you'll need the datetime stamps to ensure that your trades are executed properly in the backtest (however, there is a potential look-ahead bias here, since you'd be using future unknown data in your backtest).
Make sense?
Grant