Пример #1
0
    def parseResponse(self, body_buf):
        pos = 0
        (num, ) = struct.unpack("<H", body_buf[:2])
        pos += 2
        ticks = []
        last_price = 0
        for i in range(num):
            ### ?? get_time
            # \x80\x03 = 14:56

            hour, minute, pos = get_time(body_buf, pos)

            price_raw, pos = get_price(body_buf, pos)
            vol, pos = get_price(body_buf, pos)
            num, pos = get_price(body_buf, pos)
            buyorsell, pos = get_price(body_buf, pos)
            _, pos = get_price(body_buf, pos)

            last_price = last_price + price_raw

            tick = OrderedDict([
                ("time", "%02d:%02d" % (hour, minute)),
                ("price", float(last_price) / 100),
                ("vol", vol),
                ("num", num),
                ("buyorsell", buyorsell),
            ])

            ticks.append(tick)

        return ticks
    def parseResponse(self, body_buf):
        pos = 0
        (num, ) = struct.unpack("<H", body_buf[:2])
        pos += 2
        ticks = []

        # skip 4 bytes
        pos += 4

        last_price = 0
        for i in range(num):
            ### ?? get_time
            # \x80\x03 = 14:56

            hour, minute, pos = get_time(body_buf, pos)

            price_raw, pos = get_price(body_buf, pos)
            vol, pos = get_price(body_buf, pos)
            buyorsell, pos = get_price(body_buf, pos)
            _, pos = get_price(body_buf, pos)

            last_price = last_price + price_raw

            tick = OrderedDict(
                [
                    ("time", "%02d:%02d" % (hour, minute)),
                    ("price", float(last_price)/100),
                    ("vol", vol),
                    ("buyorsell", buyorsell),
                ]
            )

            ticks.append(tick)

        return ticks
Пример #3
0
    def parseResponse(self, body_buf):
        pos = 0

        (ret_count, ) = struct.unpack("<H", body_buf[0:2])
        pos += 2

        klines = []

        pre_diff_base = 0
        for i in range(ret_count):
            year, month, day, hour, minute, pos = get_datetime(
                self.category, body_buf, pos)

            price_open_diff, pos = get_price(body_buf, pos)
            price_close_diff, pos = get_price(body_buf, pos)

            price_high_diff, pos = get_price(body_buf, pos)
            price_low_diff, pos = get_price(body_buf, pos)

            (vol_raw, ) = struct.unpack("<I", body_buf[pos:pos + 4])
            vol = get_volume(vol_raw)

            pos += 4
            (dbvol_raw, ) = struct.unpack("<I", body_buf[pos:pos + 4])
            dbvol = get_volume(dbvol_raw)
            pos += 4

            (up_count, down_count) = struct.unpack("<HH",
                                                   body_buf[pos:pos + 4])
            pos += 4

            open = self._cal_price1000(price_open_diff, pre_diff_base)

            price_open_diff = price_open_diff + pre_diff_base

            close = self._cal_price1000(price_open_diff, price_close_diff)
            high = self._cal_price1000(price_open_diff, price_high_diff)
            low = self._cal_price1000(price_open_diff, price_low_diff)

            pre_diff_base = price_open_diff + price_close_diff

            #### 为了避免python处理浮点数的时候,浮点数运算不精确问题,这里引入了多余的代码

            kline = OrderedDict([
                ("open", open), ("close", close), ("high", high), ("low", low),
                ("vol", vol), ("amount", dbvol), ("year", year),
                ("month", month), ("day", day), ("hour", hour),
                ("minute", minute),
                ("datetime",
                 "%d-%02d-%02d %02d:%02d" % (year, month, day, hour, minute)),
                ("up_count", up_count), ("down_count", down_count)
            ])
            klines.append(kline)
        return klines
Пример #4
0
 def parseResponse(self, body_buf):
     pos = 0
     (num, ) = struct.unpack("<H", body_buf[:2])
     last_price = 0
     pos += 4
     prices = []
     for i in range(num):
         price_raw, pos = get_price(body_buf, pos)
         reversed1, pos = get_price(body_buf, pos)
         vol, pos = get_price(body_buf, pos)
         last_price = last_price + price_raw
         price = OrderedDict([("price", float(last_price) / 100),
                              ("vol", vol)])
         prices.append(price)
     return prices
