Administrator
2024-04-19 0860be15f09be6a00b1795c17575e3b1d5f2193b
L撤完善
3个文件已修改
126 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 78 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_processor.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -846,7 +846,6 @@
        base_rate = constant.L_CANCEL_RATE
        if is_up:
            base_rate = constant.L_CANCEL_RATE_UP
        try:
            block_rate = 0
            if code in cls.__block_limit_up_count_dict:
@@ -858,13 +857,13 @@
                    block_rate = rates[count]
            deal_rate = 0
            if code in cls.__big_num_deal_rate_dict:
                temp_rate = cls.__big_num_deal_rate_dict[code]
                if temp_rate >= 1:
                    if temp_rate > 3:
                        temp_rate = 3
                    deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round(
                        (temp_rate * 5.25 - 3.75) / 100, 4)
            # if code in cls.__big_num_deal_rate_dict:
            #     temp_rate = cls.__big_num_deal_rate_dict[code]
            #     if temp_rate >= 1:
            #         if temp_rate > 3:
            #             temp_rate = 3
            #         deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round(
            #             (temp_rate * 5.25 - 3.75) / 100, 4)
            base_rate += block_rate
            base_rate += deal_rate
@@ -1342,64 +1341,15 @@
        # 重新计算成交位置临近大单撤单
        self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, real_place_order_index)
    def add_transaction_datas(self, code, transaction_datas):
        if not transaction_datas:
            return False, "成交数据为空"
        buyno_map = local_today_buyno_map.get(code)
        if not buyno_map:
            return False, "没找到买单字典"
        total_datas = local_today_datas.get(code)
        if not total_datas:
            return False, "L2数据为空"
        l_down_cancel_info = self.__cancel_watch_index_info_cache.get(code)
        if not l_down_cancel_info:
            return False, "L撤为空"
        l_down_indexes = l_down_cancel_info[2]
        for transaction_data in transaction_datas:
            buy_data = buyno_map.get(str(transaction_data[6]))
            if not buy_data:
                continue
            if buy_data["index"] not in l_down_indexes:
                continue
            # 统计数据
            orgin_deal_data = self.__l_down_latest_deal_info_dict.get(code)
            if not orgin_deal_data:
                orgin_deal_data = [0, None]
            time_str = l2_huaxin_util.convert_time(transaction_data[3])
            if orgin_deal_data[1] != time_str:
                orgin_deal_data[0] = transaction_data[2]
                orgin_deal_data[1] = time_str
            else:
                orgin_deal_data[0] += transaction_data[2]
            self.__l_down_latest_deal_info_dict[code] = orgin_deal_data
        # 计算成交比例
        total_l_down_not_deal_num = self.__total_l_down_not_deal_num_dict.get(code)
        if total_l_down_not_deal_num is None:
            return False, "L撤未成交统计为空"
        orgin_deal_data = self.__l_down_latest_deal_info_dict.get(code)
        if orgin_deal_data is None:
            return False, "L后暂时无成交"
        real_place_order_index_info = self.__real_place_order_index_dict.get(code)
        if real_place_order_index_info and real_place_order_index_info[1]:
            return False, "没获取到真实的下单位"
        threshold_rate = LCancelRateManager.get_fast_deal_cancel_rate(code)
        rate = orgin_deal_data[0] / (total_l_down_not_deal_num[0] * 100)
        if rate > threshold_rate:
            limit_up_price = float(gpcode_manager.get_limit_up_price(code))
            deal_money = limit_up_price * orgin_deal_data[0]
            if deal_money >= constant.L_CANCEL_FAST_DEAL_MIN_MONEY:
                return True, f"达到撤单比例:{rate}/{threshold_rate} 成交详情:{orgin_deal_data}/{total_l_down_not_deal_num}"
            else:
                return False, f"已达到撤单比例,未达到撤单金额:{deal_money}"
        else:
            return False, "尚未达到撤单比例"
    # 已经成交的索引
    def add_deal_index(self, code, index, buy_single_index):
        """
        L后囊括范围成交一笔重新囊括1笔
        @param code:
        @param index:
        @param buy_single_index:
        @return:
        """
        watch_indexes_info = self.__get_watch_indexes_cache(code)
        if not watch_indexes_info:
            return
