Пример #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