Esempio n. 1
0
    def format_realtime_quotes(self, realtime_quotes_data):
        result = dict()
        stocks_detail = ''.join(realtime_quotes_data)
        grep_result = self.realtime_quotes_format_zs.finditer(stocks_detail)
        for stock_match_object in grep_result:
            groups = stock_match_object.groups()
            price_A1 = eval(groups[0])
            price_A2 = eval(groups[1])
            perform = eval('[\'\'%s]' % (',\'0\'' * 26))
            g = eval(groups[2])
        grep_result = self.realtime_quotes_format.finditer(stocks_detail)
        for stock_match_object in grep_result:
            groups = stock_match_object.groups()
            price_A1 = eval(groups[0])
            price_A2 = eval(groups[1])
            perform = eval(groups[2])
            g = eval(groups[3])

        q = Quote()
        if 'zs' == price_A1[0][:2]:
            q.symbol = zs_symbol_of(price_A1[0][-6:])
        if 'cn' == price_A1[0][:2]:
            q.symbol = symbol_of(price_A1[0][-6:])
        q.code = code_from_symbol(q.symbol)
        q.name = price_A1[1].decode('utf-8')
        q.now = to_float(price_A1[2])
        q.open = to_float(price_A2[3])
        q.close = to_float(price_A2[1])
        q.high = to_float(price_A2[5])
        q.low = to_float(price_A2[7])
        q.buy = to_float(perform[12])
        q.sell = to_float(perform[10])
        q.volume = to_int(price_A2[8]) * 100
        q.turnover = to_float(price_A2[12]) * 10000
        q.bid1_volume = to_int(perform[13]) * 100
        q.bid1 = to_float(perform[12])
        q.bid2_volume = to_int(perform[15]) * 100
        q.bid2 = to_float(perform[14])
        q.bid3_volume = to_int(perform[17]) * 100
        q.bid3 = to_float(perform[16])
        q.bid4_volume = to_int(perform[19]) * 100
        q.bid4 = to_float(perform[18])
        q.bid5_volume = to_int(perform[21]) * 100
        q.bid5 = to_float(perform[20])
        q.ask1_volume = to_int(perform[11]) * 100
        q.ask1 = to_float(perform[10])
        q.ask2_volume = to_int(perform[9]) * 100
        q.ask2 = to_float(perform[8])
        q.ask3_volume = to_int(perform[7]) * 100
        q.ask3 = to_float(perform[6])
        q.ask4_volume = to_int(perform[5]) * 100
        q.ask4 = to_float(perform[4])
        q.ask5_volume = to_int(perform[3]) * 100
        q.ask5 = to_float(perform[2])
        t = '%s-%s-%s %s:%s:%s' % (g[0], g[1], g[2], g[3], g[4], g[5])
        q.time = date_time.str_to_time(t)

        result[q.code] = q

        return result
Esempio n. 2
0
    def format_realtime_quotes(self, realtime_quotes_data):
        result = dict()
        stocks_detail = ''.join(realtime_quotes_data)
        grep_result = self.realtime_quotes_format.finditer(stocks_detail)
        for stock_match_object in grep_result:
            q = Quote()
            groups = stock_match_object.groups()
            l = json.loads(groups[1])
            ask_bid = []
            for i in l:
                ab = re.split(r',', i)
                ask_bid.append(ab)

            s = re.split(r',', groups[0])
            q.symbol = symbol_of(s[1])
            q.code = code_from_em_symbol(s[1] + s[0])
            q.name = s[2]
            q.now = float(s[3])
            q.open = float(s[8])
            q.close = float(s[9])
            q.high = float(s[10])
            q.low = float(s[11])
            q.buy = float(ask_bid[5][0])
            q.sell = float(ask_bid[4][0])
            q.volume = int(s[17]) * 100
            q.turnover = float(s[19]) * 10000
            q.bid1_volume = int(ask_bid[5][1]) * 100
            q.bid1 = float(ask_bid[5][0])
            q.bid2_volume = int(ask_bid[6][1]) * 100
            q.bid2 = float(ask_bid[6][0])
            q.bid3_volume = int(ask_bid[7][1]) * 100
            q.bid3 = float(ask_bid[7][0])
            q.bid4_volume = int(ask_bid[8][1]) * 100
            q.bid4 = float(ask_bid[8][0])
            q.bid5_volume = int(ask_bid[9][1]) * 100
            q.bid5 = float(ask_bid[9][0])
            q.ask1_volume = int(ask_bid[4][1]) * 100
            q.ask1 = float(ask_bid[4][0])
            q.ask2_volume = int(ask_bid[3][1]) * 100
            q.ask2 = float(ask_bid[3][0])
            q.ask3_volume = int(ask_bid[2][1]) * 100
            q.ask3 = float(ask_bid[2][0])
            q.ask4_volume = int(ask_bid[1][1]) * 100
            q.ask4 = float(ask_bid[1][0])
            q.ask5_volume = int(ask_bid[0][1]) * 100
            q.ask5 = float(ask_bid[0][0])
            q.time = date_time.str_to_time(s[27])

            result[q.code] = q

        return result
