| | |
| | | from trade import trade_manager |
| | | |
| | | |
| | | # 代码精选板块管理 |
| | | class KPLCodeJXBlockManager: |
| | | __redisManager = redis_manager.RedisManager(3) |
| | | __code_blocks = {} |
| | | |
| | | def __get_redis(self): |
| | | return self.__redisManager.getRedis() |
| | | |
| | | def save_jx_blocks(self, code, blocks): |
| | | if blocks is None: |
| | | return |
| | | # 保存前2条数据 |
| | | self.__get_redis().setex(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}") |
| | | if val is None: |
| | | return None |
| | | else: |
| | | val = json.loads(val) |
| | | self.__code_blocks[code] = val |
| | | return self.__code_blocks[code] |
| | | |
| | | |
| | | # 开盘啦禁止交易板块管理 |
| | | class KPLPlateForbiddenManager: |
| | | __redisManager = redis_manager.RedisManager(3) |
| | |
| | | __TargetCodePlateKeyManager = TargetCodePlateKeyManager() |
| | | __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() |
| | | __CodesHisReasonAndBlocksManager = CodesHisReasonAndBlocksManager() |
| | | __KPLCodeJXBlockManager = KPLCodeJXBlockManager() |
| | | |
| | | # 获取可以买的板块 |
| | | # current_limit_up_datas: 今日实时涨停 |
| | | # latest_2_day_limit_up_datas:最近2天的实时涨停(不含今日) |
| | | # limit_up_record_datas:今日历史涨停 |
| | | # yesterday_current_limit_up_codes : 昨日涨停代码 |
| | | # before_blocks_dict:历史涨停原因 |
| | | @classmethod |
| | | def get_can_buy_block(cls, code, current_limit_up_datas, limit_up_record_datas, |
| | | def get_can_buy_block(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, |
| | | before_blocks_dict): |
| | | # 加载涨停代码的目标板块 |
| | | def load_code_block(): |
| | |
| | | if k not in constant.KPL_INVALID_BLOCKS: |
| | | keys.add(k) |
| | | if not keys: |
| | | if k3: |
| | | keys |= k3 |
| | | # 获取 |
| | | jx_blocks = cls.__KPLCodeJXBlockManager.get_jx_blocks(code) |
| | | if jx_blocks: |
| | | keys |= set([k[1] for k in jx_blocks[:2]]) |
| | | log.logger_kpl_debug.info("{}最终关键词:{}", code, keys) |
| | | |
| | | # 涨停列表中匹配关键词,返回(板块:代码集合),代码集合中已经排除自身 |
| | |
| | | load_code_block() |
| | | msg_list = [] |
| | | for block in keys: |
| | | is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas, 8) |
| | | is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas, 4) |
| | | 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) |
| | | is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas, |
| | | yesterday_current_limit_up_codes, 10) |
| | | is_top_4 = is_top_8_record and is_top_4_current |
| | | msg_list.append(f"实时top4: {top_4_current}") |
| | | msg_list.append(f"历史top8: {top_8_record}") |
| | | msg_list.append(f"\n实时top10: {top_4_current}(涨停数量:{len(current_limit_up_datas)})") |
| | | msg_list.append(f"历史top20: {top_8_record}") |
| | | |
| | | # 获取主板实时身位 |
| | | current_shsz_rank = kpl_block_util.get_code_current_rank(code, block, current_limit_up_datas, |
| | |
| | | code_limit_up_reason_dict, shsz=True) |
| | | # 获取主板历史身位 |
| | | if is_top_4: |
| | | is_open_limit_up, msg = kpl_block_util.is_shsz_open_limit_up(code, block, limit_up_record_datas, |
| | | code_limit_up_reason_dict) |
| | | if is_open_limit_up: |
| | | pen_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, |
| | | code_limit_up_reason_dict) |
| | | if pen_limit_up_codes: |
| | | # 主板开1 |
| | | if current_shsz_rank < 2 and record_shsz_rank < 2: |
| | | 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,属于龙1/龙2(实时身位-{current_shsz_rank})" |
| | | return block, f"{block}:top4涨停板块,主板开1({pen_limit_up_codes}),属于主板前龙{len(pen_limit_up_codes) + 1}(实时身位-{current_shsz_rank})" |
| | | else: |
| | | msg_list.append( |
| | | f"板块-{block}: top4涨停板块,主板开1({msg}),不为主板龙1龙2(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})") |
| | | 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: |
| | |
| | | msg_list.append( |
| | | f"板块-{block}: 不是top4涨停板块,满足精选/行业流入要求,不为主板龙1(实时身位-{current_shsz_rank},历史身位-{record_shsz_rank})") |
| | | continue |
| | | return None, "\r\n".join(msg_list) |
| | | return None, "\n".join(msg_list) |
| | | |
| | | # 是否可以下单 |
| | | # 返回:是否可以下单,消息,板块类型 |
| | | @classmethod |
| | | def can_buy(cls, code, current_limit_up_datas, limit_up_record_datas, before_blocks_dict): |
| | | def can_buy(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, |
| | | before_blocks_dict): |
| | | if constant.TEST: |
| | | return True, "", cls.BLOCK_TYPE_NONE |
| | | |
| | | block, block_msg = cls.get_can_buy_block(code, current_limit_up_datas, |
| | | limit_up_record_datas, before_blocks_dict) |
| | | limit_up_record_datas, yesterday_current_limit_up_codes, |
| | | before_blocks_dict) |
| | | if block is None: |
| | | return False, block_msg |
| | | |