| | |
| | | from log_module import log, async_log_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | |
| | | from log_module.log import logger_kpl_block_can_buy, logger_debug |
| | | from log_module.log import logger_kpl_block_can_buy, logger_debug, logger_kpl_jx_out |
| | | from third_data.kpl_util import KPLPlatManager |
| | | from trade import trade_manager, l2_trade_util, trade_constant |
| | | |
| | |
| | | __KPLPlateForbiddenManager = KPLPlateForbiddenManager() |
| | | __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() |
| | | __KPLPlatManager = KPLPlatManager() |
| | | # 精选前几 |
| | | # 精选流入前几 |
| | | __top_jx_blocks = set() |
| | | # 精选流出前几 |
| | | __top_jx_out_blocks = set() |
| | | |
| | | @classmethod |
| | | def set_market_jingxuan_blocks(cls, datas): |
| | | """ |
| | | 设置精选流入数据 |
| | | @param datas: |
| | | @return: |
| | | """ |
| | | blocks = set() |
| | | for data in datas: |
| | | if data[3] <= 0: |
| | |
| | | cls.__top_jx_blocks = blocks |
| | | |
| | | @classmethod |
| | | def set_market_jingxuan_out_blocks(cls, datas): |
| | | """ |
| | | 设置精选流出数据 |
| | | @param datas: |
| | | @return: |
| | | """ |
| | | blocks = set() |
| | | for i in range(0, len(datas)): |
| | | if i >= 10 and int(tool.get_now_time_str().replace(":", "")) < int("100000"): |
| | | # 10点前看前10,十点后不看前10 |
| | | break |
| | | data = datas[i] |
| | | if data[3] > 0 - 5e7: |
| | | # 过滤5千万以上的 |
| | | break |
| | | blocks.add(kpl_util.filter_block(data[1])) |
| | | |
| | | # 记录精选流出日志 |
| | | async_log_util.info(logger_kpl_jx_out, f"原数据:{datas[:10]} 板块:{blocks}") |
| | | cls.__top_jx_out_blocks = blocks |
| | | |
| | | @classmethod |
| | | def get_top_market_jingxuan_blocks(cls): |
| | | return cls.__top_jx_blocks |
| | | |
| | | @classmethod |
| | | def get_top_market_jingxuan_out_blocks(cls): |
| | | return cls.__top_jx_out_blocks |
| | | |
| | | @classmethod |
| | | def set_top_5_industry(cls, datas): |
| | |
| | | __history_limit_up_reason_dict = {} |
| | | # 板块 |
| | | __blocks_dict = {} |
| | | |
| | | __instance = None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(CodesHisReasonAndBlocksManager, cls).__new__(cls, *args, **kwargs) |
| | | |
| | | return cls.__instance |
| | | |
| | | def __get_redis(self): |
| | | return self.__redisManager.getRedis() |
| | |
| | | except: |
| | | pass |
| | | return set() |
| | | |
| | | def get_history_blocks_cache(self, code): |
| | | """ |
| | | 获取180天的历史涨停原因缓存 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | return self.__history_blocks_dict_cache.get(code) |
| | | |
| | | |
| | | # 目标代码板块关键词管理 |
| | |
| | | current_limit_up_datas = [] |
| | | |
| | | # 获取目标代码板块 |
| | | keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) |
| | | # keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) |
| | | keys, k1 = RadicalBuyBlockManager.get_code_blocks(code) |
| | | |
| | | # log.logger_kpl_debug.info("{}最终关键词:{}", code, keys) |
| | | |
| | |
| | | fresults = [] |
| | | if not keys: |
| | | return fresults, set() |
| | | |
| | | code_limit_up_reasons_dict = {} |
| | | load_code_block() |
| | | for block in keys: |
| | |
| | | limit_up_time = time.time() |
| | | for k in LimitUpDataConstant.current_limit_up_datas: |
| | | _code = k[0] |
| | | # 剔除4板以上的板 |
| | | if kpl_util.get_high_level_count(k[4]) >= 4: |
| | | continue |
| | | |
| | | if _code in exclude_codes: |
| | | continue |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | |
| | | limit_up_space_ge_60s_codes = set() |
| | | for k in LimitUpDataConstant.history_limit_up_datas: |
| | | _code = k[3] |
| | | |
| | | # 剔除4板以上的板 |
| | | if kpl_util.get_high_level_count(k[12]) >= 4: |
| | | continue |
| | | |
| | | if _code in exclude_codes: |
| | | continue |
| | | blocks = LimitUpDataConstant.get_blocks_with_history(_code) |
| | |
| | | else: |
| | | # 距离上个代码涨停5分钟以内 |
| | | if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'), |
| | | tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 5 * 60: |
| | | return False, f"距离上个代码涨停已过去5分钟({current_before_codes_info[-1]})" |
| | | tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60: |
| | | return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[-1]})" |
| | | else: |
| | | if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'), |
| | | tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 5 * 60: |
| | | return False, f"距离上个代码涨停已过去5分钟({current_before_codes_info[-1]})" |
| | | tool.timestamp_format(current_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60: |
| | | return False, f"距离上个代码涨停已过去10分钟({current_before_codes_info[-1]})" |
| | | |
| | | return True, f"满足买入需求: 前排代码-{current_before_codes_info}" |
| | | |
| | |
| | | if match_blocks_3: |
| | | match_blocks_3 -= constant.KPL_INVALID_BLOCKS |
| | | fblocks |= match_blocks_3 |
| | | # 获取开盘啦历史涨停原因 |
| | | kpl_history_blocks = CodesHisReasonAndBlocksManager().get_history_blocks_cache(code) |
| | | if kpl_history_blocks: |
| | | fblocks |= BlockMapManager().filter_blocks(kpl_history_blocks) |
| | | jx_out_blocks = RealTimeKplMarketData.get_top_market_jingxuan_out_blocks() |
| | | if jx_out_blocks: |
| | | fblocks -= jx_out_blocks |
| | | |
| | | return fblocks, match_blocks |
| | | |