Administrator
2024-07-16 c58c2d16db12419a0f27cd5df38f3468e6bb14c0
l2/l2_transaction_data_manager.py
@@ -123,6 +123,9 @@
    # 正在成交的订单
    __dealing_order_info_dict = {}
    # 正在成交的主动买的订单
    __dealing_active_buy_order_info_dict = {}
    # 最近成交的订单{"code":(订单号,是否成交完成)}
    __latest_deal_order_info_dict = {}
@@ -165,6 +168,15 @@
        return cls.__dealing_order_info_dict.get(code)
    @classmethod
    def get_dealing_active_order_info(cls, code):
        """
        获取正在主动成交的数据
        @param code:
        @return:[订单号,总股数,成交金额,成交开始时间,成交结束时间]
        """
        return cls.__dealing_active_buy_order_info_dict.get(code)
    @classmethod
    def statistic_big_buy_data(cls, code, datas, limit_up_price):
        """
        统计大单买
@@ -175,7 +187,7 @@
        big_buy_datas = []
        normal_buy_datas = []
        # 大单阈值
        threshold_big_money = l2_data_util.get_big_money_val(limit_up_price)
        threshold_big_money = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code))
        for data in datas:
            # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'],
            #                   data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],
@@ -184,25 +196,46 @@
            if code not in cls.__dealing_order_info_dict:
                # 数据格式[订单号,总股数,成交金额,成交开始时间,成交结束时间]
                cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3], data[3]]
            if cls.__dealing_order_info_dict[code][0] == data[6]:
                # 成交同一个订单号
                cls.__dealing_order_info_dict[code][1] += data[2]
                cls.__dealing_order_info_dict[code][2] += data[2] * data[1]
                cls.__dealing_order_info_dict[code][4] = data[3]
            else:
                # 保存上一条数据
                async_log_util.info(hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}")
                # 设置最近成交完成的一条数据
                deal_info = cls.__dealing_order_info_dict[code]
                cls.__latest_deal_order_info_dict[code] = deal_info
                # 是否为大买单
                if deal_info[2] >= threshold_big_money:
                    big_buy_datas.append(deal_info)
                if deal_info[2] >= 500000:
                    normal_buy_datas.append(deal_info)
                if cls.__dealing_order_info_dict[code][0] == data[6]:
                    # 成交同一个订单号
                    cls.__dealing_order_info_dict[code][1] += data[2]
                    cls.__dealing_order_info_dict[code][2] += data[2] * data[1]
                    cls.__dealing_order_info_dict[code][4] = data[3]
                else:
                    # 保存上一条数据
                    async_log_util.info(hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}")
                    # 设置最近成交完成的一条数据
                    deal_info = cls.__dealing_order_info_dict[code]
                    cls.__latest_deal_order_info_dict[code] = deal_info
                    # 是否为大买单
                    if deal_info[2] >= threshold_big_money:
                        big_buy_datas.append(deal_info)
                    if deal_info[2] >= 500000:
                        normal_buy_datas.append(deal_info)
                # 初始化本条数据
                cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3], data[3]]
                    # 初始化本条数据
                    cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3], data[3]]
            # 统计主动买(买单号大于卖单号)
            try:
                if data[6] > data[7]:
                    if code not in cls.__dealing_active_buy_order_info_dict:
                        # 数据格式[订单号,总股数,成交金额,成交开始时间,成交结束时间]
                        cls.__dealing_active_buy_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3],
                                                                          data[3]]
                    else:
                        if cls.__dealing_active_buy_order_info_dict[code][0] == data[6]:
                            # 成交同一个订单号
                            cls.__dealing_active_buy_order_info_dict[code][1] += data[2]
                            cls.__dealing_active_buy_order_info_dict[code][2] += data[2] * data[1]
                            cls.__dealing_active_buy_order_info_dict[code][4] = data[3]
                        else:
                            # 初始化本条数据
                            cls.__dealing_active_buy_order_info_dict[code] = [data[6], data[2], data[2] * data[1],
                                                                              data[3], data[3]]
            except:
                pass
        return big_buy_datas, normal_buy_datas