| | |
| | | if blocks is None: |
| | | return |
| | | # 保存前2条数据 |
| | | RedisUtils.setex(self.__get_redis(),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 set_today_limit_up_reason_change(self, code, from_reason, to_reason): |
| | | RedisUtils.sadd(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", from_reason) |
| | | self.__get_redis().expire(f"kpl_limit_up_reason_his-{code}", tool.get_expire()) |
| | | RedisUtils.expire(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", tool.get_expire()) |
| | | self.__set_total_keys(code) |
| | | |
| | | # 设置代码的今日涨停原因 |
| | |
| | | |
| | | def set_history_limit_up_reason(self, code, reasons): |
| | | 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))) |
| | | 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表示已经加载过历史原因了 |
| | |
| | | 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 |
| | |
| | | |
| | | def set_blocks(self, code, blocks): |
| | | self.__blocks_dict[code] = set(blocks) |
| | | RedisUtils.setex(self.__get_redis(),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 |
| | |
| | | for k in k2: |
| | | if k not in constant.KPL_INVALID_BLOCKS: |
| | | keys.add(k) |
| | | if not keys: |
| | | # 始终获取精选板块 |
| | | if True: |
| | | # 获取 |
| | | jx_blocks = cls.__KPLCodeJXBlockManager.get_jx_blocks(code) |
| | | if jx_blocks: |
| | |
| | | |
| | | # 涨停列表中匹配关键词,返回(板块:代码集合),代码集合中已经排除自身 |
| | | if not keys: |
| | | return cls.BLOCK_TYPE_NONE, None, "尚未找到涨停原因" |
| | | return None, "尚未找到涨停原因" |
| | | code_limit_up_reason_dict = {} |
| | | load_code_block() |
| | | msg_list = [] |
| | |
| | | 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) |
| | | code_limit_up_reason_dict, yesterday_current_limit_up_codes, shsz=True) |
| | | record_shsz_rank = kpl_block_util.get_code_record_rank(code, block, limit_up_record_datas, |
| | | code_limit_up_reason_dict, shsz=True) |
| | | code_limit_up_reason_dict, yesterday_current_limit_up_codes, shsz=True) |
| | | # 获取主板历史身位 |
| | | if is_top_4: |
| | | pen_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, |
| | |
| | | pen_limit_up_codes) + 1: |
| | | # 属于龙1,龙2 |
| | | can_buy_blocks.append((block, |
| | | f"{block}:top4涨停板块,主板开1({pen_limit_up_codes}),属于主板前龙{len(pen_limit_up_codes) + 1}(实时身位-{current_shsz_rank})")) |
| | | f"{block}:top10涨停板块,主板开1({pen_limit_up_codes}),属于主板前龙{len(pen_limit_up_codes) + 1}(实时身位-{current_shsz_rank})")) |
| | | 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 = [x[0] for x in can_buy_blocks] |
| | | blocks_msg = "\n".join([x[1] for x in can_buy_blocks]) |
| | | return blocks, blocks_msg |
| | | |
| | |
| | | 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, yesterday_current_limit_up_codes, |
| | | before_blocks_dict) |
| | | if block is None: |
| | | blocks, block_msg = cls.get_can_buy_block(code, current_limit_up_datas, |
| | | limit_up_record_datas, yesterday_current_limit_up_codes, |
| | | before_blocks_dict) |
| | | if not blocks: |
| | | return False, block_msg |
| | | |
| | | # ---------------------------------判断目标代码的板块-------------------start------------ |
| | |
| | | # ---------------------------------加载已经下单/成交的代码信息------------end------------- |
| | | |
| | | msg_list = [] |
| | | for key in [block]: |
| | | for key in blocks: |
| | | # 板块中已经有成交的就不下单了 |
| | | if key in trade_success_blocks_count: |
| | | success_codes_count = len(trade_success_blocks_count[key]) |
| | | if success_codes_count >= 2: |
| | | if success_codes_count >= 1: |
| | | msg_list.append(f"【{key}】中已经有{success_codes_count}个成交代码") |
| | | log.logger_kpl_debug.debug(f"{code}:板块({key})已经有成交【{trade_success_blocks_count[key]}】") |
| | | continue |