示例#1
0
    def parse_hkhq_ex(self, header, bodyrecv):
        yield 'msgtype_hkhq_ex'
        pos = 0
        hkhq_ex = msg_hkhq_ex()  # .frombuffer(bodyrecv)
        memmove(addressof(hkhq_ex), bodyrecv, sizeof(msg_hkhq_ex))
        pos += sizeof(msg_hkhq_ex)

        yield Struct2Str(hkhq_ex)
        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, hkhq_ex.NoMDEntries):
            info = msghkhqexitem()
            structsize = sizeof(msghkhqexitem)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            yield Struct2Str(info)

            hkhq_ex.itemlist.append(info)
        hkhq_ex.NoComplexEventTimes = buffer.readint()
        # yield hkhq_ex.NoComplexEventTimes
        for i in range(0, hkhq_ex.NoComplexEventTimes):
            info = msghkvcm()
            structsize = sizeof(msghkvcm)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            yield Struct2Str(info)

            hkhq_ex.vcm.append(info)
        pass
示例#2
0
    def parse_hqkz_ex(self,header, bodyrecv):

        pos = 0
        hqkz_ex = msghqkz_ex()  # .frombuffer(bodyrecv)
        memmove(addressof(hqkz_ex), bodyrecv, sizeof(msghqkz_ex))
        pos += sizeof(hqkz_ex)
        flag = 0
        if str(hqkz_ex.SecurityID).strip() == "300059":
            yield 'msgtype_hqkz_ex'
            flag = 1
            yield Struct2Str(hqkz_ex)
        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, hqkz_ex.NoMDEntries):
            info = msghqkzexitem()
            structsize = sizeof(msghqkzexitem)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            if flag :
                yield Struct2Str(info)
            for j in range(0,info.NoOrders):
                item = orderitem()
                structsize = sizeof(orderitem)
                structbuff = buffer.readbytes(structsize)
                memmove(addressof(item), structbuff, structsize)
                if flag:
                    yield Struct2Str(item)
                info.itemlist.append(item)
            hqkz_ex.itemlist.append(info)
示例#3
0
    def parse_gonggao(self, header, bodyrecv):
        yield 'msgtype_gonggao'
        pos = 0
        gonggao = msggonggao()  # .frombuffer(bodyrecv)
        memmove(addressof(gonggao), bodyrecv, sizeof(msggonggao))
        pos += sizeof(msggonggao)

        yield Struct2Str(gonggao)

        buffer = buffereader(bodyrecv[pos:])
        structbuff = buffer.readbytes(gonggao.RawDataLength)
        yield structbuff
        pass
示例#4
0
 def parsebody(self, header, bodyrecv):
     if header.cmd == CAM_LOGIN_RPLY:
         reader = buffereader(bodyrecv)
         print "CAM_LOGIN_RPLY:0x%x" % reader.readint()
     elif header.cmd == CAM_MARKET_RPLY:
         print "CAM_MARKET_RPLY:"
     elif header.cmd == CAM_IDLE_RPLY:
         print "CAM_IDLE_RPLY"
     elif header.cmd == CAM_HQKZ_RQST:
         print "CAM_HQKZ_RQST"
         self.parseHQKZ_RQST(header, bodyrecv)
     elif header.cmd == CAM_ZQDMINFO_RQST:
         # print "CAM_ZQDMINFO_RQST"
         self.parseZQDMINFO_RQST(header, bodyrecv)
     else:
         print "unknown pack:0x%x" % header.cmd
示例#5
0
    def parse_stock_status(self, header, bodyrecv):
        yield 'msgtype_stock_status'
        pos = 0
        stockstatus = msgstockstatus()  # .frombuffer(bodyrecv)
        memmove(addressof(stockstatus), bodyrecv, sizeof(msgstockstatus))
        pos += sizeof(msgstockstatus)

        yield Struct2Str(stockstatus)
        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, stockstatus.NoSwitch):
            info = SecuritySwitch()
            structsize = sizeof(SecuritySwitch)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            yield Struct2Str(info)

            stockstatus.switchvec.append(info)
        pass
示例#6
0
    def parse_index_ex(self, header, bodyrecv):
        yield 'msgtype_index_ex'
        pos = 0
        index_ex = msg_index_ex()  # .frombuffer(bodyrecv)
        memmove(addressof(index_ex), bodyrecv, sizeof(msg_index_ex))
        pos += sizeof(msg_index_ex)

        yield Struct2Str(index_ex)
        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, index_ex.NoMDEntries):
            info = msgindexexitem()
            structsize = sizeof(msgindexexitem)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            yield Struct2Str(info)

            index_ex.itemlist.append(info)
        pass
