MAINT: Moves exchange to utc conversion inside of environment object.

So that the environments' exchange time is used without having to
specify it independently.

Also, moves uses of Delorean.shift for the exchange conversion inside
of environment to use the exchange_dt_to_utc method.
This commit is contained in:
Eddie Hebert
2013-03-28 12:29:52 -04:00
parent 10825c9a1d
commit 147e806bb0
2 changed files with 9 additions and 12 deletions
+4 -5
View File
@@ -1033,11 +1033,10 @@ class TestPerformanceTracker(unittest.TestCase):
def test_minute_tracker(self):
""" Tests minute performance tracking."""
exc_tz = pytz.timezone('US/Eastern')
start_dt = trading.exchange_dt_in_utc(
datetime.datetime(2013, 3, 1, 9, 30, tzinfo=exc_tz))
end_dt = trading.exchange_dt_in_utc(
datetime.datetime(2013, 3, 1, 16, 0, tzinfo=exc_tz))
start_dt = trading.environment.exchange_dt_in_utc(
datetime.datetime(2013, 3, 1, 9, 30))
end_dt = trading.environment.exchange_dt_in_utc(
datetime.datetime(2013, 3, 1, 16, 0))
sim_params = SimulationParameters(
period_start=start_dt,
+5 -7
View File
@@ -74,11 +74,6 @@ log = logbook.Logger('Transaction Simulator')
environment = None
def exchange_dt_in_utc(dt):
delorean = Delorean(dt, dt.tzinfo)
return delorean.shift(pytz.utc.zone).datetime
class TransactionSimulator(object):
def __init__(self):
@@ -156,6 +151,10 @@ class TradingEnvironment(object):
tzinfo=pytz.utc
)
def exchange_dt_in_utc(self, dt):
delorean = Delorean(dt, self.exchange_tz)
return delorean.shift(pytz.utc.zone).datetime
@property
def period_trading_days(self):
if self._period_trading_days is None:
@@ -223,8 +222,7 @@ Last successful date: %s" % self.market_open)
)
# create a new Delorean with the next_open naive date and
# the correct timezone for the exchange.
open_delorean = Delorean(next_open, self.exchange_tz)
open_utc = open_delorean.shift(pytz.utc.zone).datetime
open_utc = self.exchange_dt_in_utc(next_open)
market_open = open_utc
market_close = market_open + self.get_trading_day_duration(open_utc)