Example #1
0
 def onRspOrderInsert(self, data, error, n, last):
     """发单错误(柜台)"""
     event = Event(type_=EventType.EVENT_LOG)
     log = u' 发单错误回报,错误代码:' + \
           unicode(error['ErrorID']) + u',' + u'错误信息:' + \
           error['ErrorMsg'].decode('gbk')
     event.dict_['log'] = log
     self.__event_engine.put(event)
Example #2
0
 def onErrRtnOrderAction(self, data, error):
     """撤单错误回报(交易所)"""
     event = Event(type_=EventType.EVENT_LOG)
     log = u'撤单错误回报,错误代码:' + \
           unicode(error['ErrorID']) + u',' + u'错误信息:' + \
           error['ErrorMsg'].decode('gbk')
     event.dict_['log'] = log
     self.__event_engine.put(event)
Example #3
0
 def onRspError(self, error, n, last):
     """错误回报"""
     event = Event(type_=EventType.EVENT_LOG)
     log = u'交易错误回报,错误代码:' + \
           unicode(error['ErrorID']) + u',' + u'错误信息:' + \
           error['ErrorMsg'].decode('gbk')
     event.dict_['log'] = log
     self.__event_engine.put(event)
    def onRspSettlementInfoConfirm(self, data, error, n, last):
        """确认结算信息回报"""
        event = Event(type_=EventType.EVENT_LOG)
        log = u"结算信息确认完成"
        event.dict_["log"] = log
        self.__event_engine.put(event)

        event = Event(type_=EventType.EVENT_TDLOGIN)
        self.__event_engine.put(event)
Example #5
0
    def onRspSettlementInfoConfirm(self, data, error, n, last):
        """确认结算信息回报"""
        event = Event(type_=EventType.EVENT_LOG)
        log = u'结算信息确认完成'
        event.dict_['log'] = log
        self.__event_engine.put(event)

        event = Event(type_=EventType.EVENT_TDLOGIN)
        self.__event_engine.put(event)
    def onRspQrySettlementInfo(self, data, error, n, last):
        """查询结算信息回报"""
        if last:
            event = Event(type_=EventType.EVENT_LOG)
            log = u"结算信息查询完成"
            event.dict_["log"] = log
            self.__event_engine.put(event)

            self.confirmSettlement()  # 查询完成后立即确认结算信息
Example #7
0
    def onRspQrySettlementInfo(self, data, error, n, last):
        """查询结算信息回报"""
        if last:
            event = Event(type_=EventType.EVENT_LOG)
            log = u'结算信息查询完成'
            event.dict_['log'] = log
            self.__event_engine.put(event)

            self.confirmSettlement()  # 查询完成后立即确认结算信息
    def onRtnTrade(self, data):
        """成交回报"""
        # 常规成交事件
        event1 = Event(type_=EventType.EVENT_TRADE)
        event1.dict_["data"] = data
        self.__event_engine.put(event1)

        # 特定合约成交事件
        event2 = Event(type_=(EventType.EVENT_TRADE_CONTRACT + data["InstrumentID"]))
        event2.dict_["data"] = data
        self.__event_engine.put(event2)
    def on_front_connected(self):
        """服务器连接"""
        event = Event(type_=EventType.EVENT_TYPE.EVENT_LOG)
        event.dict_["log"] = u"行情服务器连接成功"
        self.__event_engine.put(event)

        # 如果用户已经填入了用户名等等,则自动尝试连接
        if self.__user_id:
            req = {"UserID": self.__user_id, "Password": self.__password, "BrokerID": self.__broker_id}
            self.__req_id += 1
            self.reqUserLogin(req, self.__req_id)
    def onRspUserLogout(self, data, error, n, last):
        """登出回报"""
        event = Event(type_=EventType.EVENT_LOG)

        if error["ErrorID"] == 0:
            log = u"交易服务器登出成功"
        else:
            log = u"登出回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")

        event.dict_["log"] = log
        self.__event_engine.put(event)
 def onRspQryInvestor(self, data, error, n, last):
     """投资者查询回报"""
     if error["ErrorID"] == 0:
         event = Event(type_=EventType.EVENT_INVESTOR)
         event.dict_["data"] = data
         self.__event_engine.put(event)
     else:
         event = Event(type_=EventType.EVENT_LOG)
         log = u"合约投资者回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")
         event.dict_["log"] = log
         self.__event_engine.put(event)
    def on_rsp_user_login(self, data, error, n, last):
        """登陆回报"""
        event = Event(type_=EventType.EVENT_LOG)

        if error["ErrorID"] == 0:
            log = u"行情服务器登陆成功"
        else:
            log = u"登陆回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")

        event.dict_["log"] = log
        self.__event_engine.put(event)
 def onRspQryTradingAccount(self, data, error, n, last):
     """资金账户查询回报"""
     if error["ErrorID"] == 0:
         event = Event(type_=EventType.EVENT_ACCOUNT)
         event.dict_["data"] = data
         self.__event_engine.put(event)
     else:
         event = Event(type_=EventType.EVENT_LOG)
         log = u"账户查询回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")
         event.dict_["log"] = log
         self.__event_engine.put(event)
