| | |
| | | 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 |
| | | |
| | |
| | | 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) |
| | | # 跟随精选板块一起更新 |
| | | self.load_jx_blocks_radical(code) |
| | | else: |
| | | # 还没涨停的需要更新精选板块 更新精选板块 |
| | | if abs(float(buy_1_price) - float(limit_up_price)) >= 0.001: |
| | |
| | | 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) |
| | | # 跟随精选板块一起更新 |
| | | self.load_jx_blocks_radical(code) |
| | | elif price_rate > 0.03: |
| | | # 添加备用板块 |
| | | if not self.get_jx_blocks_cache(code, by=True): |
| | |
| | | self.save_jx_blocks(code, blocks, current_limit_up_blocks, by=True) |
| | | async_log_util.info(logger_kpl_block_can_buy, |
| | | f"{code}:获取到精选板块(备用)-{blocks} 耗时:{int(time.time() - start_time)}s") |
| | | # 跟随精选板块一起更新 |
| | | self.load_jx_blocks_radical(code) |
| | | |
| | | if price_rate > 0.03: |
| | | if not self.__code_blocks_for_radical_buy.get(code): |
| | |
| | | def get_today_limit_up_reason(cls, code): |
| | | return cls.__today_total_limit_up_reason_dict.get(code) |
| | | |
| | | # 今日涨停原因变化 |
| | | def set_today_limit_up_reason_change(self, code, from_reason, to_reason): |
| | | RedisUtils.sadd(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", from_reason) |
| | | RedisUtils.expire(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", tool.get_expire()) |
| | | self.__set_total_keys(code) |
| | | |
| | | # 设置代码的今日涨停原因 |
| | | def __set_total_keys(self, code): |
| | | keys = set() |
| | |
| | | return fresult |
| | | |
| | | |
| | | |
| | | |
| | | # 实时开盘啦市场数据 |
| | | class RealTimeKplMarketData: |
| | | # 精选前5 |
| | |
| | | __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: |
| | |
| | | |
| | | class RadicalBuyBlockManager: |
| | | """ |
| | | 激进买板块管理 |
| | | 扫入买板块管理 |
| | | """ |
| | | __TargetCodePlateKeyManager = TargetCodePlateKeyManager() |
| | | # 上次的涨停代码 |
| | |
| | | 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) |
| | |
| | | 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}" |
| | | return True, f"开1数量:{count},前排代码不可买:{history_before_codes_info[0]},历史前排-{history_before_codes_info},开1代码-{open_limit_up_block_codes}" |
| | | return True, f"开1数量:{count},历史-{history_index + 1} 实时-{current_index + 1}, 前排代码-{current_before_codes_info}, 开1代码-{open_limit_up_block_codes}" |
| | | |
| | | @classmethod |
| | | def __is_radical_buy_with_block_up(cls, code, block, yesterday_limit_up_codes): |
| | |
| | | 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 blocks is None: |
| | | blocks = set() |
| | | # 将获取涨停原因与涨停推荐 |
| | | keys = TargetCodePlateKeyManager().get_plate_keys(code, contains_today=False) |
| | | keys = TargetCodePlateKeyManager().get_plate_keys(code, contains_today=True) |
| | | if keys and keys[0]: |
| | | blocks |= set(keys[0]) |
| | | return blocks |
| | |
| | | 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 |
| | | |