Ejemplo n.º 1
0
 def __onNewValues(self, dateTime, value):
     if self.__range is None:
         self.__range = resamplebase.build_range(dateTime, self.getFrequency())
         self.__grouper = BarsGrouper(self.__range.getBeginning(), value, self.getFrequency())
     elif self.__range.belongs(dateTime):
         self.__grouper.addValue(value)
     else:
         self.__values.append(self.__grouper.getGrouped())
         self.__range = resamplebase.build_range(dateTime, self.getFrequency())
         self.__grouper = BarsGrouper(self.__range.getBeginning(), value, self.getFrequency())
Ejemplo n.º 2
0
 def __onNewValues(self, dateTime, value):
     if self.__range is None:
         self.__range = resamplebase.build_range(dateTime, self.getFrequency())
         self.__grouper = BarsGrouper(self.__range.getBeginning(), value, self.getFrequency())
     elif self.__range.belongs(dateTime):
         self.__grouper.addValue(value)
     else:
         self.__values.append(self.__grouper.getGrouped())
         self.__range = resamplebase.build_range(dateTime, self.getFrequency())
         self.__grouper = BarsGrouper(self.__range.getBeginning(), value, self.getFrequency())
Ejemplo n.º 3
0
 def __onNewValue(self, dataSeries, dateTime, value):
     if self.__range is None:
         self.__range = resamplebase.build_range(dateTime, self.__frequency)
         self.__grouper = BarGrouper(self.__range.getBeginning(), value, self.__frequency)
     elif self.__range.belongs(dateTime):
         self.__grouper.addValue(value)
     else:
         self.appendWithDateTime(self.__grouper.getDateTime(), self.__grouper.getGrouped())
         self.__range = resamplebase.build_range(dateTime, self.__frequency)
         self.__grouper = BarGrouper(self.__range.getBeginning(), value, self.__frequency)
Ejemplo n.º 4
0
 def __onNewValue(self, dataSeries, dateTime, value):
     if self.__range is None:
         self.__range = resamplebase.build_range(dateTime, self.__frequency)
         self.__grouper = self.buildGrouper(self.__range, value, self.__frequency)
     elif self.__range.belongs(dateTime):
         self.__grouper.addValue(value)
     else:
         self.appendWithDateTime(self.__grouper.getDateTime(), self.__grouper.getGrouped())
         self.__range = resamplebase.build_range(dateTime, self.__frequency)
         self.__grouper = self.buildGrouper(self.__range, value, self.__frequency)
Ejemplo n.º 5
0
 def testFiveMinuteRange(self):
     freq = 60*5
     begin = datetime.datetime(2011, 1, 1, 1)
     r = resamplebase.build_range(begin + datetime.timedelta(seconds=120), freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 1, 1, 1, 5))
Ejemplo n.º 6
0
 def testHourRange(self):
     freq = bar.Frequency.HOUR
     begin = datetime.datetime(2011, 1, 1, 16)
     r = resamplebase.build_range(begin + datetime.timedelta(seconds=120), freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 1, 1, 17))
Ejemplo n.º 7
0
 def test28Days(self):
     freq = bar.Frequency.MONTH
     begin = datetime.datetime(2011, 2, 1)
     r = resamplebase.build_range(begin + datetime.timedelta(hours=5, minutes=25), freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq - bar.Frequency.DAY*3):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 3, 1))
Ejemplo n.º 8
0
 def testMinuteRange(self):
     freq = bar.Frequency.MINUTE
     begin = datetime.datetime(2011, 1, 1, 1, 1)
     r = resamplebase.build_range(begin + datetime.timedelta(seconds=5), freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 1, 1, 1, 2))
Ejemplo n.º 9
0
 def testDecember(self):
     freq = bar.Frequency.MONTH
     begin = datetime.datetime(2011, 12, 1)
     r = resamplebase.build_range(begin + datetime.timedelta(hours=5, minutes=25), freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2012, 1, 1))
Ejemplo n.º 10
0
 def testHourRange(self):
     freq = bar.Frequency.HOUR
     begin = datetime.datetime(2011, 1, 1, 16)
     r = resamplebase.build_range(begin + datetime.timedelta(seconds=120),
                                  freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(
         r.belongs(begin + datetime.timedelta(seconds=freq + 1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 1, 1, 17))
Ejemplo n.º 11
0
 def testMinuteRange(self):
     freq = bar.Frequency.MINUTE
     begin = datetime.datetime(2011, 1, 1, 1, 1)
     r = resamplebase.build_range(begin + datetime.timedelta(seconds=5),
                                  freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(
         r.belongs(begin + datetime.timedelta(seconds=freq + 1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 1, 1, 1, 2))
Ejemplo n.º 12
0
 def testFiveMinuteRange(self):
     freq = 60 * 5
     begin = datetime.datetime(2011, 1, 1, 1)
     r = resamplebase.build_range(begin + datetime.timedelta(seconds=120),
                                  freq)
     self.assertEqual(r.getBeginning(), begin)
     for i in range(freq):
         self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
     self.assertFalse(
         r.belongs(begin + datetime.timedelta(seconds=freq + 1)))
     self.assertEqual(r.getEnding(), datetime.datetime(2011, 1, 1, 1, 5))
Ejemplo n.º 13
0
    def __testHourRangeImpl(self, timezone=None):
        freq = bar.Frequency.HOUR

        begin = datetime.datetime(2011, 1, 1, 16)
        end = datetime.datetime(2011, 1, 1, 17)
        if timezone is not None:
            begin = dt.localize(begin, timezone)
            end = dt.localize(end, timezone)

        r = resamplebase.build_range(begin + datetime.timedelta(seconds=120), freq)
        self.assertEqual(r.getBeginning(), begin)
        for i in range(freq):
            self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
        self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
        self.assertEqual(r.getEnding(), end)
Ejemplo n.º 14
0
    def __testHourRangeImpl(self, timezone=None):
        freq = bar.Frequency.HOUR

        begin = datetime.datetime(2011, 1, 1, 16)
        end = datetime.datetime(2011, 1, 1, 17)
        if timezone is not None:
            begin = dt.localize(begin, timezone)
            end = dt.localize(end, timezone)

        r = resamplebase.build_range(begin + datetime.timedelta(seconds=120), freq)
        self.assertEqual(r.getBeginning(), begin)
        for i in range(freq):
            self.assertTrue(r.belongs(begin + datetime.timedelta(seconds=i)))
        self.assertFalse(r.belongs(begin + datetime.timedelta(seconds=freq+1)))
        self.assertEqual(r.getEnding(), end)
Ejemplo n.º 15
0
 def __updateNextBarClose(self):
     self.__nextBarClose = resamplebase.build_range(
         utcnow(), self.__frequency).getEnding()
Ejemplo n.º 16
0
    def __updateNextBarClose(self):

        self.__nextBarClose = resamplebase.build_range(
            localnow(), self.__frequency).getEnding()
        logger.info('local: {0} ,nextcall: {1}'.format(localnow(),
                                                       self.__nextBarClose))
Ejemplo n.º 17
0
 def __updateNextBarClose(self):
     print  'local', localnow()
     self.__nextBarClose = resamplebase.build_range(localnow(), self.__frequency).getEnding()
     print  'nextcall', self.__nextBarClose
Ejemplo n.º 18
0
 def __updateNextBarClose(self):
     self.__nextBarClose = resamplebase.build_range(utcnow(), self.__frequency).getEnding()