Administrator
2024-08-28 bda4216d608a12db7132c97083c19ecdad48d78f
third_data/code_plate_key_manager.py
@@ -4,12 +4,13 @@
# 涨停代码关键词板块管理
import copy
import datetime
import json
import time
import constant
from db.redis_manager_delegate import RedisUtils
from third_data import kpl_block_util, kpl_api, kpl_util
from third_data import kpl_block_util, kpl_api, kpl_util, kpl_data_constant, huaxin_l1_data_manager
from settings.trade_setting import MarketSituationManager
from third_data.history_k_data_manager import HistoryKDataManager
from third_data.history_k_data_util import HistoryKDatasUtils
@@ -511,7 +512,7 @@
        return self.__redisManager.getRedis()
    # 返回key集合(排除无效板块),今日涨停原因,今日历史涨停原因,历史涨停原因,二级,精选板块
    def get_plate_keys(self, code):
    def get_plate_keys(self, code, contains_today = True):
        """
        获取代码的板块: (180天的涨停原因+推荐原因)+今日涨停原因+今日涨停推荐原因+今日推荐原因
        @param code:
@@ -543,11 +544,12 @@
        if jingxuan_block_info:
            jingxuan_blocks = jingxuan_block_info[0]
            k4 |= set(jingxuan_blocks)  # set([x[1] for x in jingxuan_blocks])
        if k1:
        if k1 and contains_today:
            # 涨停过
            keys |= k1
        # 获取不到涨停原因
        if contains_today:
        keys |= k4
        keys = keys - set(constant.KPL_INVALID_BLOCKS)
        return keys, k1, k11, k2, k3, k4
@@ -852,14 +854,18 @@
        # 加载涨停代码的目标板块
        def load_code_block():
            if limit_up_record_datas:
                # 获取今日9:30以前的时间
                time_str = datetime.datetime.now().strftime("%Y-%m-%d") + " 09:30:00"
                timestamp = time.mktime(time.strptime(time_str, '%Y-%m-%d %H:%M:%S'))
                for d in limit_up_record_datas:
                    if d[2] in constant.KPL_INVALID_BLOCKS and d[3] in before_blocks_dict:
                        code_limit_up_reasons_dict[d[3]] = {list(before_blocks_dict.get(d[3]))[0]}
                    else:
                        code_limit_up_reasons_dict[d[3]] = {d[2]}
                        # 不包含推荐原因
                        # if d[6]:
                        #     code_limit_up_reasons_dict[d[3]] |= set(d[6].split("、"))
                        # 开1才能包含推荐原因
                        if d[6] and int(d[5]) < timestamp:
                            code_limit_up_reasons_dict[d[3]] |= set(d[6].split("、"))
            return code_limit_up_reasons_dict
        if current_limit_up_datas is None:
@@ -1045,5 +1051,58 @@
            can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks)
    @classmethod
    def compute_open_limit_up_code_dict_for_radical_buy(cls, current_limit_up_datas):
        """
        计算开1的代码信息,不包含5板以上的
        @param current_limit_up_datas:
        @return:
        """
        time_str = datetime.datetime.now().strftime("%Y-%m-%d") + " 09:30:00"
        timestamp = time.mktime(time.strptime(time_str, '%Y-%m-%d %H:%M:%S'))
        temp_dict = {}
        for d in current_limit_up_datas:
            code = d[0]
            # d: (代码, 名称, 首次涨停时间, 最近涨停时间, 几板, 涨停原因, 板块, 实际流通, 主力净额,涨停原因代码,涨停原因代码数量)
            # 计算是否开1
            if int(d[2]) >= timestamp:
                continue
            # 剔除5板以上的
            if d[4].find("连板") > 0 and int(d[4].replace("连板","")) >=5:
                continue
            buy1_money = huaxin_l1_data_manager.get_buy1_money(code)
            if not buy1_money or buy1_money < 1e8:
                continue
            if not tool.is_can_buy_code(code):
                continue
            # 买1是否大于1亿
            blocks =  {d[5]}
            if d[6]:
                blocks |= set(d[6].split("、"))
            blocks-=constant.KPL_INVALID_BLOCKS
            temp_dict[code] = (kpl_util.get_high_level_count(d[4]), d[6])
        kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict
    @classmethod
    def is_radical_buy(cls, code):
        """
        是否是激进买
        @param code:
        @return:
        """
        # 获取今日开一的代码,剔除5板以上的
        current_limit_up_datas = kpl_data_constant.current_limit_up_datas
        # 计算
        # 获取代码的板块
        keys_, k1_, k11_, k2_, k3_, k4_ = cls.__TargetCodePlateKeyManager.get_plate_keys(code, contains_today=False)
        # 获取
if __name__ == "__main__":
    pass