Administrator
2024-08-30 2bf118d6e0bea591a278d0460b7d2839d8178358
量化特征修复
2个文件已修改
113 ■■■■■ 已修改文件
third_data/code_plate_key_manager.py 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/buy_strategy_util.py 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py
@@ -1075,8 +1075,10 @@
                continue
            buy1_money = huaxin_l1_data_manager.get_buy1_money(code)
            # 买1是否大于5000w
            if not buy1_money or buy1_money < 5e7:
                continue
            # TODO 测试
            if not constant.TEST:
                if not buy1_money or buy1_money < 5e7:
                    continue
            if not tool.is_can_buy_code(code):
                continue
            blocks = {d[5]}
@@ -1189,37 +1191,41 @@
        @return:
        """
        # 10点之前才能买入
        if int(tool.get_now_time_str().replace(":", "")) > 100000:
            return False, "超过生效时间"
        # TODO 测试
        if not constant.TEST:
            if int(tool.get_now_time_str().replace(":", "")) > 100000:
                return False, "超过生效时间"
        # 根据板块聚合数据
        open_limit_up_block_codes = {}
        open_limit_up_block_codes_dict = {}
        for c in kpl_data_constant.open_limit_up_code_dict_for_radical_buy:
            blocks = kpl_data_constant.open_limit_up_code_dict_for_radical_buy[c][1]
            for b in blocks:
                if b not in open_limit_up_block_codes:
                    open_limit_up_block_codes[b] = set()
                open_limit_up_block_codes[b].add(c)
        if block not in open_limit_up_block_codes:
                if b not in open_limit_up_block_codes_dict:
                    open_limit_up_block_codes_dict[b] = set()
                open_limit_up_block_codes_dict[b].add(c)
        if block not in open_limit_up_block_codes_dict:
            return False, "板块未开1"
        count = len(open_limit_up_block_codes.get(block))
        open_limit_up_block_codes = list(open_limit_up_block_codes_dict.get(block))
        count = len(open_limit_up_block_codes)
        # ----获取历史身位----
        history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes)
        # ----获取实时身位----
        current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes)
        if count >= 2:
            # 买老2
        if count >= 2 or (
                count == 1 and kpl_data_constant.open_limit_up_code_dict_for_radical_buy[open_limit_up_block_codes[0]][
            0] == 2):
            # 开始数量大于2个或者只有一个2板开1
            if history_index == 0 and current_index == 0:
                return True, f"开1数量:{count}"
            else:
                return False, f"开1数量:{count},身位不匹配:历史-{history_index} 实时-{current_index}"
                return False, f"开1数量:{count},非开1首板身位不匹配:历史-{history_index+1} 实时-{current_index+1}"
        else:
            # 买老3
            if history_index == 1 and current_index == 1:
                return True, f"开1数量:{count}"
            else:
                return False, f"开1数量:{count},身位不匹配:历史-{history_index} 实时-{current_index}"
                return False, f"开1数量:{count},非开1首板身位不匹配:历史-{history_index+1} 实时-{current_index+1}"
    @classmethod
    def __is_radical_buy_with_block_up(cls, code, block, yesterday_limit_up_codes):
@@ -1234,17 +1240,17 @@
        """
        # 获取当前的板块
        current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
        if len(current_before_codes_info) < 2:
            return False, f"前排代码小于2个"
        if current_before_codes_info[0][1] >= kpl_block_util.open_limit_up_time_range[1]:
            return False, f"有开1"
        if current_index != 2:
            return False, f"只能买老3,当前身位-{current_index + 1}"
        history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
        if history_index != current_index or len(current_before_codes_info) != len(history_before_codes_info):
            return False, f"前排代码有炸板"
        if len(current_before_codes_info) < 2:
            return False, f"前排代码小于2个"
        # 老大,老二必须相隔5分钟内
        if current_before_codes_info[0][1] >= kpl_block_util.open_limit_up_time_range[1]:
            return False, f"有开1"
        # 老大,老二必须相隔5分钟内
        if current_before_codes_info[1][1] - current_before_codes_info[0][1] < 5 * 60:
            # 获取当前代码的涨停时间
            limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
@@ -1272,6 +1278,7 @@
        keys_, k1_, k11_, k2_, k3_, k4_ = cls.__TargetCodePlateKeyManager.get_plate_keys(code, contains_today=False)
        match_blocks = open_limit_up_blocks & keys_
        can_buy_blocks = set()
        fmsges = []
        msges = []
        for b in match_blocks:
            # 判断板块是否该激进买
