Пример #1
0
def test_zmq_eventengine():
    """测试函数"""
    import sys
    from datetime import datetime
    import time

    def simpletest(event):
        six.print_(str(datetime.now()), event.route)

    six.print_('test_zmq_eventengine.....')
    ee = ZMQEventEngine('test_zmq_eventengine')
    ee.register(Event.TIMER, simpletest)
    timer = Timer(ee)
    ee.start()
    timer.start()
    event = Event(route=Event.TIMER)
    ee.emit(event)
    ## @TODO test_unregister

    #time.sleep(2)
    #ee.stop_timer()
    #time.sleep(2)
    #ee.resume_timer()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        timer.stop()
        ee.stop()
        sys.exit(0)
Пример #2
0
class Backend(BackendInterface):
    ## @TODO singleton
    SERVER_FOR_UI = 'backend4ui' 
    SERVER_FOR_SHELL = "backend4shell" 
    def __init__(self):
        log.info("Init Backend..")
        self._engine = ZMQEventEngine('Backend')
        self._engine.start()

        self._shell_srv = EventRPCServer(self._engine, 
                                self.SERVER_FOR_SHELL)
        self._ui_srv = EventRPCServer(self._engine, 
                                self.SERVER_FOR_UI)
        self.register_functions(self._shell_srv)
        self.register_functions(self._ui_srv)

    def register_functions(self, server):
        server.register('get_all_contracts', self.get_all_contracts)
        server.register('get_all_pcontracts', self.get_all_pcontracts)
        server.register('get_pcontract', self.get_pcontract)
        server.register('get_strategies', self.get_strategies)
        server.register('run_strategy', self.run_strategy)
        server.register('run_technical', self.run_technical)

    def stop(self):
        log.info('Backend stopped.')
        self._engine.stop()

    def get_all_contracts(self):
        # 模拟接口
        data = ['CC.SHFE-1.MINUTE', 'BB.SHFE-1.MINUTE']
        pcons =  [PContract.from_string(d) for d in data]
        contracts =  [pcon.contract for pcon in pcons]
        return serialize_all_contracts(contracts)

    def get_all_pcontracts(self):
        # 模拟接口
        data = ['CC.SHFE-1.MINUTE', 'BB.SHFE-1.MINUTE']
        pcontracts =  [PContract.from_string(d) for d in data]
        return serialize_all_pcontracts(pcontracts)

    def get_pcontract(self, str_pcontract):
        dm = DataManager()
        da = dm.get_bars(str_pcontract)
        return serialize_pcontract_bars(str_pcontract, da.data)

    def run_strategy(self, name):
        """""" 
        return

    def run_technical(self, name):
        return

    def get_technicals(self):
        """ 获取系统的所有指标。 """
        from quantdigger.technicals import get_techs
        return get_techs()

    def get_strategies(self):
        return 'hello' 
Пример #3
0
class WindowGate(BackendInterface):
    SERVER_FOR_SHELL = "ui4shell"

    def __init__(self, widget):
        log.info("Init WindowGate..")
        self._engine = ZMQEventEngine('WindowGate')
        self._engine.start()
        self._backend = EventRPCClient('WindowGate', self._engine,
                                       Backend.SERVER_FOR_UI)
        self._shell_srv = EventRPCServer(self._engine, self.SERVER_FOR_SHELL)
        self._register_functions(self._shell_srv)
        self._period = None
        self._contract = None
        self._widget = widget

    def _register_functions(self, server):
        server.register('get_all_contracts', self.get_all_contracts)
        server.register('get_all_pcontracts', self.get_all_pcontracts)
        server.register('get_pcontract', self.get_pcontract)
        server.register('show_data', self.show_data)

    def add_widget(self, ith, type_):
        self._widget.add_widget

    def add_technical(self, ith, technical):
        """"""
        ## @TODO compute technical with backend,
        # display result from backend
        return

    @property
    def pcontract(self):
        return PContract(self._contract, self._period)

    def stop(self):
        self._engine.stop()

    def get_all_contracts(self):
        ret = self._backend.sync_call('get_all_contracts')
        return deserialize_all_contracts(ret)

    def get_all_pcontracts(self):
        ret = self._backend.sync_call('get_all_pcontracts')
        return deserialize_all_pcontracts(ret)

    def get_pcontract(self, str_pcontract):
        ret = self._backend.sync_call('get_pcontract',
                                      {'str_pcontract': str_pcontract})
        return deserialize_pcontract_bars(ret)

    def run_strategy(self, name):
        """"""
        return

    def run_technical(self, name):
        return

    def get_technicals(self):
        """ 获取系统的所有指标。 """
        return

    def get_strategies(self):
        """ 获取系统的所有策略。 """
        return

    def show_data(self, pcontract):
        self._widget.show_data(pcontract)
