Administrator
2024-11-07 93ec042ae730c8e4cad1562d7ee579941847397c
third_data/code_plate_key_manager.py
@@ -16,7 +16,7 @@
from third_data.third_blocks_manager import BlockMapManager, CodeThirdBlocksManager
from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager
from trade.order_statistic import DealAndDelegateWithBuyModeDataManager
from trade.radical_buy_data_manager import RedicalBuyDataManager
from trade.radical_buy_data_manager import RadicalBuyDataManager
from utils import global_util, tool, buy_condition_util
from log_module import log, async_log_util
from db import redis_manager_delegate as redis_manager
@@ -1176,7 +1176,12 @@
            blocks -= constant.KPL_INVALID_BLOCKS
            # 过滤
            blocks = BlockMapManager().filter_blocks(blocks)
            temp_dict[code] = (kpl_util.get_high_level_count(d[4]), blocks)
            # 开1剔除4板以上的
            high_level = kpl_util.get_high_level_count(d[4])
            if high_level >= 4:
                continue
            temp_dict[code] = (high_level, blocks)
        kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict
    @classmethod
@@ -1264,7 +1269,6 @@
            if _code in exclude_codes:
                continue
            blocks = LimitUpDataConstant.get_blocks_with_history(_code)
            blocks = BlockMapManager().filter_blocks(blocks)
            if _code == code:
                # 获取当前代码涨停时间
                limit_up_time = int(k[5])
@@ -1313,7 +1317,7 @@
        # 9:45点之前涨停的才能买入
        # 获取当前代码的涨停时间
        limit_up_timestamp = cls.__get_limit_up_timestamp(code)
        if int(tool.timestamp_format(limit_up_timestamp, "%H%M%S")) > 94500:
        if tool.get_now_time_as_int() > 100000:
            return False, "超过生效时间"
        # 根据板块聚合数据
        open_limit_up_block_codes_dict = {}
@@ -1333,12 +1337,26 @@
        current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes,
                                                                           limit_up_time=limit_up_timestamp)
        exclude_codes = set()
        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):
        # 是否为强势二板开1:该代码所有的慨念必须都为二板开1且开1的只能有他自己
        is_strong_2_level = count == 1 and \
                            kpl_data_constant.open_limit_up_code_dict_for_radical_buy[open_limit_up_block_codes[0]][
                                0] == 2
        if is_strong_2_level:
            _code = open_limit_up_block_codes[0]
            blocks = LimitUpDataConstant.get_blocks_with_history(_code)
            if blocks:
                # 所有的慨念的开1代码必须只有他自己
                for b in blocks:
                    temp_codes = open_limit_up_block_codes_dict.get(b)
                    if temp_codes and len(temp_codes) > 1:
                        is_strong_2_level = False
                        break
        if count >= 2 or is_strong_2_level:
            # 开始数量大于2个或者只有一个2板开1
            exclude_codes.clear()
        else:
            # 只有一个开1
            # 获取包含高位板的身位
            # ----获取历史身位----
            history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
@@ -1347,17 +1365,19 @@
                                                                               limit_up_time=limit_up_timestamp)
            if history_before_codes_info and current_before_codes_info and history_before_codes_info[0][0] == \
                    current_before_codes_info[0][0]:
                # 前排第一个元素无炸板
                # 排除第一个非开1数据
                exclude_codes = {history_before_codes_info[0][0]}
            else:
                return False, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}"
        # 获取主板的身位
        # 获取主板的身位(已经排除了开1的代码)
        history_index, history_before_codes_info = cls.__get_history_index(code, block,
                                                                           yesterday_limit_up_codes,
                                                                           exclude_codes=exclude_codes)
        # 过滤不正的原因
        history_index, history_before_codes_info = cls.__filter_before_codes(block, history_index, history_before_codes_info, yesterday_limit_up_codes)
        history_index, history_before_codes_info = cls.__filter_before_codes(block, history_index,
                                                                             history_before_codes_info,
                                                                             yesterday_limit_up_codes)
        # 买首板老大/老二
        # 首板老大不能买时可买老二