@@ -1279,8 +1286,7 @@
            if result[0]:
                can_buy_blocks.add(b)
            msges.append(f"【{b}】:{result}")
        if can_buy_blocks:
            return can_buy_blocks, "开1满足条件:" + ",".join(msges)
        fmsges.append("开1判断##" + ",".join(msges))
        if not can_buy_blocks:
            msges.clear()
            for b in match_blocks:
@@ -1289,7 +1295,8 @@
                if result[0]:
                    can_buy_blocks.add(b)
                msges.append(f"【{b}】:{result}")
        return can_buy_blocks, "开1不满足条件,板块快速启动:" + ",".join(msges)
            fmsges.append("板块快速启动判断##" + ",".join(msges))
        return can_buy_blocks, " **** ".join(fmsges)
if __name__ == "__main__":
utils/buy_strategy_util.py
@@ -199,18 +199,33 @@
    @param end_index:
    @return:(是否是量化, 下次可以下单时间)
    """
    THRESHOLD_BUY_COUNT = 20
    if end_index - start_index + 1 < THRESHOLD_BUY_COUNT:
        # 总数小于阈值
        return False, None
    # 阈值的取值范围
    THRESHOLD_MONEY_RANGE = 1e5, 3e5
    today_volume = code_volumn_manager.get_today_volumn_cache(code)
    histry_volumn = code_volumn_manager.get_histry_volumn(code)
    if not today_volume or not histry_volumn:
        return False, "尚未获取到量"
    threshhold_volume = (histry_volumn[0][0] - today_volume) // 6 // 100
    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
    threshhold_volumes_range = int(THRESHOLD_MONEY_RANGE[0] / limit_up_price), int(
        THRESHOLD_MONEY_RANGE[1] / limit_up_price)
    if threshhold_volume < threshhold_volumes_range[0]:
        threshhold_volume = threshhold_volumes_range[0]
    if threshhold_volume > threshhold_volumes_range[1]:
        threshhold_volume = threshhold_volumes_range[1]
    total_datas = l2_data_util.local_today_datas.get(code)
    time_as_ms = tool.trade_time_sub_with_ms(
        L2DataUtil.get_time_with_ms(total_datas[end_index]["val"]),
        L2DataUtil.get_time_with_ms(total_datas[start_index]["val"]))
    if time_as_ms > (10 if tool.is_sz_code(code) else 100):
        return False, "非量化"
    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
    buy_count = 0
    total_buy_nums = 0
    min_num = int(5000 / limit_up_price)
    trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
    if trade_index is None:
        trade_index = 0
    # 获取成交进度位
    for i in range(start_index, end_index + 1):
        val = total_datas[i]["val"]
@@ -218,25 +233,20 @@
            continue
        if val["num"] < min_num:
            continue
        buy_count += 1
        if buy_count > THRESHOLD_BUY_COUNT:
        total_buy_nums += val["num"]
        if total_buy_nums > threshhold_volume:
            break
    if buy_count > THRESHOLD_BUY_COUNT:
    if total_buy_nums > threshhold_volume:
        # 判断是否为量化
        time_as_ms = tool.trade_time_sub_with_ms(
            L2DataUtil.get_time_with_ms(total_datas[end_index]["val"]),
            L2DataUtil.get_time_with_ms(total_datas[start_index]["val"]))
        if time_as_ms <= 10 if tool.is_sz_code(code) else 100:
            # 深证10ms内,上证100ms内就判定为量化
            HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code)
            next_buy_time = time.time() + buy_condition_util.get_cancel_and_buy_space_time(
                code) / 1000
            # 如果是首次下单,增加一次下单次数
            place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
            if place_order_count == 0:
                trade_data_manager.PlaceOrderCountManager().place_order(code)
            return True, next_buy_time, f"执行位批次数据量({buy_count})大于{THRESHOLD_BUY_COUNT}  {start_index}-{end_index}"
        return False, None
        # 深证10ms内,上证100ms内就判定为量化
        HuaXinSellOrderStatisticManager.clear_latest_deal_volume(code)
        next_buy_time = time.time() + buy_condition_util.get_cancel_and_buy_space_time(
            code) / 1000
        # 如果是首次下单,增加一次下单次数
        place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
        if place_order_count == 0:
            trade_data_manager.PlaceOrderCountManager().place_order(code)
        return True, next_buy_time, f"执行位批次数据量({total_buy_nums})大于{threshhold_volume}  {start_index}-{end_index}"
    else:
        return False, None