mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-06 01:05:37 +08:00
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:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user