Administrator
2024-08-27 a66b4a987444c655b5ab5f678dbfefc82b7785b2
third_data/code_plate_key_manager.py
@@ -8,11 +8,12 @@
import time
import constant
from code_attribute import code_nature_analyse
from db.redis_manager_delegate import RedisUtils
from third_data import kpl_block_util, kpl_api, kpl_util
from settings.trade_setting import MarketSituationManager
from utils import global_util, tool, buy_condition_util
from third_data.history_k_data_manager import HistoryKDataManager
from third_data.history_k_data_util import HistoryKDatasUtils
from utils import global_util, tool, buy_condition_util, init_data_util
from log_module import log, async_log_util
from db import redis_manager_delegate as redis_manager
@@ -20,8 +21,10 @@
from third_data.kpl_util import KPLPlatManager
from trade import trade_manager, l2_trade_util, trade_constant
# 代码精选板块管理
from utils.kpl_data_db_util import KPLLimitUpDataUtil
class KPLCodeJXBlockManager:
    __db = 3
    __redisManager = redis_manager.RedisManager(3)
@@ -93,7 +96,7 @@
            # logger_kpl_block_can_buy.info(f"准备更新精选板块:{code}-{buy_1_price}-{limit_up_price}")
            if limit_up_price and buy_1_price:
                # 处理买1,卖1信息
                pre_close_price = round(float(limit_up_price) / 1.1, 2)
                pre_close_price = round(float(limit_up_price) / tool.get_limit_up_rate(code), 2)
                # 如果涨幅大于7%就读取板块
                price_rate = (buy_1_price - pre_close_price) / pre_close_price
                if price_rate > 0.07:
@@ -473,6 +476,30 @@
            blocks = set()
        return reasons | blocks
    __history_blocks_dict_cache = {}
    def get_history_blocks(self, code):
        """
        获取180天的历史涨停原因
        @param code:
        @return:
        """
        if code in self.__history_blocks_dict_cache:
            return self.__history_blocks_dict_cache.get(code)
        try:
            kpl_results = KPLLimitUpDataUtil.get_latest_block_infos(code=code)
            keys = set()
            if kpl_results:
                keys |= set([x[2] for x in kpl_results])
            for r in kpl_results:
                if r[3]:
                    keys |= set(r[3].split("、"))
            self.__history_blocks_dict_cache[code] = keys
            return keys
        except:
            pass
        return set()
# 目标代码板块关键词管理
class TargetCodePlateKeyManager:
@@ -486,7 +513,7 @@
    # 返回key集合(排除无效板块),今日涨停原因,今日历史涨停原因,历史涨停原因,二级,精选板块
    def get_plate_keys(self, code):
        """
        获取代码的板块
        获取代码的板块: (180天的涨停原因+推荐原因)+今日涨停原因+今日涨停推荐原因+今日推荐原因
        @param code:
        @return: (板块关键词集合,今日涨停原因+涨停推荐原因,今日历史涨停原因,历史涨停原因,精选板块)
        """
@@ -501,10 +528,13 @@
        k2 = self.__CodesPlateKeysManager.get_history_limit_up_reason_cache(code)
        if k2 is None:
            k2 = set()
        k3 = set()
        industry = global_util.code_industry_map.get(code)
        if industry:
            k3 = {industry}
        k3 = self.__CodesPlateKeysManager.get_history_blocks(code)
        if k3:
            keys |= k3
        # industry = global_util.code_industry_map.get(code)
        # if industry:
        #     k3 = {industry}
        k4 = set()
        jingxuan_block_info = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code)
@@ -516,11 +546,10 @@
        if k1:
            # 涨停过
            keys |= k1
            keys = keys - set(constant.KPL_INVALID_BLOCKS)
        if not keys:
            # 获取不到涨停原因
            keys |= k4
            keys = keys - set(constant.KPL_INVALID_BLOCKS)
        # 获取不到涨停原因
        keys |= k4
        keys = keys - set(constant.KPL_INVALID_BLOCKS)
        return keys, k1, k11, k2, k3, k4
@@ -597,7 +626,7 @@
        if not block_codes:
            # 高位板泛化板块中无板块
            if not high_level_block_codes.get(block):
                return False, True, f"{block}:板块无涨停", False, False
                return False, True, f"【{block}】:板块无涨停", False, False
        elif len(block_codes) == 1 and code in block_codes:
            if not high_level_block_codes.get(block):
                return False, True, f"{block}:板块只有当前代码涨停", False, False
@@ -747,7 +776,7 @@
        if not block_codes:
            # 高位板泛化板块中无板块
            if not high_level_block_codes.get(block):
                return False, True, f"{block}:板块无涨停", False, False, 0, 0, 0
                return False, True, f"【{block}】:板块无涨停", False, False, 0, 0, 0
        elif len(block_codes) == 1 and code in block_codes:
            if not high_level_block_codes.get(block):
                return False, True, f"{block}:板块只有当前代码涨停", False, False, 0, 0, 0
@@ -760,7 +789,7 @@
        is_strong_block = False
        # 最多买老几
        RANKS = [5, 4, 3, 3, 3, 2, 2]
        RANKS = [6, 5, 4, 4, 3, 3, 2]
        RANK_TIMES = ["10:00:00", "10:30:00", "11:00:00", "11:30:00", "13:30:00", "14:00:00", "15:00:00"]
        now_time_str = tool.get_now_time_str()
        max_rank = 2
@@ -800,10 +829,12 @@
        is_active_buy = cls.__is_need_active_buy(code, block, current_shsz_rank, len(current_open_limit_up_codes))
        if current_shsz_rank < len(current_open_limit_up_codes) + max_rank:
            return True, False, f"【{block}】前排代码:{current_shsz_rank}", is_strong_block, is_active_buy, current_shsz_rank, len(
            return True, len(block_codes | {
                code}) <= 1, f"【{block}】前排代码:{current_shsz_rank}", is_strong_block, is_active_buy, current_shsz_rank, len(
                block_codes), len(block_codes_records)
        else:
            return False, False, f"【{block}】前排代码:{front_current_shsz_rank_codes} 超过{len(current_open_limit_up_codes) + max_rank}个", is_strong_block, is_active_buy, current_shsz_rank, len(
            return False, len(block_codes | {
                code}) <= 1, f"【{block}】前排代码:{front_current_shsz_rank_codes} 超过{len(current_open_limit_up_codes) + max_rank}个", is_strong_block, is_active_buy, current_shsz_rank, len(
                block_codes), len(block_codes_records)
    # 获取可以买的板块