| | |
| | | """ |
| | | import constant |
| | | from code_attribute import code_nature_analyse |
| | | from code_attribute.gpcode_manager import HumanRemoveForbiddenManager |
| | | from third_data import kpl_util |
| | | from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager |
| | | from third_data import kpl_util, kpl_data_constant |
| | | from trade import l2_trade_util, trade_record_log_util |
| | | from trade.buy_radical.block_special_codes_manager import BlockSpecialCodesManager |
| | | from utils import tool |
| | | from utils import tool, global_util |
| | | from utils.kpl_data_db_util import KPLLimitUpDataUtil |
| | | |
| | | # 新题材的最少涨停个数 |
| | | __MIN_LIMIT_UP_COUNT = 1 |
| | | |
| | | |
| | | @tool.singleton |
| | |
| | | """ |
| | | 往日题材计算器 |
| | | """ |
| | | |
| | | def __init__(self): |
| | | self.__before_blocks = set() |
| | | self.__load_data() |
| | |
| | | return self.__before_blocks |
| | | |
| | | |
| | | def process_new_block(code, block): |
| | | def screen_new_blocks_with_limit_up_datas(limit_up_datas): |
| | | """ |
| | | 处理新题材 |
| | | 从涨停代码筛选出新题材 |
| | | @param limit_up_datas:[(代码,涨停原因)] |
| | | @return:{"新题材":{新题材的代码}} |
| | | """ |
| | | block_codes_dict = {} |
| | | for d in limit_up_datas: |
| | | b = kpl_util.filter_block(d[1]) |
| | | if b not in block_codes_dict: |
| | | block_codes_dict[b] = set() |
| | | block_codes_dict[b].add(d[0]) |
| | | |
| | | blocks = set() |
| | | for b in block_codes_dict: |
| | | if b in constant.KPL_INVALID_BLOCKS: |
| | | continue |
| | | if len(block_codes_dict[b]) >= __MIN_LIMIT_UP_COUNT: |
| | | # 涨停代码数大于2个的原因 |
| | | blocks.add(b) |
| | | old_blocks = BeforeBlocksComputer().get_old_blocks() |
| | | # 新题材 |
| | | new_blocks = blocks - old_blocks |
| | | return {x: block_codes_dict[x] for x in new_blocks} |
| | | |
| | | |
| | | def __is_can_add_new_block(code): |
| | | """ |
| | | 是否可以添加到新板块 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb and zyltgb < 10e8: |
| | | return False |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if not constant.TEST: |
| | | if not k_format or not k_format[1][0]: |
| | | return False |
| | | return True |
| | | |
| | | |
| | | def process_new_block_by_limit_up_list(code, block): |
| | | """ |
| | | 根据涨停列表处理新题材 |
| | | @param code: |
| | | @param block: |
| | | @return: |
| | | """ |
| | | add_result = LimitUpCodesBlockRecordManager().add_new_blocks(code, block) |
| | | if add_result: |
| | | # 新题材破前高就移黑 |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format and k_format[1][0]: |
| | | # 破前高的票才会加入辨识度 |
| | | # 增加新题材是否成功, 临时将票加入辨识度 |
| | | trade_record_log_util.add_temp_special_codes(code, f"新题材辨识度:{block}") |
| | | BlockSpecialCodesManager().add_code_block_for_temp(code, block) |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | # 加想买单要从黑名单移除 |
| | | trade_record_log_util.add_common_msg(code, "新题材移黑", block) |
| | | # 不用删除炸板代码 |
| | | if __is_can_add_new_block(code): |
| | | if kpl_data_constant.limit_up_code_new_block_dict.get(code, "") != block: |
| | | # 题材有变化 |
| | | kpl_data_constant.limit_up_code_new_block_dict[code] = block |
| | | __sync_data_to_special_codes(code) |
| | | blocks = set() |
| | | for k in kpl_data_constant.limit_up_code_new_block_dict: |
| | | blocks.add(kpl_data_constant.limit_up_code_new_block_dict[k]) |
| | | kpl_data_constant.new_blocks = blocks |
| | | |
| | | |
| | | def process_new_block_by_component_codes(block, codes, all_new_blocks): |
| | | """ |
| | | 根据成分股处理新题材 |
| | | @param block: 板块 |
| | | @param codes: 成分股 |
| | | @param all_new_blocks: 所有的新题材 |
| | | @return: |
| | | """ |
| | | # 清除这个新题材下的代码 |
| | | for c in kpl_data_constant.limit_up_component_code_new_blocks_dict: |
| | | if block in kpl_data_constant.limit_up_component_code_new_blocks_dict[c] and c not in codes: |
| | | # 原来的代码中包含该板块,而当前板块的辨识度不包含该代码 |
| | | kpl_data_constant.limit_up_component_code_new_blocks_dict[c].discard(block) |
| | | |
| | | # 清除不是新题材的代码 |
| | | for c in kpl_data_constant.limit_up_component_code_new_blocks_dict: |
| | | # 原来的板块 |
| | | diff = kpl_data_constant.limit_up_component_code_new_blocks_dict[c] - all_new_blocks |
| | | if diff: |
| | | for d in diff: |
| | | kpl_data_constant.limit_up_component_code_new_blocks_dict[c].discard(d) |
| | | |
| | | # 在代码中加入新题材 |
| | | for c in codes: |
| | | if __is_can_add_new_block(c): |
| | | if c not in kpl_data_constant.limit_up_component_code_new_blocks_dict: |
| | | kpl_data_constant.limit_up_component_code_new_blocks_dict[c] = set() |
| | | kpl_data_constant.limit_up_component_code_new_blocks_dict[c].add(block) |
| | | __sync_data_to_special_codes(c) |
| | | |
| | | |
| | | def __sync_data_to_special_codes(code): |
| | | """ |
| | | 同步数据到辨识度 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | blocks = set() |
| | | if code in kpl_data_constant.limit_up_component_code_new_blocks_dict: |
| | | blocks |= kpl_data_constant.limit_up_component_code_new_blocks_dict[code] |
| | | if code in kpl_data_constant.limit_up_code_new_block_dict: |
| | | blocks.add(kpl_data_constant.limit_up_code_new_block_dict[code]) |
| | | if blocks and l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | l2_trade_util.remove_from_forbidden_trade_codes(code) |
| | | # 加想买单要从黑名单移除 |
| | | trade_record_log_util.add_common_msg(code, "新题材移黑", f"{blocks}") |
| | | # 新板块 |
| | | if constant.TEST: |
| | | print(code,kpl_data_constant.limit_up_code_new_block_dict.get(code), kpl_data_constant.limit_up_component_code_new_blocks_dict.get(code)) |
| | | BlockSpecialCodesManager().set_code_blocks_for_temp(code, blocks) |
| | | |
| | | |
| | | def is_can_forbidden(code): |
| | |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if LimitUpCodesBlockRecordManager().has_new_block(code): |
| | | if kpl_data_constant.has_new_block(code): |
| | | # 有新题材 |
| | | k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | if k_format and k_format[1][0]: |
| | | # 突破形态 |
| | | return False |
| | | return True |
| | | |
| | | return True |