l2/l2_transaction_data_processor.py
@@ -92,7 +92,8 @@
                        big_money_count += 1
                        DealOrderNoManager().add_orderno(code, f"{deal_info[0]}")
                    # L后是否有成交,如果有成交就需要除去当前笔数,然后重新囊括一笔
                    LCancelBigNumComputer().add_deal_index(code, data["index"], order_begin_pos.buy_single_index)
                    # 暂时不需要这种复杂的机制
                    # LCancelBigNumComputer().add_deal_index(code, data["index"], order_begin_pos.buy_single_index)
            use_time_list.append(("统计买单数据", time.time() - _start_time))
            _start_time = time.time()
trade/huaxin/huaxin_trade_server.py
@@ -470,29 +470,30 @@
                                                          sell_1_price, sell_1_volume // 100, average_rate)
            latest_3m_buy1_money_list = code_price_manager.Buy1PriceManager().get_latest_3m_buy1_money_list(code)
            # -----------------------------重新计算L撤后---------------------------
            # 暂时不更新,无意义
            # 如果时涨停状态
            if abs(float(limit_up_price) - float(buy_1_price)) < 0.001:
                # 是否处于下单状态
                state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code)
                if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or constant.TEST:
                    if latest_3m_buy1_money_list and tool.trade_time_sub(latest_3m_buy1_money_list[-1][0],
                                                                         latest_3m_buy1_money_list[0][0]) >= 2 * 60:
                        # 2分钟以内,标准差在10%以内
                        c_start_index = None
                        for i in range(len(latest_3m_buy1_money_list) - 1, -1, -1):
                            if tool.trade_time_sub(latest_3m_buy1_money_list[-1][0],
                                                   latest_3m_buy1_money_list[i][0]) >= 2 * 60:
                                c_start_index = i
                                break
                        if c_start_index is not None:
                            latest_3m_buy1_money_list = copy.deepcopy(latest_3m_buy1_money_list[c_start_index:])
                            latest_3m_buy1_money_list = [x[1] for x in latest_3m_buy1_money_list]
                            avg_val = numpy.mean(numpy.array(latest_3m_buy1_money_list))
                            max_val = max(latest_3m_buy1_money_list)
                            min_val = min(latest_3m_buy1_money_list)
                            if abs(max_val - avg_val) / avg_val < 0.1 and abs(min_val - avg_val) / avg_val < 0.1:
                                # 买1封单额平稳
                                LCancelBigNumComputer().re_compute_l_down_watch_indexes(code)
            # if abs(float(limit_up_price) - float(buy_1_price)) < 0.001:
            #     # 是否处于下单状态
            #     state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code)
            #     if state == trade_manager.TRADE_STATE_BUY_DELEGATED or state == trade_manager.TRADE_STATE_BUY_PLACE_ORDER or constant.TEST:
            #         if latest_3m_buy1_money_list and tool.trade_time_sub(latest_3m_buy1_money_list[-1][0],
            #                                                              latest_3m_buy1_money_list[0][0]) >= 2 * 60:
            #             # 2分钟以内,标准差在10%以内
            #             c_start_index = None
            #             for i in range(len(latest_3m_buy1_money_list) - 1, -1, -1):
            #                 if tool.trade_time_sub(latest_3m_buy1_money_list[-1][0],
            #                                        latest_3m_buy1_money_list[i][0]) >= 2 * 60:
            #                     c_start_index = i
            #                     break
            #             if c_start_index is not None:
            #                 latest_3m_buy1_money_list = copy.deepcopy(latest_3m_buy1_money_list[c_start_index:])
            #                 latest_3m_buy1_money_list = [x[1] for x in latest_3m_buy1_money_list]
            #                 avg_val = numpy.mean(numpy.array(latest_3m_buy1_money_list))
            #                 max_val = max(latest_3m_buy1_money_list)
            #                 min_val = min(latest_3m_buy1_money_list)
            #                 if abs(max_val - avg_val) / avg_val < 0.1 and abs(min_val - avg_val) / avg_val < 0.1:
            #                     # 买1封单额平稳
            #                     LCancelBigNumComputer().re_compute_l_down_watch_indexes(code)
            threading.Thread(target=lambda: update_kpl_jx_block(code, buy_1_price, limit_up_price), daemon=True).start()