| | |
| | | from db import mysql_data_delegate as mysql_data, redis_manager_delegate as redis_manager |
| | | from log_module.log import logger_kpl_limit_up_reason_change, logger_debug, \ |
| | | logger_kpl_open_limit_up, logger_kpl_block_can_buy |
| | | from third_data import kpl_util, kpl_api |
| | | from third_data import kpl_util, kpl_api, kpl_block_util |
| | | |
| | | # 代码对应的涨停原因保存 |
| | | from third_data.kpl_util import KPLPlatManager, KPLDataType |
| | |
| | | if limit_up_price and buy_1_price: |
| | | # 处理买1,卖1信息 |
| | | pre_close_price = round(float(limit_up_price) / tool.get_limit_up_rate(code), 2) |
| | | # 如果涨幅大于7%就读取板块 |
| | | # 如果涨幅大于5%就读取板块 |
| | | price_rate = (buy_1_price - pre_close_price) / pre_close_price |
| | | if price_rate > 0.07 * (tool.get_limit_up_rate(code)-1) * 10: |
| | | if price_rate > 0.05 * (tool.get_limit_up_rate(code) - 1) * 10: |
| | | jx_blocks_info = self.get_jx_blocks_cache(code) |
| | | if not jx_blocks_info: |
| | | start_time = time.time() |
| | |
| | | async_log_util.info(logger_kpl_block_can_buy, |
| | | f"{code}:获取到精选板块(更新)-{blocks} 耗时:{int(time.time() - start_time)}s") |
| | | self.save_jx_blocks(code, blocks, current_limit_up_blocks) |
| | | elif price_rate > 0.03 * (tool.get_limit_up_rate(code)-1) * 10: |
| | | elif price_rate > 0.03 * (tool.get_limit_up_rate(code) - 1) * 10: |
| | | # 添加备用板块 |
| | | if not self.get_jx_blocks_cache(code, by=True): |
| | | start_time = time.time() |
| | |
| | | return result |
| | | |
| | | |
| | | class CodePlateKeyBuyManager: |
| | | # 无板块 |
| | | BLOCK_TYPE_NONE = -1 |
| | | # 一般板块 |
| | | BLOCK_TYPE_COMMON = 0 |
| | | # 强势板块 |
| | | BLOCK_TYPE_STRONG = 1 |
| | | # 猛拉板块 |
| | | BLOCK_TYPE_SOON_LIMIT_UP = 2 |
| | | # 潜伏板块 |
| | | BLOCK_TYPE_START_UP = 3 |
| | | |
| | | __can_buy_compute_result_dict = {} |
| | | |
| | | @classmethod |
| | | def __is_block_can_buy_new(cls, code, block, current_limit_up_datas, code_limit_up_reasons_dict, |
| | | current_limit_up_block_codes_dict, yesterday_current_limit_up_codes): |
| | | """ |
| | | 该票的板块是否可以买 |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: 当前涨停数据 |
| | | @param code_limit_up_reasons_dict: 代码的涨停原因 |
| | | @param current_limit_up_block_codes_dict: 今日涨停板块对应的代码 |
| | | @param yesterday_current_limit_up_codes: 昨日涨停代码 |
| | | @return: 返回(前排开1数量,高位板数量,创业板数量,身位) |
| | | """ |
| | | block_codes = current_limit_up_block_codes_dict.get(block) |
| | | if block_codes is None: |
| | | block_codes = set() |
| | | # 判断开1数量 |
| | | current_open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes_current(code, block, |
| | | current_limit_up_datas) |
| | | # 创业板数量 |
| | | gem_codes = set() |
| | | for c in block_codes: |
| | | if c.find("30") == 0: |
| | | gem_codes.add(code) |
| | | # 高位板数量 |
| | | high_codes = set() |
| | | for c in block_codes: |
| | | if c in yesterday_current_limit_up_codes: |
| | | high_codes.add(c) |
| | | # 获取主板实时身位,剔除高位板 |
| | | exclude_first_codes = set() |
| | | current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | exclude_first_codes, |
| | | len( |
| | | current_open_limit_up_codes), |
| | | shsz=True) |
| | | return len(current_open_limit_up_codes), len(high_codes), len(gem_codes), current_shsz_rank |
| | | |
| | | @classmethod |
| | | def get_plate_keys(cls, code): |
| | | """ |
| | | 获取代码的板块 |
| | | :param code: |
| | | :return: 返回代码板块 |
| | | """ |
| | | blocks_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code) |
| | | if not blocks_info: |
| | | blocks_info = KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) |
| | | if blocks_info: |
| | | return blocks_info[0] |
| | | return None |
| | | |
| | | # 获取可以买的板块 |
| | | # 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, yesterday_current_limit_up_codes): |
| | | # 加载涨停代码的目标板块 |
| | | def load_limit_up_codes_block(): |
| | | if current_limit_up_datas: |
| | | for d in current_limit_up_datas: |
| | | blocks = {d[5]} |
| | | if d[6]: |
| | | blocks |= set(d[6].split('、')) |
| | | blocks = blocks - constant.KPL_INVALID_BLOCKS |
| | | code_limit_up_reasons_dict[d[3]] = blocks |
| | | return code_limit_up_reasons_dict |
| | | |
| | | if current_limit_up_datas is None: |
| | | current_limit_up_datas = [] |
| | | |
| | | # 获取目标代码板块 |
| | | keys = cls.get_plate_keys(code) |
| | | |
| | | # log.logger_kpl_debug.info("{}最终关键词:{}", code, keys) |
| | | |
| | | # 涨停列表中匹配关键词,返回(板块:代码集合),代码集合中已经排除自身 |
| | | |
| | | fresults = [] |
| | | if not keys: |
| | | return fresults, set() |
| | | code_limit_up_reasons_dict = {} |
| | | current_limit_up_block_codes_dict = {} |
| | | load_limit_up_codes_block() |
| | | for c in code_limit_up_reasons_dict: |
| | | bs = code_limit_up_reasons_dict[c] |
| | | for b in bs: |
| | | if b not in current_limit_up_block_codes_dict: |
| | | current_limit_up_block_codes_dict[b] = set() |
| | | current_limit_up_block_codes_dict[b].add(c) |
| | | |
| | | for block in keys: |
| | | # 前排开1数量, 高位板数量, 创业板数量, 身位 |
| | | open_limit_up_count, high_count, gem_count, rank = cls.__is_block_can_buy_new( |
| | | code, block, current_limit_up_datas, code_limit_up_reasons_dict, |
| | | current_limit_up_block_codes_dict, yesterday_current_limit_up_codes) |
| | | fresults.append((block, open_limit_up_count, high_count, gem_count, rank)) |
| | | return fresults, keys |
| | | |
| | | # 返回:(可以买的板块列表, 是否是独苗, 消息简介,可买的强势主线, 激进买入板块列表) |
| | | @classmethod |
| | | def statistic_block_infos(cls, code, current_limit_up_datas): |
| | | """ |
| | | 统计板块信息 |
| | | :param code: |
| | | :param current_limit_up_datas: |
| | | :return: [(板块, 前排开1数量, 高位板数量, 创业板数量, 身位)] |
| | | """ |
| | | yesterday_limit_up_codes = get_yesterday_limit_up_codes() |
| | | blocks_compute_results, keys = cls.get_can_buy_block(code, current_limit_up_datas, yesterday_limit_up_codes) |
| | | return blocks_compute_results |
| | | |
| | | |
| | | def load_history_limit_up(): |
| | | for file_name in os.listdir(f"{constant.get_path_prefix()}/kpl/his"): |
| | | if file_name.find("HisDaBanList_1.log") < 0: |