@@ -1365,8 +1385,8 @@
            return False, f"开1数量:{count},非开1首板身位不匹配:历史-{history_index + 1} 实时-{current_index + 1}"
        if history_index == 1:
            # 当前代码为老2,要判断老大是否可买
            if RedicalBuyDataManager.can_buy(history_before_codes_info[0][0],
                                             DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
            if RadicalBuyDataManager.is_code_can_buy(history_before_codes_info[0][0],
                                                     DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
                return False, f"开1数量:{count},前排代码可买:{history_before_codes_info[0]}"
            return True, f"开1数量:{count},前排代码不可买:{history_before_codes_info[0]},历史前排-{history_before_codes_info},开1代码-{open_limit_up_block_codes}"
        return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}, 前排代码-{current_before_codes_info}, 开1代码-{open_limit_up_block_codes}"
@@ -1436,13 +1456,17 @@
                               tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60:
            return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[0]})"
        history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
        history_before_codes = [x[0] for x in history_before_codes_info]
        # 包含高位板的整体排序
        all_history_index, all_history_before_codes_info = cls.__get_history_index(code, block, set())
        all_history_before_codes = [x[0] for x in all_history_before_codes_info]
        # 前两个代码是否有炸板
        dif_codes = set(history_before_codes[:2]) - set(current_before_codes[:2])
        dif_codes = set(all_history_before_codes[:2]) - set(current_before_codes[:2])
        if dif_codes:
            return False, f"前2代码有炸板:{dif_codes}"
        # 不计算前2的代码
        # 前排代码炸板不能>=2个
        dif_codes = set(all_history_before_codes) - set(current_before_codes)
        if len(dif_codes) >= 2:
            return False, f"板块前排有{len(dif_codes)}个炸板"
        exclude_codes = set()
        for x in current_before_codes_info:
@@ -1477,22 +1501,25 @@
                # 首板老2,判断前面的老大是否是属于不能买的范畴
                pre_code = history_before_codes_info[0][0]
                # pre_code不能买,才能买
                if RedicalBuyDataManager.can_buy(pre_code, DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
                if RadicalBuyDataManager.is_code_can_buy(pre_code,
                                                         DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]:
                    return False, f"前排代码可买:{pre_code}"
                # 距离前一个是否在10分钟内
                if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
                                       tool.timestamp_format(history_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60:
                    return False, f"距离上个不能买的代码涨停已过去10分钟({history_before_codes_info[0]})"
                # 前面一个代码不能买,前一个代码必须与前前个代码涨停时间相差15分钟内
                for i in range(len(all_history_before_codes_info) - 1, -1, -1):
                    if all_history_before_codes_info[i][0] == pre_code:
                        if tool.trade_time_sub(tool.timestamp_format(all_history_before_codes_info[i][1], '%H:%M:%S'),
                                               tool.timestamp_format(all_history_before_codes_info[i - 1][1],
                                                                     '%H:%M:%S')) >= 15 * 60:
                            return False, f"被顺位代码({pre_code}) 与上个代码涨停时间>=15分钟 ({all_history_before_codes_info[i]}##{all_history_before_codes_info[i - 1]})"
                        else:
                            return True, f"被顺位代码({pre_code}) 与上个代码涨停时间<15分钟 ({all_history_before_codes_info[i]}##{all_history_before_codes_info[i - 1]})"
                return False, f"没找到顺位代码({pre_code})的前排代码"
            else:
                # 距离上个代码涨停5分钟以内
                if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
                                       tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60:
                    return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[-1]})"
                # 代码为目标代码
                pass
        else:
            if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'),
                                   tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60:
                return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[-1]})"
            # 代码为目标代码
            pass
        return True, f"满足买入需求: 前排代码-{current_before_codes_info}"
    @classmethod