def test_addtick4(self):
        """ simulate the processing of a large period of ticks
            the corresponding number of candles for each timeframe should
            be generated
        """
        # candleCountKnown = {"M1": 6, "M5": 1,
        #                     "M15": 1, "H1": 1, "H4": 1, "D": 1}

        candleCountKnown = {"M1": 927, "M5": 187,
                            "M15": 63, "H1": 16, "H4": 5, "D": 2}

        candleCountReal = {}
        for G in candleCountKnown.keys():
            cf = CandleFactory("DE30_EUR", G)
            n = 0
            with open(TICKDATA) as I:
                for tick in I:
                    if tick[0] == '#':
                        continue
                    r = cf.processTick(StreamRecord(tick))
                    if r:
                        n += 1

            candleCountReal.update({G: n})

        self.assertEqual(candleCountKnown, candleCountReal)
    def test_numerical_granularity(self):
        """ initialize a timeframe, diff between end - start should
            correspond with the numerical equivalent of the granularity
        """
        cft = 0
        grt = 0
        for G in ["M1", "M5", "M15", "H1"]:
            testdata = test_ticks[G]
            cf = CandleFactory("DE30_EUR", G)
            r = cf.processTick(StreamRecord(testdata[0]))
            cft += (cf.end - cf.start)
            grt += granularity_to_time(G)

        self.assertEqual(cft, grt)
 def test_frames(self):
     """ ticks that make a timeframe : atEndOfTimeFrame
         candle data should be returned
         perform this for given granularities
     """
     self.maxDiff = None
     for F in ["M1", "M5", "M15", "H1"]:
         testdata = test_ticks[F]
         candle_factory = CandleFactory("DE30_EUR", F,
                                        processingMode='atEndOfTimeFrame')
         res = []
         for T in testdata:
             r = candle_factory.processTick(StreamRecord(T))
             res.append(r)
         self.assertEqual(res, [None, None, None, None, None, candles[F]])