Пример #5
0
 def parseResponse(self, body_buf):
     pos = 0
     (num, ) = struct.unpack("<H", body_buf[:2])
     last_price = 0
     pos += 4
     prices = []
     for i in range(num):
         price_raw, pos = get_price(body_buf, pos)
         reversed1, pos = get_price(body_buf, pos)
         vol, pos = get_price(body_buf, pos)
         last_price = last_price + price_raw
         price = OrderedDict(
             [
                 ("price", float(last_price)/100),
                 ("vol", vol)
             ]
         )
         prices.append(price)
     return prices
Пример #6
0
    def parseResponse(self, body_buf):
        pos = 0
        pos += 2  # skip b1 cb
        (num_stock, ) = struct.unpack("<H", body_buf[pos:pos + 2])
        pos += 2
        stocks = []

        for _ in range(num_stock):
            # print(body_buf[pos:])
            # b'\x00000001\x95\n\x87\x0e\x01\x01\x05\x00\xb1\xb9\xd6\r\xc7\x0e\x8d\xd7\x1a\x84\x04S\x9c<M\xb6\xc8\x0e\x97\x8e\x0c\x00\xae\n\x00\x01\xa0\x1e\x9e\xb3\x03A\x02\x84\xf9\x01\xa8|B\x03\x8c\xd6\x01\xb0lC\x04\xb7\xdb\x02\xac\x7fD\x05\xbb\xb0\x01\xbe\xa0\x01y\x08\x01GC\x04\x00\x00\x95\n'
            (market, code, active1) = struct.unpack("<B6sH",
                                                    body_buf[pos:pos + 9])
            pos += 9
            price, pos = get_price(body_buf, pos)
            last_close_diff, pos = get_price(body_buf, pos)
            open_diff, pos = get_price(body_buf, pos)
            high_diff, pos = get_price(body_buf, pos)
            low_diff, pos = get_price(body_buf, pos)
            # 不确定这里应该是用 get_price 跳过还是直接跳过4个bytes
            # if price == 0 and last_close_diff == 0 and open_diff == 0 and high_diff == 0 and low_diff == 0:
            #     # 这个股票当前应该无法获取信息, 这个时候,这个值一般是0 或者 100
            #     #reversed_bytes0 = body_buf[pos: pos + 1]
            #     #pos += 1
            #     # 感觉这里应该都可以用 get_price ,但是由于一次性改动影响比较大,所以暂时只针对没有行情的股票做改动
            #     reversed_bytes0, pos = get_price(body_buf, pos)
            # else:
            #     reversed_bytes0 = body_buf[pos: pos + 4]
            #     pos += 4
            reversed_bytes0, pos = get_price(body_buf, pos)
            # reversed_bytes0, pos = get_price(body_buf, pos)
            # 应该是 -price
            reversed_bytes1, pos = get_price(body_buf, pos)
            # print('reversed_bytes1:' + str(reversed_bytes1)  + ",price" + str(price))
            # assert (reversed_bytes1 == -price)
            vol, pos = get_price(body_buf, pos)
            cur_vol, pos = get_price(body_buf, pos)
            (amount_raw, ) = struct.unpack("<I", body_buf[pos:pos + 4])
            amount = get_volume(amount_raw)
            pos += 4
            s_vol, pos = get_price(body_buf, pos)
            b_vol, pos = get_price(body_buf, pos)
            reversed_bytes2, pos = get_price(body_buf, pos)
            reversed_bytes3, pos = get_price(body_buf, pos)

            bid1, pos = get_price(body_buf, pos)
            ask1, pos = get_price(body_buf, pos)
            bid_vol1, pos = get_price(body_buf, pos)
            ask_vol1, pos = get_price(body_buf, pos)

            bid2, pos = get_price(body_buf, pos)
            ask2, pos = get_price(body_buf, pos)
            bid_vol2, pos = get_price(body_buf, pos)
            ask_vol2, pos = get_price(body_buf, pos)

            bid3, pos = get_price(body_buf, pos)
            ask3, pos = get_price(body_buf, pos)
            bid_vol3, pos = get_price(body_buf, pos)
            ask_vol3, pos = get_price(body_buf, pos)

            bid4, pos = get_price(body_buf, pos)
            ask4, pos = get_price(body_buf, pos)
            bid_vol4, pos = get_price(body_buf, pos)
            ask_vol4, pos = get_price(body_buf, pos)

            bid5, pos = get_price(body_buf, pos)
            ask5, pos = get_price(body_buf, pos)
            bid_vol5, pos = get_price(body_buf, pos)
            ask_vol5, pos = get_price(body_buf, pos)

            # (reversed_bytes4, reversed_bytes5, reversed_bytes6,
            #  reversed_bytes7, reversed_bytes8, reversed_bytes9,
            #  active2) = struct.unpack("<HbbbbHH", body_buf[pos: pos + 10])
            # pos += 10

            reversed_bytes4 = struct.unpack("<H", body_buf[pos:pos + 2])
            pos += 2
            reversed_bytes5, pos = get_price(body_buf, pos)
            reversed_bytes6, pos = get_price(body_buf, pos)
            reversed_bytes7, pos = get_price(body_buf, pos)
            reversed_bytes8, pos = get_price(body_buf, pos)
            (reversed_bytes9, active2) = struct.unpack("<hH",
                                                       body_buf[pos:pos + 4])
            pos += 4

            one_stock = OrderedDict([
                ("market", market),
                ("code", code.decode("utf-8")),
                ("active1", active1),
                ("price", self._cal_price(price, 0)),
                ("last_close", self._cal_price(price, last_close_diff)),
                ("open", self._cal_price(price, open_diff)),
                ("high", self._cal_price(price, high_diff)),
                ("low", self._cal_price(price, low_diff)),
                ("reversed_bytes0", reversed_bytes0),
                ("reversed_bytes1", reversed_bytes1),
                ("vol", vol),
                ("cur_vol", cur_vol),
                ("amount", amount),
                ("s_vol", s_vol),
                ("b_vol", b_vol),
                ("reversed_bytes2", reversed_bytes2),
                ("reversed_bytes3", reversed_bytes3),
                ("bid1", self._cal_price(price, bid1)),
                ("ask1", self._cal_price(price, ask1)),
                ("bid_vol1", bid_vol1),
                ("ask_vol1", ask_vol1),
                ("bid2", self._cal_price(price, bid2)),
                ("ask2", self._cal_price(price, ask2)),
                ("bid_vol2", bid_vol2),
                ("ask_vol2", ask_vol2),
                ("bid3", self._cal_price(price, bid3)),
                ("ask3", self._cal_price(price, ask3)),
                ("bid_vol3", bid_vol3),
                ("ask_vol3", ask_vol3),
                ("bid4", self._cal_price(price, bid4)),
                ("ask4", self._cal_price(price, ask4)),
                ("bid_vol4", bid_vol4),
                ("ask_vol4", ask_vol4),
                ("bid5", self._cal_price(price, bid5)),
                ("ask5", self._cal_price(price, ask5)),
                ("bid_vol5", bid_vol5),
                ("ask_vol5", ask_vol5),
                ("reversed_bytes4", reversed_bytes4),
                ("reversed_bytes5", reversed_bytes5),
                ("reversed_bytes6", reversed_bytes6),
                ("reversed_bytes7", reversed_bytes7),
                ("reversed_bytes8", reversed_bytes8),
                ("reversed_bytes9", reversed_bytes9 / 100.0),  # 涨速
                ("active2", active2)
            ])
            stocks.append(one_stock)
        return stocks
