Example #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
Example #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
Example #3
0
 def get_today_ticks(self, code):
     """
     获取当天tick数据
     """
     self.ticks = Ticks()
     self.ticks.symbol = symbol_of(code)
     pages = 16
     page = 1
     while (page <= pages):
         url = self._gen_today_ticks_url(code, page)
         lines = self._request(url)
         pages = self.format_today_ticks(lines)
         page += 1
     return self.ticks
Example #4
0
 def get_today_ticks(self, code):
     """
     获取当天tick数据
     """
     self.ticks = Ticks()
     self.ticks.symbol = symbol_of(code)
     pages = 15
     page = 1
     while (page <= pages):
         try:
             url = self._gen_today_ticks_url(code, page)
             lines = self._request(url)
             self.format_today_ticks(lines)
             page += 1
         except IOError:
             break
     url = self._gen_today_ticks_url(code, 0)
     lines = self._request(url)
     pages = self.format_today_ticks(lines)
     return self.ticks
Example #5
0
 def _code_to_symbol(self, code):
     return symbol_of(code)