Exemple #1
0
class TradingEngineThread(Thread):
    def __init__(self, pubsub, securities, strategy):
        Thread.__init__(self)
        self.trading_engine = TradingEngine(pubsub, strategy)
        for security in securities:
            self.trading_engine.listen(security)

    def run(self):
        while True:
            self.trading_engine.consume()
Exemple #2
0
class TradingEngineThread(Thread):

    def __init__(self, pubsub, securities, strategy):
        Thread.__init__(self)
        self.trading_engine = TradingEngine(pubsub, strategy)
        for security in securities:
            self.trading_engine.listen(security)

    def run(self):
        while True:
            self.trading_engine.consume()
    def test_register_strategy(self):
        trading_engine = TradingEngine()
        trading_engine.register(self.strategy)

        # lets check that the trading engine was setup correctly
        for key in trading_engine.subscribers.keys():
            event = trading_engine.subscribers[key]
            for strategy in event.keys():
                self.assertEquals(self.strategy, strategy)
                self.assertEquals(self.symbols, event[strategy]['symbols'])
                self.assertEquals(0, event[strategy]['fail'])
Exemple #4
0
 def __init__(self, pubsub, securities, strategy):
     Thread.__init__(self)
     self.trading_engine = TradingEngine(pubsub, strategy)
     for security in securities:
         self.trading_engine.listen(security)
    def test_unregister_strategy(self):
        trading_engine = TradingEngine()
        trading_engine.register(self.strategy)

        self.assertEquals(len(trading_engine.strategies), 2)
        trading_engine.unregister(self.strategy)
        # since this was the only strategy check if events is empty
        self.assertEquals(len(trading_engine.strategies), 0)
        trading_engine.register(self.strategy)
        trading_engine.register(self.strategy2)
        self.assertEquals(len(trading_engine.strategies), 2)
        self.assertEquals(len(map(lambda vdict: vdict.keys(), trading_engine.strategies.values())[0]), 2)
        self.assertEquals(len(map(lambda vdict: vdict.keys(), trading_engine.strategies.values())[1]), 2)
        trading_engine.unregister(self.strategy)
        self.assertEquals(len(trading_engine.strategies.keys()), 2)
        self.assertEquals(len(map(lambda vdict: vdict.keys(), trading_engine.strategies.values())[0]), 1)
        self.assertEquals(len(map(lambda vdict: vdict.keys(), trading_engine.strategies.values())[1]), 1)
    def test_stop(self):
        trading_engine = TradingEngine()
        self.assertFalse(trading_engine._stop)
        trading_engine.stop()

        self.assertTrue(trading_engine._stop)
Exemple #7
0
 def test_register_strategy(self):
     trading_engine = TradingEngine(self.pubsub, self.strategy)
Exemple #8
0
 def __init__(self, pubsub, securities, strategy):
     Thread.__init__(self)
     self.trading_engine = TradingEngine(pubsub, strategy)
     for security in securities:
         self.trading_engine.listen(security)