Administrator
2023-11-24 d6b6be5eb2ae00a8ccf46bd7d53cd7d0c1e59c72
third_data/code_plate_key_manager.py
@@ -6,13 +6,14 @@
import json
import constant
from code_attribute.code_nature_analyse import HighIncreaseCodeManager
from db.redis_manager_delegate import RedisUtils
from third_data import kpl_block_util
from third_data import kpl_block_util, kpl_api
from utils import global_util, tool
from log_module import log
from log_module import log, async_log_util
from db import redis_manager_delegate as redis_manager
from log_module.log import logger_kpl_limit_up, logger_kpl_block_can_buy, logger_kpl_debug
from log_module.log import logger_kpl_limit_up, logger_kpl_block_can_buy
from third_data.kpl_util import KPLPlatManager
from trade import trade_manager, l2_trade_util
@@ -77,6 +78,25 @@
            return self.__code_by_blocks.get(code)
        else:
            return self.__code_blocks.get(code)
    # 从网络上加载精选板块
    def load_jx_blocks(self, 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)
            # 如果涨幅大于7%就读取板块
            price_rate = (buy_1_price - pre_close_price) / pre_close_price
            if price_rate > 0.07:
                if not self.get_jx_blocks_cache(code):
                    blocks = kpl_api.getCodeJingXuanBlocks(code)
                    self.save_jx_blocks(code, blocks)
                    async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块-{blocks}")
            elif price_rate > 0.03:
                # 添加备用板块
                if not self.get_jx_blocks_cache(code, by=True):
                    blocks = kpl_api.getCodeJingXuanBlocks(code)
                    self.save_jx_blocks(code, blocks, by=True)
                    async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(备用)-{blocks}")
# 开盘啦禁止交易板块管理
@@ -291,11 +311,9 @@
    @classmethod
    def is_in_top(cls, keys):
        reasons = cls.get_can_buy_key_set()
        log.logger_kpl_debug.debug("市场流入前5:{}", reasons)
        forbidden_plates = cls.__KPLPlateForbiddenManager.list_all_cache()
        reasons = reasons - forbidden_plates
        temp_set = keys & reasons
        log.logger_kpl_debug.debug("市场流入前5匹配结果:{}", temp_set)
        if temp_set:
            return True, temp_set
        else:
@@ -317,7 +335,6 @@
        self.__history_limit_up_reason_dict[code] = set(reasons)
        RedisUtils.setex(self.__get_redis(), f"kpl_his_limit_up_reason-{code}", tool.get_expire(),
                         json.dumps(list(reasons)))
        logger_kpl_debug.debug(f"设置历史涨停原因:{code}-{reasons}")
    # 如果返回值不为None表示已经加载过历史原因了
    def get_history_limit_up_reason(self, code):
@@ -450,26 +467,36 @@
        # msg_list.append(f"\n实时top10(涨停数量:{len(current_limit_up_datas)})")
        # msg_list.append(f"历史top20(涨停数量:{len(top_8_record)})")
        # 需要排除的老大的代码
        exclude_first_codes = HighIncreaseCodeManager().list_all()
        # 获取主板开1的代码
        open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas,
                                                                          code_limit_up_reason_dict)
        # 剔除高位板
        if open_limit_up_codes and yesterday_current_limit_up_codes:
            open_limit_up_codes -= yesterday_current_limit_up_codes
        # 获取主板实时身位,剔除高位板
        current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block,
                                                                                                current_limit_up_datas,
                                                                                                code_limit_up_reason_dict,
                                                                                                yesterday_current_limit_up_codes,
                                                                                                exclude_first_codes,
                                                                                                len(open_limit_up_codes),
                                                                                                shsz=True)
        record_shsz_rank, record_shsz_rank_codes = kpl_block_util.get_code_record_rank(code, block,
                                                                                       limit_up_record_datas,
                                                                                       code_limit_up_reason_dict,
                                                                                       yesterday_current_limit_up_codes,
                                                                                       shsz=True)
        # 获取主板历史身位
        open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas,
                                                                          code_limit_up_reason_dict)
        if open_limit_up_codes:
            # 主板开1
            if current_shsz_rank < len(open_limit_up_codes) + 1 and record_shsz_rank < len(open_limit_up_codes) + 2:
                # 属于龙1,龙2
                return True, f"{tool.get_now_time_str()} {block}:top10涨停板块,主板开1({open_limit_up_codes}),属于主板前龙{len(open_limit_up_codes) + 1}(实时身位-{current_shsz_rank}/{len(current_limit_up_datas)})"
                return True, f"{tool.get_now_time_str()} {block}:top10涨停板块,主板开1({open_limit_up_codes}),属于主板前龙{len(open_limit_up_codes) + 1}(实时身位-{current_shsz_rank}:{front_current_shsz_rank_codes}/{len(current_limit_up_datas)})"
            else:
                if record_shsz_rank >= len(open_limit_up_codes) + 1:
                    cls.__remove_from_l2(code, f"{code}根据身位禁止买入:【{block}】历史身位{record_shsz_rank}")
@@ -494,11 +521,12 @@
                          before_blocks_dict):
        # 加载涨停代码的目标板块
        def load_code_block():
            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_reason_dict[d[3]] = list(before_blocks_dict.get(d[3]))[0]
                else:
                    code_limit_up_reason_dict[d[3]] = d[2]
            if limit_up_record_datas:
                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_reason_dict[d[3]] = list(before_blocks_dict.get(d[3]))[0]
                    else:
                        code_limit_up_reason_dict[d[3]] = d[2]
            return code_limit_up_reason_dict
        if current_limit_up_datas is None:
@@ -519,7 +547,7 @@
                keys |= k4
                keys = keys - constant.KPL_INVALID_BLOCKS
        log.logger_kpl_debug.info("{}最终关键词:{}", code, keys)
        # log.logger_kpl_debug.info("{}最终关键词:{}", code, keys)
        # 涨停列表中匹配关键词,返回(板块:代码集合),代码集合中已经排除自身
        if not keys: