Administrator
2024-10-11 331d8caf63a7119c8cf2d1faef28b5450b8f40f5
third_data/code_plate_key_manager.py
@@ -14,6 +14,7 @@
from settings.trade_setting import MarketSituationManager
from third_data.kpl_data_constant import LimitUpDataConstant
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 utils import global_util, tool, buy_condition_util
@@ -1128,7 +1129,7 @@
        kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict
    @classmethod
    def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None):
    def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, limit_up_time=None):
        """
        获取当前涨停身位
        @param code:
@@ -1141,6 +1142,7 @@
        current_index = 0
        block_codes_infos = []
        timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range
        if limit_up_time is None:
        limit_up_time = time.time()
        for k in LimitUpDataConstant.current_limit_up_datas:
            _code = k[0]
@@ -1250,9 +1252,7 @@
        """
        # 9:45点之前涨停的才能买入
        # 获取当前代码的涨停时间
        limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
        if not limit_up_timestamp:
            limit_up_timestamp = time.time()
        limit_up_timestamp = cls.__get_limit_up_timestamp(code)
        if int(tool.timestamp_format(limit_up_timestamp, "%H%M%S")) > 94500:
            return False, "超过生效时间"
        # 根据板块聚合数据
@@ -1270,7 +1270,8 @@
        # ----获取历史身位----
        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)
        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]][
@@ -1282,7 +1283,8 @@
            # ----获取历史身位----
            history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
            # ----获取实时身位----
            current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
            current_index, current_before_codes_info = cls.__get_current_index(code, block, set(),
                                                                               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]:
                # 前排第一个元素无炸板
@@ -1300,7 +1302,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 RedicalBuyDataManager.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]}"
        return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}"
@@ -1320,17 +1323,17 @@
        @param yesterday_limit_up_codes:
        @return:
        """
        # 获取当前代码的涨停时间
        limit_up_timestamp = cls.__get_limit_up_timestamp(code)
        # 获取当前的板块
        current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
        current_index, current_before_codes_info = cls.__get_current_index(code, block, set(),
                                                                           limit_up_time=limit_up_timestamp)
        current_before_codes = [x[0] for x in current_before_codes_info]
        if len(current_before_codes_info) < 2:
            return False, f"前排代码小于2个:{current_before_codes_info}"
        # 获取当前代码的涨停时间
        limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
        if not limit_up_timestamp:
            limit_up_timestamp = time.time()
        # 当前代码开1不能买
        if limit_up_timestamp < kpl_block_util.open_limit_up_time_range[1]:
@@ -1365,9 +1368,13 @@
            exclude_codes |= set(open_limit_up_code_dict.keys())
        history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes,
                                                                           exclude_codes)
        if history_index > 1:
            return False, f"排除前2,目标代码位于历史身位-{history_index + 1},前排代码:{history_before_codes_info}"
        elif history_index == 1:
        # 获取本板块买入代码的最大数量
        max_count = RadicalBuyBlockCodeCountManager().get_block_code_count(block)
        if history_index > max_count:
            return False, f"排除前2,目标代码位于历史身位-{history_index + 1},前排代码:{history_before_codes_info}, 板块最多可买{max_count}"
        if max_count == 1:
            if history_index == 1:
            # 首板老2,判断前面的老大是否是属于不能买的范畴
            pre_code = history_before_codes_info[0][0]
            # pre_code不能买,才能买
@@ -1382,13 +1389,25 @@
            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')) >= 5 * 60:
                return False, f"距离上个代码涨停已过去5分钟({current_before_codes_info[-1]})"
        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')) >= 5 * 60:
                return False, f"距离上个代码涨停已过去5分钟({current_before_codes_info[-1]})"
        return True, f"满足买入需求: 前排代码-{current_before_codes_info}"
    @classmethod
    def __is_re_limit_up(cls, code, block):
        """
        是否是炸板回封可买
        @param code:
        @param block:
        @return:
        """
        # 获取身位
        current_index, current_before_codes_info = cls.__get_current_index(code, block, set())
        current_index, current_before_codes_info = cls.__get_current_index(code, block, set(),
                                                                           limit_up_time=cls.__get_limit_up_timestamp(
                                                                               code))
        history_index, history_before_codes_info = cls.__get_history_index(code, block, set())
        if current_index != history_index:
            return False, f"有其他炸板"
@@ -1421,6 +1440,18 @@
        if diff:
            return False, f"板块炸板不止当前票:{diff}"
        return True, ""
    @classmethod
    def __get_limit_up_timestamp(cls, code):
        """
        获取代码的涨停时间,默认当前时间
        @param code:
        @return:
        """
        limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code)
        if not limit_up_timestamp:
            limit_up_timestamp = time.time()
        return limit_up_timestamp
    @classmethod
    def get_code_kpl_blocks(cls, code):
@@ -1490,15 +1521,18 @@
                result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes)
                if result[0]:
                    can_buy_blocks.add(b)
                msges.append(f"【{b}】:{result[1]}")
            fmsges.append("板块快速启动判断##" + ",".join(msges))
        if not can_buy_blocks:
            msges.clear()
            for b in keys_:
                result = cls.__is_re_limit_up(code, b)
                if result[0]:
                    can_buy_blocks.add(b)
                    msges.append(f"【{b}】:{result[1]}")
            fmsges.append("板块回封判断##" + ",".join(msges))
        return can_buy_blocks, " **** ".join(fmsges)