Esempio n. 3
0
    def format_realtime_quotes(self, realtime_quotes_data):
        result = dict()
        stocks_detail = ''.join(realtime_quotes_data)
        #stock_detail_list = stocks_detail.split(';')
        grep_result = self.realtime_quotes_format.finditer(stocks_detail)
        for stock_match_object in grep_result:
            #i = 0
            #for x in stock_match_object.groups():
            #    print i
            #    print x.encode('utf-8')
            #    i += 1
            stock = stock_match_object.groups()
            q = Quote()
            q.symbol = stock[0]
            q.code = code_from_symbol(q.symbol)
            q.name = stock[2]
            q.open = float(stock[6])
            q.close = float(stock[5])
            q.now = float(stock[4])
            q.high = float(stock[34])
            q.low = float(stock[35])
            q.buy = float(stock[10])
            q.sell = float(stock[20])
            q.turnover = float(stock[38]) * 10000
            q.volume = int(stock[37]) * 100
            q.bid1_volume = int(stock[11]) * 100
            q.bid1 = float(stock[10])
            q.bid2_volume = int(stock[13]) * 100
            q.bid2 = float(stock[12])
            q.bid3_volume = int(stock[15]) * 100
            q.bid3 = float(stock[14])
            q.bid4_volume = int(stock[17]) * 100
            q.bid4 = float(stock[16])
            q.bid5_volume = int(stock[19]) * 100
            q.bid5 = float(stock[18])
            q.ask1_volume = int(stock[21]) * 100
            q.ask1 = float(stock[20])
            q.ask2_volume = int(stock[23]) * 100
            q.ask2 = float(stock[22])
            q.ask3_volume = int(stock[25]) * 100
            q.ask3 = float(stock[24])
            q.ask4_volume = int(stock[27]) * 100
            q.ask4 = float(stock[26])
            q.ask5_volume = int(stock[29]) * 100
            q.ask5 = float(stock[28])
            #q.date = date_time.str_to_date(stock[31])
            q.time = datetime.datetime.strptime(stock[31], '%Y%m%d%H%M%S')

            result[q.code] = q

        return result
Esempio n. 4
0
    def format_realtime_quotes(self, realtime_quotes_data):
        result = dict()
        stocks_detail = ''.join(realtime_quotes_data)
        grep_result = self.realtime_quotes_format.finditer(stocks_detail)
        for stock_match_object in grep_result:
            stock = stock_match_object.groups()
            q = Quote()
            q.symbol = stock[0]
            q.code = code_from_symbol(stock[0])
            q.name = stock[1]
            q.open = float(stock[2])
            q.close = float(stock[3])
            q.now = float(stock[4])
            q.high = float(stock[5])
            q.low = float(stock[6])
            q.buy = float(stock[7])
            q.sell = float(stock[8])
            q.volume = int(stock[9])
            q.turnover = float(stock[10])
            q.bid1_volume = int(stock[11])
            q.bid1 = float(stock[12])
            q.bid2_volume = int(stock[13])
            q.bid2 = float(stock[14])
            q.bid3_volume = int(stock[15])
            q.bid3 = float(stock[16])
            q.bid4_volume = int(stock[17])
            q.bid4 = float(stock[18])
            q.bid5_volume = int(stock[19])
            q.bid5 = float(stock[20])
            q.ask1_volume = int(stock[21])
            q.ask1 = float(stock[22])
            q.ask2_volume = int(stock[23])
            q.ask2 = float(stock[24])
            q.ask3_volume = int(stock[25])
            q.ask3 = float(stock[26])
            q.ask4_volume = int(stock[27])
            q.ask4 = float(stock[28])
            q.ask5_volume = int(stock[29])
            q.ask5 = float(stock[30])
            #q.date = date_time.str_to_date(stock[31])
            q.time = date_time.str_to_time(stock[31] + ' ' + stock[32])

            result[q.code] = q

        return result