Esempio n. 1
0
    def __init__(self):
        """Constructor"""
        self.ee = EventEngine()  # 创建事件驱动引擎

        #self.md = DemoMdApi(self.ee)    # 创建API接口
        #self.td = DemoTdApi(self.ee)

        self.ee.start()  # 启动事件驱动引擎

        # 循环查询持仓和账户相关
        self.countGet = 0  # 查询延时计数
        self.lastGet = 'Account'  # 上次查询的性质
        #self.ee.register(EVENT_TDLOGIN, self.initGet)  # 登录成功后开始初始化查询

        # 合约储存相关
        self.dictInstrument = {}  # 字典(保存合约查询数据)
Esempio n. 2
0
class MainEngine:
    def __init__(self):
        self.algoInstanceManage = AlgoInstanceManage()
        self._event_engine = EventEngine(self.algoInstanceManage)
        self._event_manage = EventManage(self._event_engine)

    def start(self):
        self._event_engine.start()
        self._event_manage.start()

    def stop(self):
        self._event_engine.stop()
        self._event_manage.stop()

    def create_algo_instance(self, event_type, param_dict):
        self._event_engine.put(event=Event(event_type, params=param_dict))

    def add_algo(self, algo):
        """
        加载算法程序
        :param algo:
        :return:
        """
        self._event_engine.register(algo)
        if algo.config.launch_type == 'unactive':
            self._event_manage.add_Config(algo.config)

    def remove_algo(self, algo):
        """
        移除算法程序
        :param algo:
        :return:
        """
        self._event_engine.unregister(algo)
        if algo.config.launch_type == 'unactive':
            self._event_manage.remove_Config(algo.config)

    def deploy_algo(self):
        pass
Esempio n. 3
0
    def __init__(self):
        """Constructor"""
        self.ee = EventEngine()         # 创建事件驱动引擎

        #self.md = DemoMdApi(self.ee)    # 创建API接口
        #self.td = DemoTdApi(self.ee)

        self.ee.start()                 # 启动事件驱动引擎

        # 循环查询持仓和账户相关
        self.countGet = 0               # 查询延时计数
        self.lastGet = 'Account'        # 上次查询的性质
        #self.ee.register(EVENT_TDLOGIN, self.initGet)  # 登录成功后开始初始化查询

        # 合约储存相关
        self.dictInstrument = {}        # 字典(保存合约查询数据)
Esempio n. 4
0
        'price':
        lambda x: -x,
        'number of items':
        lambda x: 0.5 * x,
        'delivery': {
            'delivered': 1.0,
            'not delivered': 0.0
        }
    })


# TODO test for anac2019 tournament
if __name__ == "__main__":
    fig, ax = plt.subplots(1, 1)
    a = ShowProcess(ax=ax,
                    fig=fig,
                    world_recall_reuslt_dict=glovar.
                    world_recall_reuslt_naodongbanana_manager_dict)
    Event_Porcess_New_Step = "Porcess_New_Step"
    listener1 = ListenerTypeOne('naodongbanana',
                                world_recall_reuslt_dict=glovar.
                                world_recall_reuslt_naodongbanana_manager_dict)
    ee = EventEngine()
    ee.register(Event_Porcess_New_Step, listener1.showNewStep)
    ee.start()
    publicAcc = Public_NegmasAccount(ee)
    negmas = Process(target=run_negmas)
    negmas.start()
    # glovar.world_recall_reuslt_naodongbanana_manager_dict['init'].wait()
    a.show()
Esempio n. 5
0
 def __init__(self):
     self.algoInstanceManage = AlgoInstanceManage()
     self._event_engine = EventEngine(self.algoInstanceManage)
     self._event_manage = EventManage(self._event_engine)
Esempio n. 6
0
        event = Event(event_type=self.EventType, data=data)
        self.event_engine.put(event)

    def stop(self):
        self.is_active = False

    def register(self, handle):
        self.event_engine.register(self.EventType, handle)


if __name__ == '__main__':
    from WindPy import w
    from EventEngine import *
    from ClockEngine import *
    w.start()
    tradedate = w.tdays("2018-01-01", "2018-04-07", "").Data[0]
    clocks = ClockEvent("clock", tradedate)
    clock = ClockEngine(EventEngine(), clocks)

    def clockhandel(Event):
        date = Event.data.strftime("%Y-%m-%d")
        bar = tusharebar(date).getOneBar("600008.SH")
        print("传递bar")
        print(bar)

    from tools.getTushareData import *

    clock.register(clockhandel)
    clock.start()
    clock.event_engine.start()
