Ejemplo n.º 1
0
class TickFeederThread(Thread):
    """
        This is used to retrieve realtime info
        and broadcast to all trading engines
    """

    def __init__(self, config, pubsub, securities, start=None, end=None):
        Thread.__init__(self)
        self.config = config
        self.tick_feeder = TickFeeder(
            publisher=pubsub,
            securities=securities,
            dam=self._create_dam(""),  # no need to set symbol because it's batch operation
        )
        self.last_execution = datetime.now()

    def _create_dam(self, symbol):
        dam_name = self.config.get(CONF_ANALYZER_SECTION, CONF_INPUT_DAM)
        input_db = self.config.get(CONF_ANALYZER_SECTION, CONF_INPUT_DB)
        dam = DAMFactory.createDAM(dam_name, {'db': input_db})
        dam.symbol = symbol

        return dam

    def run(self):
        self.last_execution = datetime.now()
        self.tick_feeder.execute(self.last_execution, datetime.now())
Ejemplo n.º 2
0
    def test_tick_feeder(self):
        now = datetime.datetime.now()
        start = datetime.datetime.now() - timedelta(days=1)
        end = datetime.datetime.now() + timedelta(days=1)
        tick_1_dam1 = Tick(security=self.stock_one, trade_date=now, price=Decimal(19), volume=100)
        tick_2_dam1 = Tick(security=self.stock_one, trade_date=now, price=Decimal(23), volume=100)

        now_2 = datetime.datetime.now()
        tick_1_dam2 = Tick(security=self.stock_two, trade_date=now_2, price=Decimal(8), volume=100)
        tick_2_dam2 = Tick(security=self.stock_two, trade_date=now_2, price=Decimal(12), volume=100)

        dam1 = self.mock.CreateMock(BaseDAM)
        dam1.read_ticks(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([tick_1_dam1, tick_2_dam1])

        dam2 = self.mock.CreateMock(BaseDAM)
        dam2.read_ticks(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([tick_1_dam2, tick_2_dam2])

        tf_1 = TickFeeder(publisher=self.pubsub, dam=dam1)
        tf_2 = TickFeeder(publisher=self.pubsub, dam=dam2)

        self.mock.ReplayAll()
        time_ticks_1 = tf_1.load(start, end)
        time_ticks_2 = tf_2.load(start, end)
        self.mock.VerifyAll()

        self.assertEquals(time_ticks_1, [tick_1_dam1, tick_2_dam1])
        self.assertEquals(time_ticks_2, [tick_1_dam2, tick_2_dam2])
Ejemplo n.º 3
0
class TickFeederThread(Thread):
    """
        This is used to retrieve realtime info
        and broadcast to all trading engines
    """
    def __init__(self, config, pubsub, securities, start=None, end=None):
        Thread.__init__(self)
        self.config = config
        self.tick_feeder = TickFeeder(
            publisher=pubsub,
            securities=securities,
            dam=self._create_dam(
                ""),  # no need to set symbol because it's batch operation
        )
        self.last_execution = datetime.now()

    def _create_dam(self, symbol):
        dam_name = self.config.get(CONF_ANALYZER_SECTION, CONF_INPUT_DAM)
        input_db = self.config.get(CONF_ANALYZER_SECTION, CONF_INPUT_DB)
        dam = DAMFactory.createDAM(dam_name, {'db': input_db})
        dam.symbol = symbol

        return dam

    def run(self):
        self.last_execution = datetime.now()
        self.tick_feeder.execute(self.last_execution, datetime.now())
Ejemplo n.º 4
0
 def __init__(self, config, pubsub, securities, start=None, end=None):
     Thread.__init__(self)
     self.config = config
     self.tick_feeder = TickFeeder(
         publisher=pubsub,
         securities=securities,
         dam=self._create_dam(
             ""),  # no need to set symbol because it's batch operation
     )
     self.last_execution = datetime.now()
Ejemplo n.º 5
0
 def __init__(self, config, pubsub, securities, start=None, end=None):
     Thread.__init__(self)
     self.config = config
     self.tick_feeder = TickFeeder(
         publisher=pubsub,
         securities=securities,
         dam=self._create_dam(""),  # no need to set symbol because it's batch operation
     )
     self.last_execution = datetime.now()
Ejemplo n.º 6
0
    def test_tick_feeder(self):
        now = datetime.datetime.now()
        start = datetime.datetime.now() - timedelta(days=1)
        end = datetime.datetime.now() + timedelta(days=1)
        tick_1_dam1 = Tick(security=self.stock_one,
                           trade_date=now,
                           price=Decimal(19),
                           volume=100)
        tick_2_dam1 = Tick(security=self.stock_one,
                           trade_date=now,
                           price=Decimal(23),
                           volume=100)

        now_2 = datetime.datetime.now()
        tick_1_dam2 = Tick(security=self.stock_two,
                           trade_date=now_2,
                           price=Decimal(8),
                           volume=100)
        tick_2_dam2 = Tick(security=self.stock_two,
                           trade_date=now_2,
                           price=Decimal(12),
                           volume=100)

        dam1 = self.mock.CreateMock(BaseDAM)
        dam1.read_ticks(mox.IgnoreArg(), mox.IgnoreArg(),
                        mox.IgnoreArg()).AndReturn([tick_1_dam1, tick_2_dam1])

        dam2 = self.mock.CreateMock(BaseDAM)
        dam2.read_ticks(mox.IgnoreArg(), mox.IgnoreArg(),
                        mox.IgnoreArg()).AndReturn([tick_1_dam2, tick_2_dam2])

        tf_1 = TickFeeder(publisher=self.pubsub, dam=dam1)
        tf_2 = TickFeeder(publisher=self.pubsub, dam=dam2)

        self.mock.ReplayAll()
        time_ticks_1 = tf_1.load(start, end)
        time_ticks_2 = tf_2.load(start, end)
        self.mock.VerifyAll()

        self.assertEquals(time_ticks_1, [tick_1_dam1, tick_2_dam1])
        self.assertEquals(time_ticks_2, [tick_1_dam2, tick_2_dam2])