Пример #7
0
    def parseResponse(self, body_buf):
        pos = 0
        pos += 2  # skip b1 cb
        (num_stock, ) = struct.unpack("<H", body_buf[pos:pos + 2])
        pos += 2
        stocks = []

        for _ in range(num_stock):
            # print(body_buf[pos:])
            # b'\x00000001\x95\n\x87\x0e\x01\x01\x05\x00\xb1\xb9\xd6\r\xc7\x0e\x8d\xd7\x1a\x84\x04S\x9c<M\xb6\xc8\x0e\x97\x8e\x0c\x00\xae\n\x00\x01\xa0\x1e\x9e\xb3\x03A\x02\x84\xf9\x01\xa8|B\x03\x8c\xd6\x01\xb0lC\x04\xb7\xdb\x02\xac\x7fD\x05\xbb\xb0\x01\xbe\xa0\x01y\x08\x01GC\x04\x00\x00\x95\n'
            (market, code, active1) = struct.unpack("<B6sH",
                                                    body_buf[pos:pos + 9])
            pos += 9
            price, pos = get_price(body_buf, pos)
            last_close_diff, pos = get_price(body_buf, pos)
            open_diff, pos = get_price(body_buf, pos)
            high_diff, pos = get_price(body_buf, pos)
            low_diff, pos = get_price(body_buf, pos)
            # 不确定这里应该是用 get_price 跳过还是直接跳过4个bytes
            reversed_bytes0 = body_buf[pos:pos + 4]
            pos += 4
            # reversed_bytes0, pos = get_price(body_buf, pos)
            # 应该是 -price
            reversed_bytes1, pos = get_price(body_buf, pos)
            assert (reversed_bytes1 == -price)
            vol, pos = get_price(body_buf, pos)
            cur_vol, pos = get_price(body_buf, pos)
            (amount_raw, ) = struct.unpack("<I", body_buf[pos:pos + 4])
            amount = get_volume(amount_raw)
            pos += 4
            s_vol, pos = get_price(body_buf, pos)
            b_vol, pos = get_price(body_buf, pos)
            reversed_bytes2, pos = get_price(body_buf, pos)
            reversed_bytes3, pos = get_price(body_buf, pos)

            bid1, pos = get_price(body_buf, pos)
            ask1, pos = get_price(body_buf, pos)
            bid_vol1, pos = get_price(body_buf, pos)
            ask_vol1, pos = get_price(body_buf, pos)

            bid2, pos = get_price(body_buf, pos)
            ask2, pos = get_price(body_buf, pos)
            bid_vol2, pos = get_price(body_buf, pos)
            ask_vol2, pos = get_price(body_buf, pos)

            bid3, pos = get_price(body_buf, pos)
            ask3, pos = get_price(body_buf, pos)
            bid_vol3, pos = get_price(body_buf, pos)
            ask_vol3, pos = get_price(body_buf, pos)

            bid4, pos = get_price(body_buf, pos)
            ask4, pos = get_price(body_buf, pos)
            bid_vol4, pos = get_price(body_buf, pos)
            ask_vol4, pos = get_price(body_buf, pos)

            bid5, pos = get_price(body_buf, pos)
            ask5, pos = get_price(body_buf, pos)
            bid_vol5, pos = get_price(body_buf, pos)
            ask_vol5, pos = get_price(body_buf, pos)

            (reversed_bytes4, reversed_bytes5, reversed_bytes6,
             reversed_bytes7, reversed_bytes8, reversed_bytes9,
             active2) = struct.unpack("<HbbbbHH", body_buf[pos:pos + 10])

            pos += 10

            # print(int.from_bytes(reversed_bytes0, byteorder='little'))

            one_stock = OrderedDict([
                ("market", market), ("code", code.decode("utf-8")),
                ("active1", active1), ("price", self._cal_price(price, 0)),
                ("last_close", self._cal_price(price, last_close_diff)),
                ("open", self._cal_price(price, open_diff)),
                ("high", self._cal_price(price, high_diff)),
                ("low", self._cal_price(price, low_diff)),
                ("reversed_bytes0", reversed_bytes0),
                ("reversed_bytes1", reversed_bytes1), ("vol", vol),
                ("cur_vol", cur_vol), ("amount", amount), ("s_vol", s_vol),
                ("b_vol", b_vol), ("reversed_bytes2", reversed_bytes2),
                ("reversed_bytes3", reversed_bytes3),
                ("bid1", self._cal_price(price, bid1)),
                ("ask1", self._cal_price(price, ask1)), ("bid_vol1", bid_vol1),
                ("ask_vol1", ask_vol1), ("bid2", self._cal_price(price, bid2)),
                ("ask2", self._cal_price(price, ask2)), ("bid_vol2", bid_vol2),
                ("ask_vol2", ask_vol2), ("bid3", self._cal_price(price, bid3)),
                ("ask3", self._cal_price(price, ask3)), ("bid_vol3", bid_vol3),
                ("ask_vol3", ask_vol3), ("bid4", self._cal_price(price, bid4)),
                ("ask4", self._cal_price(price, ask4)), ("bid_vol4", bid_vol4),
                ("ask_vol4", ask_vol4), ("bid5", self._cal_price(price, bid5)),
                ("ask5", self._cal_price(price, ask5)), ("bid_vol5", bid_vol5),
                ("ask_vol5", ask_vol5), ("reversed_bytes4", reversed_bytes4),
                ("reversed_bytes5", reversed_bytes5),
                ("reversed_bytes6", reversed_bytes6),
                ("reversed_bytes7", reversed_bytes7),
                ("reversed_bytes8", reversed_bytes8),
                ("reversed_bytes9", reversed_bytes9), ("active2", active2)
            ])
            stocks.append(one_stock)
        return stocks