| | |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from third_data import kpl_block_util, kpl_api, kpl_util, kpl_data_constant, huaxin_l1_data_manager |
| | | from settings.trade_setting import MarketSituationManager |
| | | from third_data.history_k_data_manager import HistoryKDataManager |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from third_data.kpl_data_constant import LimitUpDataConstant |
| | | from third_data.third_blocks_manager import BlockMapManager, CodeThirdBlocksManager |
| | | from trade.order_statistic import DealAndDelegateWithBuyModeDataManager |
| | | from trade.radical_buy_data_manager import RedicalBuyDataManager |
| | | from utils import global_util, tool, buy_condition_util, init_data_util |
| | | 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 |
| | | |
| | |
| | | __KPLPlateForbiddenManager = KPLPlateForbiddenManager() |
| | | __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() |
| | | __KPLPlatManager = KPLPlatManager() |
| | | # 精选前几 |
| | | __top_jx_blocks = set() |
| | | |
| | | @classmethod |
| | | def set_top_5_reasons(cls, datas): |
| | | temp_list = [] |
| | | for d in datas: |
| | | cls.total_reason_dict[d[1]] = d |
| | | # 排序 |
| | | for i in range(0, len(datas)): |
| | | if datas[i][1] not in constant.KPL_INVALID_BLOCKS: |
| | | # (名称,净流入金额,排名) |
| | | temp_list.append((datas[i][1], datas[i][3], len(temp_list))) |
| | | # 只获取前10个 |
| | | if len(temp_list) > 10: |
| | | break |
| | | if datas[i][3] < 3 * 10000 * 10000: |
| | | break |
| | | def set_market_jingxuan_blocks(cls, datas): |
| | | blocks = set() |
| | | for data in datas: |
| | | if data[3] <= 0: |
| | | break |
| | | blocks.add(data[1]) |
| | | cls.__top_jx_blocks = blocks |
| | | |
| | | for temp in temp_list: |
| | | names = cls.__KPLPlatManager.get_same_plat_names_by_id(temp[0]) |
| | | for name in names: |
| | | if name == temp[1]: |
| | | continue |
| | | temp_list.append((name, temp[1], temp[2])) |
| | | cls.top_5_reason_list = temp_list |
| | | cls.__reset_top_5_dict() |
| | | @classmethod |
| | | def get_top_market_jingxuan_blocks(cls): |
| | | return cls.__top_jx_blocks |
| | | |
| | | @classmethod |
| | | def set_top_5_industry(cls, datas): |
| | |
| | | def get_can_buy_key_set(cls): |
| | | temp_set = cls.top_5_key_dict.keys() |
| | | return temp_set |
| | | |
| | | # 通过关键字判断能买的代码数量 |
| | | @classmethod |
| | | def get_can_buy_codes_count(cls, code, key): |
| | | # 判断行业涨停票数量,除开自己必须大于1个 |
| | | temp_codes = LimitUpCodesPlateKeyManager.total_key_codes_dict.get(key) |
| | | if temp_codes is None: |
| | | temp_codes = set() |
| | | else: |
| | | temp_codes = set(temp_codes) |
| | | temp_codes.discard(code) |
| | | if len(temp_codes) < 1: |
| | | # 后排才能挂单 |
| | | return 0, "身位不为后排" |
| | | |
| | | forbidden_plates = cls.__KPLPlateForbiddenManager.list_all_cache() |
| | | if key in forbidden_plates: |
| | | return 0, "不买该板块" |
| | | |
| | | # 10:30以前可以挂2个单 |
| | | if int(tool.get_now_time_str().replace(':', '')) < int("100000"): |
| | | return 2, "10:00以前可以挂2个单" |
| | | # 10:30以后 |
| | | if key not in cls.top_5_key_dict: |
| | | return 0, "净流入没在前5" |
| | | if cls.top_5_key_dict[key][1] > 3 * 10000 * 10000: |
| | | return 2, "净流入在前5且大于3亿" |
| | | else: |
| | | return 1, "净流入在前5" |
| | | |
| | | @classmethod |
| | | def is_in_top(cls, keys): |
| | |
| | | return False, f"开1数量:{count},非开1首板身位不匹配:历史-{history_index + 1} 实时-{current_index + 1}" |
| | | if history_index == 1: |
| | | # 当前代码为老2,要判断老大是否可买 |
| | | if RedicalBuyDataManager.can_buy(history_before_codes_info[0][0])[0]: |
| | | if RedicalBuyDataManager.can_buy(history_before_codes_info[0][0], DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]: |
| | | return False, f"开1数量:{count},前排代码可买:{history_before_codes_info[0]}" |
| | | return True, f"开1数量:{count},前排代码不可买:{history_before_codes_info[0]}" |
| | | return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}" |
| | |
| | | # 不计算前2的代码 |
| | | |
| | | exclude_codes = set() |
| | | for x in current_before_codes: |
| | | for x in current_before_codes_info: |
| | | if x[1] < kpl_block_util.open_limit_up_time_range[1]: |
| | | exclude_codes.add(x[0]) |
| | | # 除去前二代码与开1代码之后是否为首板老大:所有开1的视为1个 |
| | |
| | | # 首板老2,判断前面的老大是否是属于不能买的范畴 |
| | | pre_code = history_before_codes_info[0][0] |
| | | # pre_code不能买,才能买 |
| | | if RedicalBuyDataManager.can_buy(pre_code)[0]: |
| | | if RedicalBuyDataManager.can_buy(pre_code, DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]: |
| | | return False, f"前排代码可买:{pre_code}" |
| | | # 距离前一个是否在10分钟内 |
| | | if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'), |
| | |
| | | return True, "" |
| | | |
| | | @classmethod |
| | | def get_code_kpl_blocks(cls, code): |
| | | blocks = KPLCodeJXBlockManager().get_jx_blocks_radical(code) |
| | | if blocks is None: |
| | | blocks = set() |
| | | # 将获取涨停原因与涨停推荐 |
| | | keys = TargetCodePlateKeyManager().get_plate_keys(code, contains_today=False) |
| | | if keys and keys[0]: |
| | | blocks |= set(keys[0]) |
| | | return blocks |
| | | |
| | | @classmethod |
| | | def get_code_blocks(cls, code): |
| | | """ |
| | | 获取目标代码的板块 |
| | | @param code: |
| | | @return: 过滤后的板块,过滤前的板块 |
| | | """ |
| | | blocks = cls.get_code_kpl_blocks(code) |
| | | match_blocks, info = CodeThirdBlocksManager().get_intersection_blocks_info(code, blocks) |
| | | match_blocks -= constant.KPL_INVALID_BLOCKS |
| | | fblocks = match_blocks & RealTimeKplMarketData.get_top_market_jingxuan_blocks() |
| | | if not fblocks: |
| | | fblocks = set() |
| | | match_blocks_3, info = CodeThirdBlocksManager().get_intersection_blocks_info(code, blocks, same_count=3) |
| | | if match_blocks_3: |
| | | match_blocks_3 -= constant.KPL_INVALID_BLOCKS |
| | | fblocks |= match_blocks_3 |
| | | |
| | | return fblocks, match_blocks |
| | | |
| | | @classmethod |
| | | def is_radical_buy(cls, code, yesterday_limit_up_codes): |
| | | """ |
| | | 是否是激进买 |
| | |
| | | for c in open_limit_up_code_dict: |
| | | open_limit_up_blocks |= open_limit_up_code_dict[c][1] |
| | | # 获取代码的板块 |
| | | keys_ = KPLCodeJXBlockManager().get_jx_blocks_radical(code) |
| | | if not keys_: |
| | | return set(), "没获取到板块" |
| | | keys_ = BlockMapManager().filter_blocks(keys_) |
| | | if not keys_: |
| | | return set(), "过滤后没获取到板块" |
| | | # 获取交集 |
| | | keys_, info = CodeThirdBlocksManager().get_intersection_blocks_info(code, keys_) |
| | | keys_, info = cls.get_code_blocks(code) |
| | | if not keys_: |
| | | return set(), "没获取到板块交集" |
| | | |