Administrator
2023-08-02 8595dc22aa9dde6aba6d0f8cdcf1656a8a59513b
third_data/code_plate_key_manager.py
@@ -6,6 +6,7 @@
import json
import constant
from db.redis_manager import RedisUtils
from third_data import kpl_block_util
from utils import global_util, tool
from log_module import log
@@ -28,14 +29,14 @@
        if blocks is None:
            return
        # 保存前2条数据
        self.__get_redis().setex(f"kpl_jx_blocks-{code}", tool.get_expire(), json.dumps(blocks))
        RedisUtils.setex(self.__get_redis(), f"kpl_jx_blocks-{code}", tool.get_expire(), json.dumps(blocks))
        self.__code_blocks[code] = blocks
    # 获取精选板块
    def get_jx_blocks(self, code):
        if code in self.__code_blocks:
            return self.__code_blocks[code]
        val = self.__get_redis().get(f"kpl_jx_blocks-{code}")
        val = RedisUtils.get(self.__get_redis(), f"kpl_jx_blocks-{code}")
        if val is None:
            return None
        else:
@@ -52,11 +53,11 @@
        return self.__redisManager.getRedis()
    def save_plate(self, plate):
        self.__get_redis().sadd("kpl_forbidden_plates", plate)
        self.__get_redis().expire("kpl_forbidden_plates", tool.get_expire())
        RedisUtils.sadd(self.__get_redis(), "kpl_forbidden_plates", plate)
        RedisUtils.expire(self.__get_redis(), "kpl_forbidden_plates", tool.get_expire())
    def list_all(self):
        return self.__get_redis().smembers("kpl_forbidden_plates")
        return RedisUtils.smembers(self.__get_redis(), "kpl_forbidden_plates")
class LimitUpCodesPlateKeyManager:
@@ -90,8 +91,8 @@
    # 今日涨停原因变化
    def set_today_limit_up_reason_change(self, code, from_reason, to_reason):
        self.__get_redis().sadd(f"kpl_limit_up_reason_his-{code}", from_reason)
        self.__get_redis().expire(f"kpl_limit_up_reason_his-{code}", tool.get_expire())
        RedisUtils.sadd(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", from_reason)
        RedisUtils.expire(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", tool.get_expire())
        self.__set_total_keys(code)
    # 设置代码的今日涨停原因
@@ -258,7 +259,8 @@
    def set_history_limit_up_reason(self, code, reasons):
        self.__history_limit_up_reason_dict[code] = set(reasons)
        self.__get_redis().setex(f"kpl_his_limit_up_reason-{code}", tool.get_expire(), json.dumps(list(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表示已经加载过历史原因了
@@ -266,7 +268,7 @@
        reasons = self.__history_limit_up_reason_dict.get(code)
        if reasons is None:
            # 从内存中加载
            val = self.__get_redis().get(f"kpl_his_limit_up_reason-{code}")
            val = RedisUtils.get(self.__get_redis(), f"kpl_his_limit_up_reason-{code}")
            if val is not None:
                val = set(json.loads(val))
                self.__history_limit_up_reason_dict[code] = val
@@ -279,13 +281,13 @@
    def set_blocks(self, code, blocks):
        self.__blocks_dict[code] = set(blocks)
        self.__get_redis().setex(f"kpl_blocks-{code}", tool.get_expire(), json.dumps(list(blocks)))
        RedisUtils.setex(self.__get_redis(), f"kpl_blocks-{code}", tool.get_expire(), json.dumps(list(blocks)))
    def get_blocks(self, code):
        reasons = self.__blocks_dict.get(code)
        if reasons is None:
            # 从内存中加载
            val = self.__get_redis().get(f"kpl_blocks-{code}")
            val = RedisUtils.get(self.__get_redis(), f"kpl_blocks-{code}")
            if val is not None:
                val = set(json.loads(val))
                self.__blocks_dict[code] = val
@@ -321,7 +323,7 @@
        if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict:
            k1 = {LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict[code]}
        # 加载今日历史原因
        k11 = self.__get_redis().smembers(f"kpl_limit_up_reason_his-{code}")
        k11 = RedisUtils.smembers(self.__get_redis(), f"kpl_limit_up_reason_his-{code}")
        k2 = self.__CodesPlateKeysManager.get_history_limit_up_reason(code)
        if k2 is None:
            k2 = set()
@@ -409,6 +411,8 @@
        code_limit_up_reason_dict = {}
        load_code_block()
        msg_list = []
        can_buy_blocks = []
        for block in keys:
            is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas,
                                                                               yesterday_current_limit_up_codes, 20)
@@ -429,16 +433,20 @@
                                                                                 code_limit_up_reason_dict)
                if pen_limit_up_codes:
                    # 主板开1
                    if current_shsz_rank < len(pen_limit_up_codes) + 1 and record_shsz_rank < len(pen_limit_up_codes) + 1:
                    if current_shsz_rank < len(pen_limit_up_codes) + 1 and record_shsz_rank < len(
                            pen_limit_up_codes) + 1:
                        # 属于龙1,龙2
                        return block, f"{block}:top4涨停板块,主板开1({pen_limit_up_codes}),属于主板前龙{len(pen_limit_up_codes) + 1}(实时身位-{current_shsz_rank})"
                        can_buy_blocks.append((block,
                                               f"{block}:top4涨停板块,主板开1({pen_limit_up_codes}),属于主板前龙{len(pen_limit_up_codes) + 1}(实时身位-{current_shsz_rank})"))
                        continue
                    else:
                        msg_list.append(
                            f"板块-{block}: top4涨停板块,主板开1({pen_limit_up_codes}),不为主板前龙{len(pen_limit_up_codes) + 1}(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})")
                        continue
                else:
                    if current_shsz_rank == 0 and record_shsz_rank < 2:
                        return block, f"{block}:top4涨停板块,非主板开1,属于龙1"
                        can_buy_blocks.append((block, f"{block}:top4涨停板块,非主板开1,属于龙1"))
                        continue
                    else:
                        msg_list.append(
                            f"板块-{block}: top4涨停板块,非主板开1,不为主板龙1(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})")
@@ -453,11 +461,17 @@
                else:
                    # 是否为主板龙1(实时龙1,历史龙2以内)
                    if current_shsz_rank == 0 and record_shsz_rank < 2:
                        return block, f"{block}:不是top4涨停板块,满足精选/行业流入要求,满足主板龙1"
                        can_buy_blocks.append((block, f"{block}:不是top4涨停板块,满足精选/行业流入要求,满足主板龙1"))
                        continue
                    else:
                        msg_list.append(
                            f"板块-{block}: 不是top4涨停板块,满足精选/行业流入要求,不为主板龙1(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})")
                        continue
        if len(can_buy_blocks) == len(keys):
            blocks = "/".join([x[0] for x in can_buy_blocks])
            blocks_msg = "\n".join([x[1] for x in can_buy_blocks])
            return blocks, blocks_msg
        return None, "\n".join(msg_list)
    # 是否可以下单