示例#1
0
 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),
     )
示例#2
0
 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))
示例#3
0
 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),
     )
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
 def __updateNextBarClose(self):
     self.__nextBarClose = resampled.get_slot_datetime(
         utcnow(), self.__frequency) + self.__timeDelta
示例#7
0
 def __updateNextBarClose(self):
     self.__nextBarClose = resampled.get_slot_datetime(utcnow(), self.__frequency) + self.__timeDelta