Esempio n. 7
0
class MainEngine(object):
    """主引擎,负责对API的调度"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        self.ee = EventEngine()  # 创建事件驱动引擎

        #self.md = DemoMdApi(self.ee)    # 创建API接口
        #self.td = DemoTdApi(self.ee)

        self.ee.start()  # 启动事件驱动引擎

        # 循环查询持仓和账户相关
        self.countGet = 0  # 查询延时计数
        self.lastGet = 'Account'  # 上次查询的性质
        #self.ee.register(EVENT_TDLOGIN, self.initGet)  # 登录成功后开始初始化查询

        # 合约储存相关
        self.dictInstrument = {}  # 字典(保存合约查询数据)
        #self.ee.register(EVENT_INSTRUMENT, self.insertInstrument)

    #----------------------------------------------------------------------
    def login(self, userid, password, brokerid, mdAddress, tdAddress):
        """登陆"""
        pass
        #self.md.login(mdAddress, userid, password, brokerid)
        #self.td.login(tdAddress, userid, password, brokerid)

    #----------------------------------------------------------------------
    def subscribe(self, instrumentid, exchangeid):
        """订阅合约"""
        print 'subscribe============'
        #self.md.subscribe(instrumentid, exchangeid)

    #----------------------------------------------------------------------
    def getAccount(self):
        """查询账户"""
        print 'getAccount============'
        #self.td.getAccount()

    #----------------------------------------------------------------------
    def getInvestor(self):
        """查询投资者"""
        print 'getInvestor============'
        #self.td.getInvestor()

    #----------------------------------------------------------------------
    def getPosition(self):
        """查询持仓"""
        print 'getPosition============'
        #self.td.getPosition()

    #----------------------------------------------------------------------
    def getInstrument(self):
        """获取合约"""
        '''
        event = Event(type_=EVENT_LOG)
        log = u'查询合约信息'
        event.dict_['log'] = log
        self.ee.put(event)
        '''
        #self.td.getInstrument()

    #----------------------------------------------------------------------
    def sendOrder(self, instrumentid, exchangeid, price, pricetype, volume,
                  direction, offset):
        """发单"""
        print 'sendOrder============'
        #ref = self.td.sendOrder(instrumentid, exchangeid, price, pricetype, volume, direction, offset)
        #return str(ref)

    #----------------------------------------------------------------------
    def cancelOrder(self, instrumentid, exchangeid, orderref, frontid,
                    sessionid):
        """撤单"""
        print 'cancelOrder============'
        #self.td.cancelOrder(instrumentid, exchangeid, orderref, frontid, sessionid)

    #----------------------------------------------------------------------
    def getAccountPosition(self, event):
        """循环查询账户和持仓"""
        self.countGet = self.countGet + 1

        # 每5秒发一次查询
        if self.countGet > 5:
            self.countGet = 0  # 清空计数

            if self.lastGet == 'Account':
                self.getPosition()
                self.lastGet = 'Position'
            else:
                self.getAccount()
                self.lastGet = 'Account'

    #----------------------------------------------------------------------
    def initGet(self, event):
        """在交易服务器登录成功后,开始初始化查询"""
        # 打开设定文件setting.vn
        f = shelve.open('setting.vn')

        # 尝试读取设定字典,若该字典不存在,则发出查询请求
        try:
            d = f['instrument']

            # 如果本地保存的合约数据是今日的,则载入,否则发出查询请求
            today = date.today()
            if d['date'] == today:
                self.dictInstrument = d['dictInstrument']

                event = Event(type_=EVENT_LOG)
                log = u'合约信息读取完成'
                event.dict_['log'] = log
                self.ee.put(event)

                self.getInvestor()

                # 开始循环查询
                self.ee.register(EVENT_TIMER, self.getAccountPosition)
            else:
                self.getInstrument()
        except KeyError:
            self.getInstrument()

        f.close()

    #----------------------------------------------------------------------
    def insertInstrument(self, event):
        """插入合约对象"""
        print '=====其实什么都先不干======'
        '''
        data = event.dict_['data']
        last = event.dict_['last']

        self.dictInstrument[data['InstrumentID']] = data

        # 合约对象查询完成后,查询投资者信息并开始循环查询
        if last:
            # 将查询完成的合约信息保存到本地文件,今日登录可直接使用不再查询
            self.saveInstrument()

            event = Event(type_=EVENT_LOG)
            log = u'合约信息查询完成'
            event.dict_['log'] = log
            self.ee.put(event)

            self.getInvestor()

            # 开始循环查询
            self.ee.register(EVENT_TIMER, self.getAccountPosition)
        '''

    #----------------------------------------------------------------------
    def selectInstrument(self, instrumentid):
        """获取合约信息对象"""
        try:
            instrument = self.dictInstrument[instrumentid]
        except KeyError:
            instrument = None
        return instrument

    #----------------------------------------------------------------------
    def exit(self):
        """退出"""
        # 销毁API对象
        self.td = None
        self.md = None

        # 停止事件驱动引擎
        self.ee.stop()

    #----------------------------------------------------------------------
    def saveInstrument(self):
        """保存合约属性数据"""
        f = shelve.open('setting.vn')
        d = {}
        d['dictInstrument'] = self.dictInstrument
        d['date'] = date.today()
        f['instrument'] = d
        f.close()
        table = []
        eventRows = EventObjects[event].eventRows
        for key in sorted(eventRows.keys(),
                          lambda x, y: int(x[0]) - int(y[0])):
            table.append({'range': key, 'body': eventRows[key][-1]})
        ret.append({'name': event, 'table': table})
    return ret


encoded_player_data = [
    p('Cain', [o.MILITARY_ACADEMY, o.MERCENARY_COMPANY]),
    p('Oz', [o.MAGICAL_ACADEMY, o.ALCHEMIST, o.LIBRARY]),
    p('sirus', [o.TEMPLE, o.SHOP, o.HOUSE]),
    p('shazaman', [o.THIEVES_GUILD, o.CABAL, o.CULT])
]
engine = EventEngine(encoded_player_data, EventObjects)

events = []
for x in range(365):
    events.append(engine.next())

output = """
<html>
<head>
<title>High Level Campaign Rannick Event List</title>
</head>
<body>
<table border="1">
"""
for table in get_all_events_tables_for_printing():
    output += '<tr style="background-color: lightgray;"><td colspan="2">%s</td></tr>' % table[
Esempio n. 9
0
class MainEngine(object):
    """主引擎,负责对API的调度"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        self.ee = EventEngine()         # 创建事件驱动引擎

        #self.md = DemoMdApi(self.ee)    # 创建API接口
        #self.td = DemoTdApi(self.ee)

        self.ee.start()                 # 启动事件驱动引擎

        # 循环查询持仓和账户相关
        self.countGet = 0               # 查询延时计数
        self.lastGet = 'Account'        # 上次查询的性质
        #self.ee.register(EVENT_TDLOGIN, self.initGet)  # 登录成功后开始初始化查询

        # 合约储存相关
        self.dictInstrument = {}        # 字典(保存合约查询数据)
        #self.ee.register(EVENT_INSTRUMENT, self.insertInstrument)

    #----------------------------------------------------------------------
    def login(self, userid, password, brokerid, mdAddress, tdAddress):
        """登陆"""
        pass
        #self.md.login(mdAddress, userid, password, brokerid)
        #self.td.login(tdAddress, userid, password, brokerid)

    #----------------------------------------------------------------------
    def subscribe(self, instrumentid, exchangeid):
        """订阅合约"""
        print 'subscribe============'
        #self.md.subscribe(instrumentid, exchangeid)

    #----------------------------------------------------------------------
    def getAccount(self):
        """查询账户"""
        print 'getAccount============'
        #self.td.getAccount()

    #----------------------------------------------------------------------
    def getInvestor(self):
        """查询投资者"""
        print 'getInvestor============'
        #self.td.getInvestor()

    #----------------------------------------------------------------------
    def getPosition(self):
        """查询持仓"""
        print 'getPosition============'
        #self.td.getPosition()

    #----------------------------------------------------------------------
    def getInstrument(self):
        """获取合约"""
        '''
        event = Event(type_=EVENT_LOG)
        log = u'查询合约信息'
        event.dict_['log'] = log
        self.ee.put(event)
        '''
        #self.td.getInstrument()

    #----------------------------------------------------------------------
    def sendOrder(self, instrumentid, exchangeid, price, pricetype, volume, direction, offset):
        """发单"""
        print 'sendOrder============'
        #ref = self.td.sendOrder(instrumentid, exchangeid, price, pricetype, volume, direction, offset)
        #return str(ref)

    #----------------------------------------------------------------------
    def cancelOrder(self, instrumentid, exchangeid, orderref, frontid, sessionid):
        """撤单"""
        print 'cancelOrder============'
        #self.td.cancelOrder(instrumentid, exchangeid, orderref, frontid, sessionid)

    #----------------------------------------------------------------------
    def getAccountPosition(self, event):
        """循环查询账户和持仓"""
        self.countGet = self.countGet + 1

        # 每5秒发一次查询
        if self.countGet > 5:
            self.countGet = 0   # 清空计数

            if self.lastGet == 'Account':
                self.getPosition()
                self.lastGet = 'Position'
            else:
                self.getAccount()
                self.lastGet = 'Account'

    #----------------------------------------------------------------------
    def initGet(self, event):
        """在交易服务器登录成功后,开始初始化查询"""
        # 打开设定文件setting.vn
        f = shelve.open('setting.vn')

        # 尝试读取设定字典,若该字典不存在,则发出查询请求
        try:
            d = f['instrument']

            # 如果本地保存的合约数据是今日的,则载入,否则发出查询请求
            today = date.today()
            if d['date'] == today:
                self.dictInstrument = d['dictInstrument']

                event = Event(type_=EVENT_LOG)
                log = u'合约信息读取完成'
                event.dict_['log'] = log
                self.ee.put(event)

                self.getInvestor()

                # 开始循环查询
                self.ee.register(EVENT_TIMER, self.getAccountPosition)
            else:
                self.getInstrument()
        except KeyError:
            self.getInstrument()

        f.close()

    #----------------------------------------------------------------------
    def insertInstrument(self, event):
        """插入合约对象"""
        print '=====其实什么都先不干======'
        '''
        data = event.dict_['data']
        last = event.dict_['last']

        self.dictInstrument[data['InstrumentID']] = data

        # 合约对象查询完成后,查询投资者信息并开始循环查询
        if last:
            # 将查询完成的合约信息保存到本地文件,今日登录可直接使用不再查询
            self.saveInstrument()

            event = Event(type_=EVENT_LOG)
            log = u'合约信息查询完成'
            event.dict_['log'] = log
            self.ee.put(event)

            self.getInvestor()

            # 开始循环查询
            self.ee.register(EVENT_TIMER, self.getAccountPosition)
        '''

    #----------------------------------------------------------------------
    def selectInstrument(self, instrumentid):
        """获取合约信息对象"""
        try:
            instrument = self.dictInstrument[instrumentid]
        except KeyError:
            instrument = None
        return instrument

    #----------------------------------------------------------------------
    def exit(self):
        """退出"""
        # 销毁API对象
        self.td = None
        self.md = None

        # 停止事件驱动引擎
        self.ee.stop()

    #----------------------------------------------------------------------
    def saveInstrument(self):
        """保存合约属性数据"""
        f = shelve.open('setting.vn')
        d = {}
        d['dictInstrument'] = self.dictInstrument
        d['date'] = date.today()
        f['instrument'] = d
        f.close()
Esempio n. 10
0
    for event in sorted(EventObjects.keys()):
        table=[]
        eventRows=EventObjects[event].eventRows
        for key in sorted(eventRows.keys(), lambda x,y:int(x[0]) - int(y[0])):
            table.append({'range':key,'body':eventRows[key][-1]})
        ret.append({'name':event,'table':table})
    return ret


encoded_player_data=[
    p('Cain',[o.MILITARY_ACADEMY,o.MERCENARY_COMPANY]),
    p('Oz',[o.MAGICAL_ACADEMY,o.ALCHEMIST,o.LIBRARY]),
    p('sirus',[o.TEMPLE,o.SHOP,o.HOUSE]),
    p('shazaman',[o.THIEVES_GUILD,o.CABAL,o.CULT])
]
engine = EventEngine(encoded_player_data,EventObjects);


events=[]
for x in range(365):
    events.append(engine.next());

output="""
<html>
<head>
<title>High Level Campaign Rannick Event List</title>
</head>
<body>
<table border="1">
"""
for table in get_all_events_tables_for_printing():