Administrator
2024-03-27 87103d9325be0601b6f33eab737fc541b56e9577
l2/l2_transaction_data_manager.py
@@ -95,6 +95,9 @@
    # 大卖单的卖单号->卖单信息映射
    __big_sell_order_info_dict = {}
    # 大单列表
    __big_sell_order_info_list_dict = {}
    # 最近的卖单, 格式{code:[卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)]}
    __latest_sell_order_dict = {}
@@ -110,6 +113,10 @@
            cls.__big_sell_order_ids_dict[code] = set()
        if code not in cls.__big_sell_order_info_dict:
            cls.__big_sell_order_info_dict[code] = {}
        if code not in cls.__big_sell_order_info_list_dict:
            cls.__big_sell_order_info_list_dict[code] = []
        for d in datas:
            cls.__latest_sell_order_info_list_dict[code].append(d)
            if code not in cls.__latest_sell_order_dict:
@@ -129,13 +136,14 @@
                        l2_log.info(code, hx_logger_l2_transaction_sell_order, f"{cls.__latest_sell_order_dict[code]}")
                        cls.__big_sell_order_ids_dict[code].add(info[0])
                        cls.__big_sell_order_info_dict[code][info[0]] = info
                        cls.__big_sell_order_info_list_dict[code].append(info)
                    cls.__latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])]
        latest_time = l2_huaxin_util.convert_time(datas[-1][3], with_ms=True)
        min_time = tool.trade_time_add_millionsecond(latest_time, -1000)
        min_time_int = int(min_time.replace(":", "").replace(".", ""))
        # 计算最近1s的大单成交
        total_datas = cls.__latest_sell_order_info_list_dict.get(code)
        total_big_sell_datas = cls.__big_sell_order_info_list_dict.get(code)
        start_index = 0
        total_sell_info = [0, None]  # 总资金,开始成交信息,结束成交信息
@@ -144,16 +152,18 @@
        # print("大卖单", big_sell_order_ids)
        big_sell_orders = []
        temp_sell_order_ids = set()
        for i in range(len(datas) - 1, -1, -1):
            d = datas[i]
            if d[7] != latest_sell_order_info[0]:
        # 统计已经结算出的大单
        print(f"总大单数量:{len(total_big_sell_datas)}")
        for i in range(len(total_big_sell_datas) - 1, -1, -1):
            bd = total_big_sell_datas[i]
            if bd[0] != latest_sell_order_info[0]:
                # 不是最近的成交且不是大单直接过滤
                if d[7] not in big_sell_order_ids:
                if bd[0] not in big_sell_order_ids:
                    continue
                else:
                    if d[7] not in temp_sell_order_ids:
                        big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(d[7]))
                        temp_sell_order_ids.add(d[7])
                    if bd[0] not in temp_sell_order_ids:
                        big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(bd[0]))
                        temp_sell_order_ids.add(bd[0])
            else:
                # 是最近的但不是大单需要过滤
                if latest_sell_order_info[1] * latest_sell_order_info[2] < 500000:
@@ -163,11 +173,18 @@
                        big_sell_orders.append(latest_sell_order_info)
                        temp_sell_order_ids.add(latest_sell_order_info[0])
            if min_time_int > int(l2_huaxin_util.convert_time(d[3], with_ms=True).replace(":", "").replace(".", "")):
            if min_time_int > int(
                    l2_huaxin_util.convert_time(bd[3][0], with_ms=True).replace(":", "").replace(".", "")):
                start_index = i
                break
            # 统计最近1s的大卖单数据
            total_sell_info[0] += int(d[1] * d[2])
            total_sell_info[0] += int(bd[1] * bd[2])
        # 统计最近的大单
        if latest_sell_order_info[1] * latest_sell_order_info[2] >= 500000:
            if latest_sell_order_info[0] not in temp_sell_order_ids:
                big_sell_orders.append(latest_sell_order_info)
                temp_sell_order_ids.add(latest_sell_order_info[0])
        big_sell_orders.reverse()
        total_sell_info[1] = big_sell_orders
        cls.__latest_sell_order_info_list_dict[code] = cls.__latest_sell_order_info_list_dict[code][start_index:]