def testSlotDateTime(self): # 1 minute self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60), datetime.datetime(2011, 1, 1, 1, 1) ) # 1 hour self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60 * 60), datetime.datetime(2011, 1, 1, 1), ) # 1 day self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60 * 60 * 24), datetime.datetime(2011, 1, 1), )
def testSlotDateTime(self): # 1 minute self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60), datetime.datetime(2011, 1, 1, 1, 1)) self.assertEqual( resampled.get_slot_datetime( datetime.datetime(2011, 1, 1, 1, 1, 1, microsecond=1), 60), datetime.datetime(2011, 1, 1, 1, 1)) # 5 minute self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 0), 60 * 5), datetime.datetime(2011, 1, 1, 1, 0)) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1), 60 * 5), datetime.datetime(2011, 1, 1, 1, 0)) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 4), 60 * 5), datetime.datetime(2011, 1, 1, 1, 0)) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 5), 60 * 5), datetime.datetime(2011, 1, 1, 1, 5)) # 1 hour self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60 * 60), datetime.datetime(2011, 1, 1, 1)) self.assertEqual( resampled.get_slot_datetime( datetime.datetime(2011, 1, 1, 1, 1, 1, microsecond=1), 60 * 60), datetime.datetime(2011, 1, 1, 1)) # 1 day self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60 * 60 * 24), datetime.datetime(2011, 1, 1)) self.assertEqual( resampled.get_slot_datetime( datetime.datetime(2011, 1, 1, 1, 1, 1, microsecond=1), 60 * 60 * 24), datetime.datetime(2011, 1, 1))
def testSlotDateTime(self): # 1 minute self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60), datetime.datetime(2011, 1, 1, 1, 1) ) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1, microsecond=1), 60), datetime.datetime(2011, 1, 1, 1, 1), ) # 5 minute self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 0), 60 * 5), datetime.datetime(2011, 1, 1, 1, 0), ) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1), 60 * 5), datetime.datetime(2011, 1, 1, 1, 0), ) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 4), 60 * 5), datetime.datetime(2011, 1, 1, 1, 0), ) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 5), 60 * 5), datetime.datetime(2011, 1, 1, 1, 5), ) # 1 hour self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60 * 60), datetime.datetime(2011, 1, 1, 1), ) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1, microsecond=1), 60 * 60), datetime.datetime(2011, 1, 1, 1), ) # 1 day self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1), 60 * 60 * 24), datetime.datetime(2011, 1, 1), ) self.assertEqual( resampled.get_slot_datetime(datetime.datetime(2011, 1, 1, 1, 1, 1, microsecond=1), 60 * 60 * 24), datetime.datetime(2011, 1, 1), )
def __onBars(self, dateTime, bars): slotDateTime = resampled.get_slot_datetime(dateTime, self.__frequency) bar = bars[self.__instrument] if self.__slot is None: self.__slot = resampled.Slot(slotDateTime, bar) elif self.__slot.getDateTime() == slotDateTime: self.__slot.addBar(bar) else: self.__writer.writeSlot(self.__slot) self.__slot = resampled.Slot(slotDateTime, bar)
def __onBars(self, dateTime, bars): slotDateTime = resampled.get_slot_datetime(dateTime, self.__frequency) bar = bars[self.__instrument] if self.__slot is None: self.__slot = resampled.Slot(slotDateTime, bar, self.__frequency) elif self.__slot.getDateTime() == slotDateTime: self.__slot.addBar(bar) else: self.__writer.writeSlot(self.__slot) self.__slot = resampled.Slot(slotDateTime, bar, self.__frequency)
def __updateNextBarClose(self): self.__nextBarClose = resampled.get_slot_datetime( utcnow(), self.__frequency) + self.__timeDelta
def __updateNextBarClose(self): self.__nextBarClose = resampled.get_slot_datetime(utcnow(), self.__frequency) + self.__timeDelta