Пример #4
0
class WindowGate(BackendInterface):
    SERVER_FOR_SHELL = "ui4shell"
    def __init__(self, widget):
        log.info("Init WindowGate..")
        self._engine = ZMQEventEngine('WindowGate')
        self._engine.start()
        self._backend = EventRPCClient('WindowGate', self._engine, Backend.SERVER_FOR_UI)
        self._shell_srv = EventRPCServer(self._engine, self.SERVER_FOR_SHELL)
        self._register_functions(self._shell_srv)
        self._period = None
        self._contract = None
        self._widget = widget

    def _register_functions(self, server):
        server.register('get_all_contracts', self.get_all_contracts)
        server.register('get_all_pcontracts', self.get_all_pcontracts)
        server.register('get_pcontract', self.get_pcontract)
        server.register('show_data', self.show_data)

    def add_widget(self, ith, type_):
        self._widget.add_widget

    def add_technical(self, ith, technical):
        """""" 
        ## @TODO compute technical with backend,
        # display result from backend
        return

    @property
    def pcontract(self):
        return PContract(self._contract, self._period)

    def stop(self):
        self._engine.stop()

    def get_all_contracts(self):
        ret = self._backend.sync_call('get_all_contracts')
        return deserialize_all_contracts(ret)

    def get_all_pcontracts(self):
        ret = self._backend.sync_call('get_all_pcontracts')
        return deserialize_all_pcontracts(ret)

    def get_pcontract(self, str_pcontract):
        ret = self._backend.sync_call('get_pcontract', {
            'str_pcontract': str_pcontract
            })
        return deserialize_pcontract_bars(ret)

    def run_strategy(self, name):
        """""" 
        return

    def run_technical(self, name):
        return

    def get_technicals(self):
        """ 获取系统的所有指标。 """
        return

    def get_strategies(self):
        """ 获取系统的所有策略。 """
        return

    def show_data(self, pcontract):
        self._widget.show_data(pcontract)
Пример #5
0
class Backend:
    SERVER_FOR_UI = 'backend4ui'
    SERVER_FOR_SHELL = "backend4shell"

    def __init__(self):
        log.info("Init Backend..")
        self._dm = DataManager()
        self._engine = ZMQEventEngine('Backend')
        self._engine.start()

        self._shell_srv = EventRPCServer(self._engine, self.SERVER_FOR_SHELL)
        self._ui_srv = EventRPCServer(self._engine, self.SERVER_FOR_UI)
        self.register_functions(self._shell_srv)
        self.register_functions(self._ui_srv)

    def register_functions(self, server):
        server.register('get_all_contracts', self.get_all_contracts)
        server.register('get_all_pcontracts', self.get_all_pcontracts)
        server.register('get_pcontract', self.get_pcontract)
        server.register('get_strategies', self.get_strategies)
        server.register('run_strategy', self.run_strategy)
        server.register('run_technical', self.run_technical)
        server.register('test_speed', self.test_speed)

    def stop(self):
        log.info('Backend stopped.')
        self._engine.stop()

    def get_all_contracts(self):
        def _mk_contract(code, exchage):
            s = '%s.%s' % (code, exchage)
            return Contract(s)

        # 模拟接口
        df = self._dm.get_contracts()
        contracts = [
            str(_mk_contract(row['code'], row['exchange']))
            for _, row in df.iterrows()
        ]
        return serialize_all_contracts(contracts)

    def get_all_pcontracts(self):
        # 模拟接口
        data = ['CC.SHFE-1.MINUTE', 'BB.SHFE-1.MINUTE']
        pcontracts = [PContract.from_string(d) for d in data]
        return serialize_all_pcontracts(pcontracts)

    def get_pcontract(self, str_pcontract):
        da = self._dm.get_bars(str_pcontract)
        return serialize_pcontract_bars(str_pcontract, da.data)

    def run_strategy(self, name):
        """"""
        return

    def run_technical(self, name):
        return

    def get_technicals(self):
        """ 获取系统的所有指标。 """
        from quantdigger.technicals import get_techs
        return get_techs()

    def get_strategies(self):
        return 'hello'

    def test_speed(self):
        return 'hello world!'
Пример #6
0
class Backend:
    SERVER_FOR_UI = 'backend4ui'
    SERVER_FOR_SHELL = "backend4shell"

    def __init__(self):
        log.info("Init Backend..")
        self._dm = DataManager()
        self._engine = ZMQEventEngine('Backend')
        self._engine.start()

        self._shell_srv = EventRPCServer(self._engine,
                                         self.SERVER_FOR_SHELL)
        self._ui_srv = EventRPCServer(self._engine,
                                      self.SERVER_FOR_UI)
        self.register_functions(self._shell_srv)
        self.register_functions(self._ui_srv)

    def register_functions(self, server):
        server.register('get_all_contracts', self.get_all_contracts)
        server.register('get_all_pcontracts', self.get_all_pcontracts)
        server.register('get_pcontract', self.get_pcontract)
        server.register('get_strategies', self.get_strategies)
        server.register('run_strategy', self.run_strategy)
        server.register('run_technical', self.run_technical)
        server.register('test_speed', self.test_speed)

    def stop(self):
        log.info('Backend stopped.')
        self._engine.stop()

    def get_all_contracts(self):
        def _mk_contract(code, exchage):
            s = '%s.%s' % (code, exchage)
            return Contract(s)
        # 模拟接口
        df = self._dm.get_contracts()
        contracts = [str(_mk_contract(row['code'], row['exchange'])) for _, row in df.iterrows()]
        return serialize_all_contracts(contracts)

    def get_all_pcontracts(self):
        # 模拟接口
        data = ['CC.SHFE-1.MINUTE', 'BB.SHFE-1.MINUTE']
        pcontracts = [PContract.from_string(d) for d in data]
        return serialize_all_pcontracts(pcontracts)

    def get_pcontract(self, str_pcontract):
        da = self._dm.get_bars(str_pcontract)
        return serialize_pcontract_bars(str_pcontract, da.data)

    def run_strategy(self, name):
        """"""
        return

    def run_technical(self, name):
        return

    def get_technicals(self):
        """ 获取系统的所有指标。 """
        from quantdigger.technicals import get_techs
        return get_techs()

    def get_strategies(self):
        return 'hello'

    def test_speed(self):
        return 'hello world!'