Example #14
0
    def on_rsp_user_login(self, data, error, n, last):
        """登陆回报"""
        event = Event(type_=EventType.EVENT_LOG)

        if error['ErrorID'] == 0:
            log = u'行情服务器登陆成功'
        else:
            log = u'登陆回报,错误代码:' + \
                  unicode(error['ErrorID']) + u',' + u'错误信息:' + \
                  error['ErrorMsg'].decode('gbk')

        event.dict_['log'] = log
        self.__event_engine.put(event)
    def on_rtn_depth_market_data(self, data):
        """行情推送"""
        # 行情推送收到后,同时触发常规行情事件,以及特定合约行情事件,用于满足不同类型的监听

        # 常规行情事件
        event1 = Event(type_=EventType.EVENT_MARKET_DATA)
        event1.dict_["data"] = data
        self.__event_engine.put(event1)

        # 特定合约行情事件
        event2 = Event(type_=(EventType.EVENT_MARKET_DATA_CONTRACT + data["InstrumentID"]))
        event2.dict_["data"] = data
        self.__event_engine.put(event2)
Example #16
0
    def onRspUserLogout(self, data, error, n, last):
        """登出回报"""
        event = Event(type_=EventType.EVENT_LOG)

        if error['ErrorID'] == 0:
            log = u'交易服务器登出成功'
        else:
            log = u'登出回报,错误代码:' + \
                  unicode(error['ErrorID']) + u',' + u'错误信息:' + \
                  error['ErrorMsg'].decode('gbk')

        event.dict_['log'] = log
        self.__event_engine.put(event)
Example #17
0
    def on_front_connected(self):
        """服务器连接"""
        event = Event(type_=EventType.EVENT_TYPE.EVENT_LOG)
        event.dict_['log'] = u'行情服务器连接成功'
        self.__event_engine.put(event)

        # 如果用户已经填入了用户名等等,则自动尝试连接
        if self.__user_id:
            req = {
                'UserID': self.__user_id,
                'Password': self.__password,
                'BrokerID': self.__broker_id
            }
            self.__req_id += 1
            self.reqUserLogin(req, self.__req_id)
Example #18
0
    def onRspUserLogin(self, data, error, n, last):
        """登陆回报"""
        event = Event(type_=EventType.EVENT_LOG)

        if error['ErrorID'] == 0:
            log = u'交易服务器登陆成功'
        else:
            log = u'登陆回报,错误代码:' + \
                  unicode(error['ErrorID']) + u',' + u'错误信息:' + \
                  error['ErrorMsg'].decode('gbk')

        event.dict_['log'] = log
        self.__event_engine.put(event)

        self.getSettlement()  # 登录完成后立即查询结算信息
    def onRtnOrder(self, data):
        """报单回报"""
        # 更新最大报单编号
        newref = data["OrderRef"]
        self.__order_ref = max(self.__order_ref, int(newref))

        # 常规报单事件
        event1 = Event(type_=EventType.EVENT_ORDER)
        event1.dict_["data"] = data
        self.__event_engine.put(event1)

        # 特定合约行情事件
        event2 = Event(type_=(EventType.EVENT_ORDER_REF + data["OrderRef"]))
        event2.dict_["data"] = data
        self.__event_engine.put(event2)
 def onRspQryInstrument(self, data, error, n, last):
     """
     合约查询回报
     由于该回报的推送速度极快,因此不适合全部存入队列中处理,
     选择先储存在一个本地字典中,全部收集完毕后再推送到队列中
     (由于耗时过长目前使用其他进程读取)
     """
     if error["ErrorID"] == 0:
         event = Event(type_=EventType.EVENT_INSTRUMENT)
         event.dict_["data"] = data
         event.dict_["last"] = last
         self.__event_engine.put(event)
     else:
         event = Event(type_=EventType.EVENT_LOG)
         log = u"合约投资者回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")
         event.dict_["log"] = log
         self.__event_engine.put(event)
Example #21
0
 def __next_bar(self):
     # try:
     #     bar = self._next_bar()
     # except StopIteration:
     #     pass
     # else:
     #     self.event_engine.put(Event(EventType.EVENT_BAR_ARRIVE, bar))
     #     return bar
     row = self.next_bar().next()
     self.event_engine.put(Event(type_=EventType.EVENT_BAR_ARRIVE, dict_=row))
Example #22
0
 def run(self):
     self.event_engine.start()
     gen = self.__barfeed.next_bar()
     try:
         while True:
             self.event_engine.put(
                 Event(EventType.EVENT_BAR_ARRIVE, gen.next()))
             self.event_engine.run()
     except StopIteration:
         self.on_finish()
