Esempio n. 1
0
    def testSqlDam(self):
        dam = SqlDAM(echo = False)
        dam.setup({"db": 'sqlite:////tmp/sqldam.sqlite'})
        dam.setSymbol("test")

        quotes = [Quote(*['1320676200', '32.59', '32.59', '32.58', '32.58', '65213', None]),
                  Quote(*['1320676201', '32.60', '32.60', '32.59', '32.59', '65214', None])]
        ticks = [Tick(*['1320676200', '32.59', '32.59', '32.58', '32.58', '65213']),
                 Tick(*['1320676201', '32.60', '32.60', '32.59', '32.59', '65214'])]

        dam.writeQuotes(quotes)
        dam.writeTicks(ticks)
        dam.commit()
        print([str(quotes) for symbol, quotes in dam.readBatchTupleQuotes(["test"], 0, None).items() ])
        print([str(quote) for quote in dam.readQuotes(0, None) ])
        print([str(tick) for tick in dam.readTicks(0, "1320676201")])
        print([str(tick) for tick in dam.readTicks(0, "1320676202")])
Esempio n. 2
0
    def __rowResultToTick(self, row):
        ''' convert rowResult from Hbase to Tick'''
        keyValues = row.columns
        for field in TICK_FIELDS:
            key = "%s:%s" % (HBaseDAM.TICK, field)
            if 'time' != field and keyValues[key].value:
                keyValues[key].value = float(keyValues[key].value)

        return Tick(*[keyValues["%s:%s" % (HBaseDAM.TICK, field)].value for field in TICK_FIELDS])
Esempio n. 3
0
    def testWriteExcel(self):
        writeDam = ExcelDAM()
        writeDam.setDir(self.targetPath)
        writeDam.setSymbol(self.symbol)

        for f in [
                writeDam.targetPath(ExcelDAM.QUOTE),
                writeDam.targetPath(ExcelDAM.TICK)
        ]:
            if os.path.exists(f):
                os.remove(f)

        quote1 = Quote('1320676200', '32.58', '32.58', '32.57', '32.57',
                       '65212', None)
        quote2 = Quote('1320676201', '32.59', '32.59', '32.58', '32.58',
                       '65213', None)
        tick1 = Tick('1320676200', '32.58', '32.58', '32.57', '32.57', '65212')
        tick2 = Tick('1320676201', '32.59', '32.59', '32.58', '32.58', '65213')
        writeDam.writeQuotes([quote1, quote2])
        writeDam.writeTicks([tick1, tick2])
Esempio n. 4
0
    def readTicks(self, start, end):
        ''' read ticks '''
        rows = self.__hbase.scanTable(self.tableName(HBaseDAM.TICK), [HBaseDAM.TICK], start, end)
        return [self.__rowResultToTick(row) for row in rows]

    def writeTicks(self, ticks):
        ''' read quotes '''
        tName = self.tableName(HBaseDAM.TICK)
        if tName not in self.__hbase.getTableNames():
            self.__hbase.createTable(tName, [ColumnDescriptor(name=HBaseDAM.TICK, maxVersions=5)])

        for tick in ticks:
            self.__hbase.updateRow(self.tableName(HBaseDAM.TICK),
                                   tick.time,
                                   [Mutation(column = "%s:%s" % (HBaseDAM.TICK, field),
                                             value = getattr(tick, field) ) for field in TICK_FIELDS])

if __name__ == '__main__':
    dam = HBaseDAM()
    dam.setSymbol("test")
    quotes = [Quote(*['1320676200', '32.59', '32.59', '32.58', '32.58', '65213', None]),
              Quote(*['1320676201', '32.60', '32.60', '32.59', '32.59', '65214', None])]
    ticks = [Tick(*['1320676200', '32.59', '32.59', '32.58', '32.58', '65213']),
              Tick(*['1320676201', '32.60', '32.60', '32.59', '32.59', '65214'])]

    dam.writeQuotes(quotes)
    dam.writeTicks(ticks)
    print(dam.readQuotes("0", None))
    print(dam.readTicks("0", "1320676201"))
    print(dam.readTicks("0", "1320676202"))
Esempio n. 5
0
 def readTicks(self, start, end):
     ''' read ticks '''
     ticks = self.__readData(self.targetPath(ExcelDAM.TICK), start, end)
     return [Tick(*tick) for tick in ticks]