示例#7
0
    def parse_panhou(self, header, bodyrecv):
        yield 'msgtype_panhou'
        pos = 0
        panhou = msgpanhou()  # .frombuffer(bodyrecv)
        memmove(addressof(panhou), bodyrecv, sizeof(msgpanhou))
        pos += sizeof(msgpanhou)

        yield Struct2Str(panhou)

        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, panhou.NoMDEntries):
            info = msgpanhouitem()
            structsize = sizeof(msgpanhouitem)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            yield Struct2Str(info)

            panhou.itemvec.append(info)
        pass
示例#8
0
    def parse_quote_count(self, header, bodyrecv):
        yield 'msgtype_quote_count'
        pos = 0
        quotecount = msgquotecount()  # .frombuffer(bodyrecv)
        memmove(addressof(quotecount), bodyrecv, sizeof(msgquotecount))
        pos += sizeof(msgquotecount)

        yield Struct2Str(quotecount)

        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, quotecount.NoMDStreamID):
            info = quotecountitem()
            structsize = sizeof(quotecountitem)
            structbuff = buffer.readbytes(structsize)
            memmove(addressof(info), structbuff, structsize)
            yield Struct2Str(info)

            quotecount.itemvec.append(info)
        pass
示例#9
0
    def parseHQKZ_RQST(self, header, bodyrecv):
        pos = 0
        camHqkzReq = CamHqkzReq.frombuffer(bodyrecv)
        print camHqkzReq.getstr()
        pos += camHqkzReq.size
        if camHqkzReq.flags & CAM_FLAGS_MARKET_FIRST_PACKET:
            if header.length < (CaMsgHeader.size + CamHqkzReq.size +
                                CamHqkzHeaderReq.size):
                print "header.length < ( CaMsgHeader.size +CamHqkzReq.size +CamHqkzHeaderReq.size )"
                return
            camHqkzHeaderReq = CamHqkzHeaderReq.frombuffer(bodyrecv[pos:])
            prn_obj(camHqkzHeaderReq)
            print camHqkzHeaderReq.getstr()
            pos += CamHqkzHeaderReq.size

        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, camHqkzReq.item_count):
            kztype = buffer.readbyte()
            structsize = buffer.readint()
            # print "kztype:",kztype
            if kztype == CAM_HQKZ_SSHQ:
                structbuff = buffer.readbytes(structsize)
                sshq = SSHQ.frombuffer(structbuff)
                if sshq.code[0:3] == 'SH6':
                    logging.debug(prn_obj(sshq))
                elif sshq.code[0:3] == 'SZ0':
                    logging.debug(prn_obj(sshq))
                elif sshq.code[0:3] == 'SZ3':
                    logging.debug(prn_obj(sshq))
            elif kztype == CAM_HQKZ_BLOCKHQ:
                info = BLOCKHQ()
                structbuff = buffer.readbytes(structsize)
                memmove(addressof(info), structbuff, sizeof(BLOCKHQ))
                strstruct = PrintStuct(info)
                logging.debug(strstruct)
                pipe.multi()
                pipe.set('hq_' + info.code, strstruct)
                pipe.hset(info.code, 'last', info.last)
                pipe.hset(info.code, 'open', info.open)
                pipe.hset(info.code, 'high', info.high)
                pipe.hset(info.code, 'low', info.low)
                pipe.hset(info.code, 'total_volume', info.total_volume)
                pipe.hset(info.code, 'total_amount', info.total_amount)
                pipe.hset(info.code, 'pchTopStockCode', info.pchTopStockCode)
                pipe.hset(info.code, 'StockNum', info.StockNum)
                pipe.hset(info.code, 'UpNum', info.UpNum)
                pipe.hset(info.code, 'DownNum', info.DownNum)
                pipe.hset(info.code, 'StrongNum', info.StrongNum)
                pipe.hset(info.code, 'WeakNum', info.WeakNum)
                pipe.hset(info.code, 'ZGB', info.ZGB)
                pipe.hset(info.code, 'LTG', info.LTG)
                pipe.hset(info.code, 'LTSZ', info.LTSZ)
                pipe.hset(info.code, 'ZSZ', info.ZSZ)
                pipe.hset(info.code, 'date', info.date)
                pipe.hset(info.code, 'time', info.time)
                pipe.execute()
                # print sshq.getstr()
            # elif kztype == CAM_HQKZ_SSZS:
            # elif kztype == CAM_HQKZ_ORDER_QUEUE:
            # elif kztype == CAM_HQKZ_STEP_TRADE:
            # elif kztype == CAM_HQKZ_SSHQHZEXT:
            # elif kztype == CAM_HQKZ_HZZXJC:
            # elif kztype == CAM_HQKZ_MARKET_STATUS:
            # elif kztype == CAM_HQKZ_MARKET_STATIC_INFO:
            # elif kztype == CAM_HQKZ_SSHQ_OTC:
            # elif kztype == CAM_HQKZ_SSHQ_OTCZH:
            # elif kztype == CAM_HQKZ_SSHQ_SOZH:
            # elif kztype == CAM_HQKZ_SSHQ_SG:
            # elif kztype == CAM_HQKZ_SSHQEXT:
            elif kztype == CAM_HQKZ_XGSG:
                info = struct_xgsg()
                structbuff = buffer.readbytes(structsize)
                memmove(addressof(info), structbuff, sizeof(struct_xgsg))
                # logging.debug(PrintStuct(info))
            else:
                # print "kztype:",kztype
                structbuff = buffer.readbytes(structsize)