Example #23
0
    def onRtnTrade(self, data):
        """成交回报"""
        # 常规成交事件
        event1 = Event(type_=EventType.EVENT_TRADE)
        event1.dict_['data'] = data
        self.__event_engine.put(event1)

        # 特定合约成交事件
        event2 = Event(type_=(EventType.EVENT_TRADE_CONTRACT +
                              data['InstrumentID']))
        event2.dict_['data'] = data
        self.__event_engine.put(event2)
Example #24
0
 def onRspQryTradingAccount(self, data, error, n, last):
     """资金账户查询回报"""
     if error['ErrorID'] == 0:
         event = Event(type_=EventType.EVENT_ACCOUNT)
         event.dict_['data'] = data
         self.__event_engine.put(event)
     else:
         event = Event(type_=EventType.EVENT_LOG)
         log = u'账户查询回报,错误代码:' + \
               unicode(error['ErrorID']) + u',' + u'错误信息:' + \
               error['ErrorMsg'].decode('gbk')
         event.dict_['log'] = log
         self.__event_engine.put(event)
Example #25
0
 def onRspQryInvestor(self, data, error, n, last):
     """投资者查询回报"""
     if error['ErrorID'] == 0:
         event = Event(type_=EventType.EVENT_INVESTOR)
         event.dict_['data'] = data
         self.__event_engine.put(event)
     else:
         event = Event(type_=EventType.EVENT_LOG)
         log = u'合约投资者回报,错误代码:' + \
               unicode(error['ErrorID']) + u',' + u'错误信息:' + \
               error['ErrorMsg'].decode('gbk')
         event.dict_['log'] = log
         self.__event_engine.put(event)
Example #26
0
    def on_rtn_depth_market_data(self, data):
        """行情推送"""
        # 行情推送收到后,同时触发常规行情事件,以及特定合约行情事件,用于满足不同类型的监听

        # 常规行情事件
        event1 = Event(type_=EventType.EVENT_MARKET_DATA)
        event1.dict_['data'] = data
        self.__event_engine.put(event1)

        # 特定合约行情事件
        event2 = Event(type_=(EventType.EVENT_MARKET_DATA_CONTRACT +
                              data['InstrumentID']))
        event2.dict_['data'] = data
        self.__event_engine.put(event2)
Example #27
0
    def onRtnOrder(self, data):
        """报单回报"""
        # 更新最大报单编号
        newref = data['OrderRef']
        self.__order_ref = max(self.__order_ref, int(newref))

        # 常规报单事件
        event1 = Event(type_=EventType.EVENT_ORDER)
        event1.dict_['data'] = data
        self.__event_engine.put(event1)

        # 特定合约行情事件
        event2 = Event(type_=(EventType.EVENT_ORDER_REF + data['OrderRef']))
        event2.dict_['data'] = data
        self.__event_engine.put(event2)
Example #28
0
 def onRspQryInstrument(self, data, error, n, last):
     """
     合约查询回报
     由于该回报的推送速度极快,因此不适合全部存入队列中处理,
     选择先储存在一个本地字典中,全部收集完毕后再推送到队列中
     (由于耗时过长目前使用其他进程读取)
     """
     if error['ErrorID'] == 0:
         event = Event(type_=EventType.EVENT_INSTRUMENT)
         event.dict_['data'] = data
         event.dict_['last'] = last
         self.__event_engine.put(event)
     else:
         event = Event(type_=EventType.EVENT_LOG)
         log = u'合约投资者回报,错误代码:' + \
               unicode(error['ErrorID']) + u',' + u'错误信息:' + \
               error['ErrorMsg'].decode('gbk')
         event.dict_['log'] = log
         self.__event_engine.put(event)
 def on_front_disconnected(self, n):
     """服务器断开"""
     event = Event(type_=EventType.EVENT_LOG)
     event.dict_["log"] = u"行情服务器连接断开"
     self.__event_engine.put(event)
 def onErrRtnOrderAction(self, data, error):
     """撤单错误回报(交易所)"""
     event = Event(type_=EventType.EVENT_LOG)
     log = u"撤单错误回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")
     event.dict_["log"] = log
     self.__event_engine.put(event)
 def onRspError(self, error, n, last):
     """错误回报"""
     event = Event(type_=EventType.EVENT_LOG)
     log = u"交易错误回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")
     event.dict_["log"] = log
     self.__event_engine.put(event)
Example #32
0
 def on_front_disconnected(self, n):
     """服务器断开"""
     event = Event(type_=EventType.EVENT_LOG)
     event.dict_['log'] = u'行情服务器连接断开'
     self.__event_engine.put(event)
 def onRspOrderInsert(self, data, error, n, last):
     """发单错误(柜台)"""
     event = Event(type_=EventType.EVENT_LOG)
     log = u" 发单错误回报,错误代码:" + unicode(error["ErrorID"]) + u"," + u"错误信息:" + error["ErrorMsg"].decode("gbk")
     event.dict_["log"] = log
     self.__event_engine.put(event)