| | |
| | | import time |
| | | |
| | | import constant |
| | | from code_attribute import code_nature_analyse |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from third_data import kpl_block_util, kpl_api |
| | | from utils import global_util, tool |
| | | from third_data import kpl_block_util, kpl_api, kpl_util |
| | | from trade.trade_manager import MarketSituationManager |
| | | from utils import global_util, tool, buy_condition_util |
| | | from log_module import log, async_log_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | |
| | |
| | | jingxuan_block_info = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code, by=True) |
| | | if jingxuan_block_info: |
| | | jingxuan_blocks = jingxuan_block_info[0] |
| | | k4 |= set(jingxuan_blocks) #set([x[1] for x in jingxuan_blocks]) |
| | | k4 |= set(jingxuan_blocks) # set([x[1] for x in jingxuan_blocks]) |
| | | for k in [k1, k11, k2, k3, k4]: |
| | | keys |= k |
| | | |
| | |
| | | |
| | | # 返回内容(是否可买, 是否为独苗, 描述信息) |
| | | @classmethod |
| | | def __is_block_can_buy(cls, code, block, current_limit_up_datas, code_limit_up_reason_dict, |
| | | def __is_block_can_buy(cls, code, block, current_limit_up_datas, code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, limit_up_record_datas, current_limit_up_block_codes_dict, |
| | | high_level_code_blocks=None, high_level_block_codes=None): |
| | | # 独苗判断 |
| | |
| | | if high_level_block_codes is None: |
| | | high_level_block_codes = {} |
| | | block_codes = current_limit_up_block_codes_dict.get(block) |
| | | if block_codes is None: |
| | | block_codes = set() |
| | | if not block_codes: |
| | | # 高位板泛化板块中无板块 |
| | | if not high_level_block_codes.get(block): |
| | |
| | | # ---------------------------判断强势主线------------------------- |
| | | is_strong_block = False |
| | | for d in current_limit_up_datas: |
| | | if d[5] != block: |
| | | bs = kpl_util.get_current_limit_up_reasons(d) |
| | | if block not in bs: |
| | | general_blocks = high_level_code_blocks.get(d[0]) |
| | | if not general_blocks or block not in general_blocks: |
| | | # 没在泛化板块中 |
| | | continue |
| | | if d[4].find("连板") > 0: |
| | | if d[4].replace("连板", "").isdigit(): |
| | | count = int(d[4].replace("连板", "")) |
| | | if count >= 3: |
| | | is_strong_block = True |
| | | break |
| | | count = kpl_util.get_high_level_count(d[4]) |
| | | if count >= 3: |
| | | if d[4].find("连板") > 0: |
| | | is_strong_block = True |
| | | break |
| | | elif d[0] in yesterday_current_limit_up_codes and len(block_codes) >= 2: |
| | | # 几天几板,且最近2连板 |
| | | # 看是否有首板后排 |
| | | is_strong_block = True |
| | | break |
| | | |
| | | if not is_strong_block: |
| | | temp_block_codes = set(copy.deepcopy(block_codes)) |
| | | temp_block_codes.discard(code) |
| | | if len(temp_block_codes) >= 3: |
| | | is_strong_block = True |
| | | max_rank = 2 |
| | | # 强势板块买老四 |
| | | if is_strong_block: |
| | |
| | | # 获取主板实时身位,剔除高位板 |
| | | current_shsz_rank, front_current_shsz_rank_codes = kpl_block_util.get_code_current_rank(code, block, |
| | | current_limit_up_datas, |
| | | code_limit_up_reason_dict, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | exclude_first_codes, |
| | | len(current_open_limit_up_codes), |
| | | shsz=True, limit_up_time=first_limit_up_time) |
| | | len( |
| | | current_open_limit_up_codes), |
| | | shsz=True, |
| | | limit_up_time=first_limit_up_time) |
| | | # record_shsz_rank, record_shsz_rank_codes = kpl_block_util.get_code_record_rank(code, block, |
| | | # limit_up_record_datas, |
| | | # code_limit_up_reason_dict, |
| | |
| | | if current_shsz_rank < len(current_open_limit_up_codes) + max_rank: |
| | | return True, False, f"【{block}】前排代码:{current_shsz_rank}", is_strong_block |
| | | else: |
| | | # k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) |
| | | # if k_format and k_format[8][0]: |
| | | # # 具有辨识度 |
| | | # return True, False, f"【{block}】具有辨识度", is_strong_block |
| | | # 看自由流通市值是否小于20亿 |
| | | if is_strong_block and current_shsz_rank < len(current_open_limit_up_codes) + max_rank + 1: |
| | | zyltgb_as_yi = round(global_util.zyltgb_map.get(code) / 100000000, 2) if code in global_util.zyltgb_map else None |
| | | situation = MarketSituationManager().get_situation_cache() |
| | | zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation) |
| | | if zyltgb_as_yi and zylt_threshold_as_yi[2] <= zyltgb_as_yi <= zylt_threshold_as_yi[3]: |
| | | return True, False, f"【{block}】强势板块 自由流通市值({zyltgb_as_yi})大于{zylt_threshold_as_yi[2]}亿 小于{zylt_threshold_as_yi[3]}亿", is_strong_block |
| | | return False, False, f"【{block}】前排代码:{front_current_shsz_rank_codes} 超过{len(current_open_limit_up_codes) + max_rank}个", is_strong_block |
| | | |
| | | # 过时的代码 |
| | |
| | | if limit_up_record_datas: |
| | | for d in limit_up_record_datas: |
| | | if d[2] in constant.KPL_INVALID_BLOCKS and d[3] in before_blocks_dict: |
| | | code_limit_up_reason_dict[d[3]] = list(before_blocks_dict.get(d[3]))[0] |
| | | code_limit_up_reasons_dict[d[3]] = {list(before_blocks_dict.get(d[3]))[0]} |
| | | else: |
| | | code_limit_up_reason_dict[d[3]] = d[2] |
| | | return code_limit_up_reason_dict |
| | | code_limit_up_reasons_dict[d[3]] = {d[2]} |
| | | if d[6]: |
| | | code_limit_up_reasons_dict[d[3]] |= set(d[6].split("、")) |
| | | return code_limit_up_reasons_dict |
| | | |
| | | if current_limit_up_datas is None: |
| | | current_limit_up_datas = [] |
| | |
| | | # 始终获取精选板块 |
| | | if True: |
| | | # 获取 |
| | | if k4 and not keys: |
| | | if k4: |
| | | # 当涨停原因没有时才取精选板块 |
| | | keys |= k4 |
| | | keys = keys - constant.KPL_INVALID_BLOCKS |
| | |
| | | fresults = [] |
| | | if not keys: |
| | | return fresults, set() |
| | | code_limit_up_reason_dict = {} |
| | | code_limit_up_reasons_dict = {} |
| | | load_code_block() |
| | | for block in keys: |
| | | can_buy, unique, msg, is_strong = cls.__is_block_can_buy(code, block, current_limit_up_datas, |
| | | code_limit_up_reason_dict, |
| | | code_limit_up_reasons_dict, |
| | | yesterday_current_limit_up_codes, |
| | | limit_up_record_datas, |
| | | current_limit_up_block_codes_dict, |
| | |
| | | # high_level_general_code_blocks 高位泛化板块 |
| | | @classmethod |
| | | def update_can_buy_blocks(cls, code, current_limit_up_datas, limit_up_record_datas, |
| | | yesterday_current_limit_up_records, |
| | | latest_current_limit_up_records, |
| | | before_blocks_dict, current_limit_up_block_codes_dict): |
| | | yesterday_current_limit_up_codes = set() |
| | | yesterday_current_limit_up_records_dict = {} |
| | | yesterday_current_limit_up_records = latest_current_limit_up_records[0][1] |
| | | if yesterday_current_limit_up_records: |
| | | for r in yesterday_current_limit_up_records: |
| | | yesterday_current_limit_up_codes.add(r[0]) |
| | |
| | | high_level_general_code_blocks = {} |
| | | # 是否是3板及以上的高位板 |
| | | for r in current_limit_up_datas: |
| | | if r[4].find("连板") > 0: |
| | | if r[4].replace("连板", "").isdigit(): |
| | | count = int(r[4].replace("连板", "")) |
| | | if count >= 3: |
| | | # 是高位板 |
| | | # 当日精选 |
| | | blocks = set(r[6].split("、")) |
| | | if r[0] in yesterday_current_limit_up_records_dict: |
| | | # 昨日涨停原因 |
| | | blocks.add(yesterday_current_limit_up_records_dict.get(r[0])[5]) |
| | | f_blocks = [] |
| | | for b in blocks: |
| | | if b: |
| | | f_blocks.append(b) |
| | | high_level_general_code_blocks[r[0]] = f_blocks |
| | | count = kpl_util.get_high_level_count(r[4]) |
| | | if count >= 3 and r[0] in yesterday_current_limit_up_codes: |
| | | latest_datas = latest_current_limit_up_records[:count - 1] |
| | | # 是高位板 |
| | | # 当日精选 |
| | | blocks = set(r[6].split("、")) |
| | | for d in latest_datas: |
| | | for dd in d[1]: |
| | | if dd[0] == r[0]: |
| | | blocks.add(dd[5]) |
| | | break |
| | | f_blocks = [] |
| | | for b in blocks: |
| | | if b: |
| | | f_blocks.append(b) |
| | | high_level_general_code_blocks[r[0]] = f_blocks |
| | | |
| | | can_buy_blocks, unique, msg, can_buy_strong_blocks, keys = cls.__compute_can_buy_blocks(code, |
| | | current_limit_up_datas, |