示例#10
0
    def parseZQDMINFO_RQST(self, header, bodyrecv):
        pos = 0
        camZqdmInfoReq = CamZqdmInfoReq.frombuffer(bodyrecv)
        # print "CamZqdmInfoReq:",camZqdmInfoReq.getstr()
        pos += camZqdmInfoReq.size
        if camZqdmInfoReq.flags & CAM_FLAGS_MARKET_FIRST_PACKET:
            if header.length < (CaMsgHeader.size + CamZqdmInfoReq.size +
                                CamZqdmInfoHeaderReq.size):
                print "header.length < ( CaMsgHeader.size +CamZqdmInfoReq.size +CamZqdmInfoHeaderReq.size )"
                return
            camZqdmInfoHeaderReq = CamZqdmInfoHeaderReq.frombuffer(
                bodyrecv[pos:])
            # print "camZqdmInfoHeaderReq:",camZqdmInfoHeaderReq.getstr()
            pos += CamZqdmInfoHeaderReq.size

        buffer = buffereader(bodyrecv[pos:])
        for i in range(0, camZqdmInfoReq.item_count):
            kztype = buffer.readbyte()
            structsize = buffer.readint()
            if kztype == CAM_ZQDM_INFO:
                info = Struct_ZQDMInfo()
                structbuff = buffer.readbytes(structsize)
                memmove(addressof(info), structbuff, sizeof(Struct_ZQDMInfo))
                # if info.code[0:3] == 'SH6':
                strstruct = PrintStuct(info)
                #     logging.debug(strstruct)
                # elif info.code[0:3] == 'SZ0':
                #     strstruct = PrintStuct(info)
                #     logging.debug(strstruct)
                # elif info.code[0:3] == 'SZ3':
                #     strstruct = PrintStuct(info)
                #     logging.debug(strstruct)
                if info.type == 15:
                    print strstruct

                pipe.multi()
                pipe.set('zqdminfo_' + info.code, strstruct)
                pipe.sadd('zqdmset', info.code)

                pipe.hset(info.code, 'code', info.code)
                pipe.hset(info.code, 'name', info.name)
                pipe.hset(info.code, 'pinyin_name', info.pinyin_name)
                pipe.hset(info.code, 'type', info.type)
                pipe.hset(info.code, 'volume_unit', info.volume_unit)
                pipe.hset(info.code, 'pre_close', info.pre_close)
                pipe.hset(info.code, 'high_limit', info.high_limit)
                pipe.hset(info.code, 'low_limit', info.low_limit)
                pipe.hset(info.code, 'price_digit', info.price_digit)
                pipe.hset(info.code, 'price_divide', info.price_divide)
                pipe.hset(info.code, 'intrest', info.intrest)
                pipe.hset(info.code, 'crd_flag', info.crd_flag)
                pipe.hset(info.code, 'pre_position', info.pre_position)
                pipe.hset(info.code, 'pre_settle_price', info.pre_settle_price)
                pipe.hset(info.code, 'ext_type', info.ext_type)
                #
                pipe.execute()
            elif kztype == CAM_MB_INFO:
                # print "GET GET GET GET GET GET GET GET GET GET GET GET GET GET GET GET GET"

                info = myMbInfo()
                structbuff = buffer.readbytes(structsize)
                memmove(addressof(info), structbuff, sizeof(myMbInfo))
                logging.debug(PrintStuct(info))
                # mbinfo = MBInfo.frombuffer(structbuff)
                # print mbinfo.getstr()
            else:
                print "kztype 2:", kztype, i, structsize
                structbuff = buffer.readbytes(structsize)