Administrator
2025-05-19 e355406604ed8a2c9576322b68546e5721e1c141
L2成交大单提取
2个文件已修改
25 ■■■■■ 已修改文件
huaxin_client/l2_client_test.py 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2_data_parser.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client_test.py
@@ -67,9 +67,10 @@
    def get_big_sell_orders(self):
        return self.__big_sell_orders
    def add_transaction_data_for_accurate(self, item):
    def add_transaction_data_for_accurate(self, item, big_order_money_threshold=299e4):
        """
        获取精确的买单信息
        @param big_order_money_threshold: 大单阈值
        @param data:
        @return:
        """
@@ -77,13 +78,14 @@
        def format_timestamp(timestamp):
            time_str = str(timestamp)
            return int(time_str[:5] if time_str[0] == '9' else time_str[:6])
        money = round(item[2] * item[3])
        volume = item[3]
        price = item[2]
        order_time = item[4]
        if item[0] not in self.__big_accurate_buy_order_dict:
            # (买单号, 量, 金额, 时间, 最新成交价格)
            self.__big_accurate_buy_order_dict[item[0]] = [item[0], 0, 0, order_time, price]
            # (买单号, 量, 金额, 时间, 最新成交价格, 开始成交时间, 开始成交价格)
            self.__big_accurate_buy_order_dict[item[0]] = [item[0], 0, 0, order_time, price, order_time, price]
        buy_order_info = self.__big_accurate_buy_order_dict[item[0]]
        buy_order_info[1] += volume
        buy_order_info[2] += money
@@ -94,7 +96,7 @@
            # 有可能是大单成交完成, 判断上个订单是否是大单
            last_buy_order = self.__big_accurate_buy_order_dict.get(self.__latest_buy_order[0])
            if last_buy_order[2] > 299e4:
            if last_buy_order[2] > big_order_money_threshold:
                self.big_accurate_buy_order_queue.put_nowait(last_buy_order)
            # 如果数据过多需要移除过长时间的小金额数据
@@ -115,8 +117,8 @@
        # 统计卖单
        if item[1] not in self.__big_accurate_sell_order_dict:
            # (卖单号, 量, 金额, 时间, 最新成交价格)
            self.__big_accurate_sell_order_dict[item[1]] = [item[1], 0, 0, order_time, price]
            # (卖单号, 量, 金额, 时间, 最新成交价格, 开始成交时间, 开始成交价格)
            self.__big_accurate_sell_order_dict[item[1]] = [item[1], 0, 0, order_time, price, order_time, price]
        sell_order_info = self.__big_accurate_sell_order_dict[item[1]]
        sell_order_info[1] += volume
        sell_order_info[2] += money
@@ -125,14 +127,15 @@
        if self.__latest_sell_order and self.__latest_sell_order[0] != item[1]:
            # 有可能是大单成交完成, 判断上个订单是否是大单
            last_sell_order = self.__big_accurate_sell_order_dict.get(self.__latest_sell_order[0])
            if last_sell_order[2] > 299e4:
            if last_sell_order[2] > big_order_money_threshold:
                self.big_accurate_sell_order_queue.put_nowait(last_sell_order)
            # 如果数据过多需要移除过长时间的小金额数据
            accurate_sell_count = len(self.__big_accurate_sell_order_dict.keys())
            if accurate_sell_count > 10000 and accurate_sell_count - self.__last_accurate_sell_count > 2000:
                # 超过1w条数据且新增2000条数据
                # 超过1w条数据就要移除30分钟之前的数据
                now_time_int = int(tool.trade_time_add_second(l2_huaxin_util.convert_time(order_time), -3600).replace(":", ""))
                now_time_int = int(
                    tool.trade_time_add_second(l2_huaxin_util.convert_time(order_time), -3600).replace(":", ""))
                try:
                    remove_order_nos = [x for x in self.__big_accurate_sell_order_dict if
                                        now_time_int > format_timestamp(
@@ -143,7 +146,7 @@
                finally:
                    self.__last_accurate_sell_count = len(self.__big_accurate_sell_order_dict.keys())
    def add_transaction_data(self, data):
    def add_transaction_data(self, data, big_order_money_threshold=299e4):
        item = (data["BuyNo"], data["SellNo"], data["TradePrice"], data["TradeVolume"], data["OrderTime"])
        # item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'],
        #         "TradeVolume": pTransaction['TradeVolume'],
@@ -157,7 +160,7 @@
        order_time = item[4]
        if self.accurate_buy:
            self.add_transaction_data_for_accurate(item)
            self.add_transaction_data_for_accurate(item, big_order_money_threshold=big_order_money_threshold)
        if not self.__latest_buy_order:
            # (买单号, 量, 金额, 时间, 最新成交价格)
l2_data_parser.py
@@ -124,7 +124,7 @@
            continue
        if code not in l2_data_manager_dict:
            l2_data_manager_dict[code] = L2TransactionDataManager(code, True)
        l2_data_manager_dict[code].add_transaction_data(item)
        l2_data_manager_dict[code].add_transaction_data(item, big_order_money_threshold=100e4)
        if index % 100 == 0:
            # 读取队列中的数据
            l2_data_manager: L2TransactionDataManager = l2_data_manager_dict[code]