| | |
| | | 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 |
| | | from log_module.log import logger_kpl_block_can_buy, logger_debug |
| | | from third_data.kpl_util import KPLPlatManager |
| | | from trade import trade_manager, l2_trade_util, trade_constant |
| | | |
| | |
| | | 激进买板块管理 |
| | | """ |
| | | __TargetCodePlateKeyManager = TargetCodePlateKeyManager() |
| | | # 上次的涨停代码 |
| | | __last_limit_up_codes = set() |
| | | # 记录代码的涨停时间 |
| | | __limit_up_time_dict = {} |
| | | # 炸板代码的总涨停时间 |
| | | __total_limit_up_space_dict = {} |
| | | |
| | | # 当前涨停的代码 |
| | | __current_limit_up_codes = set() |
| | | |
| | | @classmethod |
| | | def set_current_limit_up_datas(cls, current_limit_up_datas): |
| | | # 查询当前的涨停代码集合 |
| | | codes = set([d[0] for d in current_limit_up_datas]) |
| | | cls.__current_limit_up_codes = codes |
| | | try: |
| | | # 炸板代码 |
| | | break_limit_up_codes = cls.__last_limit_up_codes - codes |
| | | # 新涨停的代码 |
| | | new_limit_up_codes = codes - cls.__last_limit_up_codes |
| | | if new_limit_up_codes: |
| | | for code in new_limit_up_codes: |
| | | if code not in cls.__limit_up_time_dict: |
| | | cls.__limit_up_time_dict[code] = time.time() |
| | | if break_limit_up_codes: |
| | | # 记录总涨停时间 |
| | | for bc in break_limit_up_codes: |
| | | if bc in cls.__limit_up_time_dict: |
| | | space = tool.trade_time_sub(tool.get_now_time_str(), |
| | | tool.to_time_str(cls.__limit_up_time_dict[bc])) |
| | | if bc not in cls.__total_limit_up_space_dict: |
| | | cls.__total_limit_up_space_dict[bc] = 0 |
| | | cls.__total_limit_up_space_dict[bc] = cls.__total_limit_up_space_dict[bc] + space |
| | | logger_debug.info(f"炸板代码涨停时间:{bc}-{cls.__total_limit_up_space_dict[bc]}") |
| | | cls.__limit_up_time_dict.pop(bc) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | finally: |
| | | cls.__last_limit_up_codes = codes |
| | | cls.compute_open_limit_up_code_dict_for_radical_buy(current_limit_up_datas) |
| | | |
| | | @classmethod |
| | | def compute_open_limit_up_code_dict_for_radical_buy(cls, current_limit_up_datas): |
| | |
| | | 获取历史涨停身位 |
| | | @param code: |
| | | @param block: |
| | | @param current_limit_up_datas: |
| | | @param current_limit_up_datas: 昨日涨停代码 |
| | | @param current_limit_up_codes: 目前的涨停代码 |
| | | @return: |
| | | """ |
| | | history_index = 0 |
| | | block_codes_infos = [] |
| | | # 开1时间范围 |
| | | timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range |
| | | limit_up_time = time.time() |
| | | for k in LimitUpDataConstant.history_limit_up_datas: |
| | |
| | | # 剔除高位板 |
| | | if _code in yesterday_limit_up_codes: |
| | | continue |
| | | # 代码.涨停时间 |
| | | # 剔除炸板代码持续涨停时间小于1分钟的代码 |
| | | if _code not in cls.__current_limit_up_codes and _code in cls.__total_limit_up_space_dict and cls.__total_limit_up_space_dict[_code] < 60: |
| | | continue |
| | | # 代码,涨停时间 |
| | | block_codes_infos.append((_code, int(k[5]))) |
| | | block_codes_infos.append((code, limit_up_time)) |
| | | block_codes_infos.sort(key=lambda x: x[1]) |