| | |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | if can_buy_result is None: |
| | | async_log_util.warning(logger_debug, "没有获取到板块缓存,将获取板块") |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | yesterday_current_limit_up_records = kpl_data_manager.get_yesterday_current_limit_up_records() |
| | | CodePlateKeyBuyManager.update_can_buy_blocks(code, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, |
| | | yesterday_codes, |
| | | yesterday_current_limit_up_records, |
| | | block_info.get_before_blocks_dict(), |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reason_codes_dict()) |
| | | can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | |
| | | can_buy_result = cls.__get_can_buy_block(code) |
| | | if can_buy_result is None: |
| | | return False, True, "尚未获取到板块信息" |
| | | if not can_buy_result[0] and can_buy_result[1]: |
| | | # 独苗 |
| | | return False, True, "独苗不下单" |
| | | |
| | | l2_log.debug(code, "获取到的板块信息:{}", can_buy_result) |
| | | |
| | | # -------量的约束-------- |
| | |
| | | # HighIncreaseCodeManager().add_code(code) |
| | | return False, True, f"近日出现最大量,当日量比({cls.volume_rate_info[code][0]})小于0.6" |
| | | |
| | | if can_buy_result[1]: |
| | | # 独苗 |
| | | # ------自由流通市值约束------ |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb: |
| | | if zyltgb < 10 * 100000000: |
| | | return False, True, f"独苗,自由流通小于10亿({zyltgb})" |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: |
| | | return False, True, f"独苗:量比({cls.volume_rate_info[code][0]})未达到60%" |
| | | |
| | | # 判断是否近2天是否为10天内最大量 |
| | | if k_format and len(k_format) >= 10 and k_format[9]: |
| | | # 是独苗 |
| | | if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.3: |
| | | return False, True, f"近2天有10日内最高量,量比({cls.volume_rate_info[code][0]})未达到30%" |
| | | if now_timestamp < int("100000") or int("130000") <= now_timestamp < int("133000"): |
| | | # 独苗必须9:30-10:00和13:00-13:30时间段内买 |
| | | return True, False, f"独苗:{can_buy_result[2]}" |
| | | else: |
| | | return False, True, f"独苗:当前时间不能买" |
| | | else: |
| | | if can_buy_result[0]: |
| | | return True, False, can_buy_result[2] |
| | | # 独苗不再下单 |
| | | # if can_buy_result[1]: |
| | | # # 独苗 |
| | | # # ------自由流通市值约束------ |
| | | # zyltgb = global_util.zyltgb_map.get(code) |
| | | # if zyltgb: |
| | | # if zyltgb < 10 * 100000000: |
| | | # return False, True, f"独苗,自由流通小于10亿({zyltgb})" |
| | | # if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.6: |
| | | # return False, True, f"独苗:量比({cls.volume_rate_info[code][0]})未达到60%" |
| | | # |
| | | # # 判断是否近2天是否为10天内最大量 |
| | | # if k_format and len(k_format) >= 10 and k_format[9]: |
| | | # # 是独苗 |
| | | # if code in cls.volume_rate_info and cls.volume_rate_info[code][0] < 0.3: |
| | | # return False, True, f"近2天有10日内最高量,量比({cls.volume_rate_info[code][0]})未达到30%" |
| | | # if now_timestamp < int("100000") or int("130000") <= now_timestamp < int("133000"): |
| | | # # 独苗必须9:30-10:00和13:00-13:30时间段内买 |
| | | # return True, False, f"独苗:{can_buy_result[2]}" |
| | | # else: |
| | | # return False, True, f"独苗:当前时间不能买" |
| | | # else: |
| | | if can_buy_result[0]: |
| | | return True, False, can_buy_result[2] |
| | | return False, True, can_buy_result[2] |
| | | |
| | | @classmethod |
| | |
| | | |
| | | # @unittest.skip("跳过此单元测试") |
| | | def test_block(self): |
| | | code = "002315" |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 37.24, 38, |
| | | code = "603918" |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 23.52,23.62, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | |
| | | block_info.init_code(code) |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.load_total_datas() |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | yesterday_current_limit_up_records = kpl_data_manager.get_yesterday_current_limit_up_records() |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), |
| | | kpl_data_manager.KPLDataManager.get_data( |
| | | kpl_util.KPLDataType.LIMIT_UP)) |
| | |
| | | CodePlateKeyBuyManager.update_can_buy_blocks(code, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, |
| | | yesterday_codes, |
| | | yesterday_current_limit_up_records, |
| | | block_info.get_before_blocks_dict(), |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reason_codes_dict()) |
| | | l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, None) |
| | |
| | | # 返回内容(是否可买, 是否为独苗, 描述信息) |
| | | @classmethod |
| | | def __is_block_can_buy(cls, code, block, current_limit_up_datas, code_limit_up_reason_dict, |
| | | yesterday_current_limit_up_codes, limit_up_record_datas, current_limit_up_block_codes_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_code_blocks is None: |
| | | high_level_code_blocks = {} |
| | | if high_level_block_codes is None: |
| | | high_level_block_codes = {} |
| | | block_codes = current_limit_up_block_codes_dict.get(block) |
| | | if not block_codes: |
| | | return False, True, f"{block}:板块无涨停", False |
| | | # 高位板泛化板块中无板块 |
| | | if not high_level_block_codes.get(block): |
| | | return False, True, f"{block}:板块无涨停", False |
| | | elif len(block_codes) == 1 and code in block_codes: |
| | | return False, True, f"{block}:板块只有当前代码涨停", False |
| | | if not high_level_block_codes.get(block): |
| | | return False, True, f"{block}:板块只有当前代码涨停", False |
| | | # 可以买的最大排名 |
| | | # open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, |
| | | # code_limit_up_reason_dict) |
| | |
| | | is_strong_block = False |
| | | for d in current_limit_up_datas: |
| | | if d[5] != block: |
| | | continue |
| | | 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("连板", "")) |
| | |
| | | |
| | | @classmethod |
| | | def get_can_buy_block(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, |
| | | before_blocks_dict, current_limit_up_block_codes_dict): |
| | | before_blocks_dict, current_limit_up_block_codes_dict, high_level_general_code_blocks, |
| | | high_level_general_block_codes): |
| | | # 加载涨停代码的目标板块 |
| | | def load_code_block(): |
| | | if limit_up_record_datas: |
| | |
| | | code_limit_up_reason_dict, |
| | | yesterday_current_limit_up_codes, |
| | | limit_up_record_datas, |
| | | current_limit_up_block_codes_dict) |
| | | current_limit_up_block_codes_dict, |
| | | high_level_code_blocks=high_level_general_code_blocks, |
| | | high_level_block_codes=high_level_general_block_codes) |
| | | fresults.append((block, can_buy, unique, msg, is_strong)) |
| | | return fresults, keys |
| | | |
| | |
| | | @classmethod |
| | | def __compute_can_buy_blocks(cls, code, current_limit_up_datas, limit_up_record_datas, |
| | | yesterday_current_limit_up_codes, before_blocks_dict, |
| | | current_limit_up_block_codes_dict): |
| | | current_limit_up_block_codes_dict, high_level_general_code_blocks): |
| | | # 根据代码泛化板块获取泛化板块的代码集合 |
| | | high_level_general_block_codes = {} |
| | | for c in high_level_general_code_blocks: |
| | | blocks = high_level_general_code_blocks[c] |
| | | for b in blocks: |
| | | if b not in high_level_general_block_codes: |
| | | high_level_general_block_codes[b] = set() |
| | | high_level_general_block_codes[b].add(c) |
| | | blocks_compute_results, keys = cls.get_can_buy_block(code, current_limit_up_datas, |
| | | limit_up_record_datas, yesterday_current_limit_up_codes, |
| | | before_blocks_dict, current_limit_up_block_codes_dict) |
| | | before_blocks_dict, current_limit_up_block_codes_dict, |
| | | high_level_general_code_blocks, |
| | | high_level_general_block_codes) |
| | | if not blocks_compute_results: |
| | | return False, True, f"没有找到板块", [], keys |
| | | codes_delegate = set(cls.__CodesTradeStateManager.get_codes_by_trade_states_cache( |
| | |
| | | return can_buy_blocks, False, ",".join(msg_list), can_buy_strong_blocks, keys |
| | | |
| | | # 更新代码板块判断是否可以买的结果 |
| | | # 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_codes, |
| | | yesterday_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 = {} |
| | | if yesterday_current_limit_up_records: |
| | | for r in yesterday_current_limit_up_records: |
| | | yesterday_current_limit_up_codes.add(r[0]) |
| | | yesterday_current_limit_up_records_dict[r[0]] = r |
| | | 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 |
| | | |
| | | can_buy_blocks, unique, msg, can_buy_strong_blocks, keys = cls.__compute_can_buy_blocks(code, |
| | | current_limit_up_datas, |
| | | limit_up_record_datas, |
| | | yesterday_current_limit_up_codes, |
| | | before_blocks_dict, |
| | | current_limit_up_block_codes_dict) |
| | | current_limit_up_block_codes_dict, |
| | | high_level_general_code_blocks) |
| | | # 保存板块计算结果 |
| | | cls.__can_buy_compute_result_dict[code] = (can_buy_blocks, unique, msg, can_buy_strong_blocks, keys) |
| | | |
| | |
| | | |
| | | |
| | | def get_yesterday_limit_up_codes(): |
| | | yesterday_limit_up_data_records = get_current_limit_up_data_records(1)[0][1] |
| | | yesterday_limit_up_data_records = get_yesterday_current_limit_up_records() |
| | | yesterday_codes = set([x[0] for x in yesterday_limit_up_data_records]) |
| | | return yesterday_codes |
| | | |
| | | |
| | | def get_yesterday_current_limit_up_records(): |
| | | yesterday_limit_up_data_records = get_current_limit_up_data_records(1)[0][1] |
| | | return yesterday_limit_up_data_records |
| | | |
| | | |
| | | # 运行拉取任务 |
| | | def run_pull_task(): |
| | | def __upload_data(type, datas): |
| | |
| | | cls.__KPLCodeJXBlockManager.load_jx_blocks(code, buy_1_price, limit_up_price, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | # 更新板块信息 |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | yesterday_current_limit_up_records = kpl_data_manager.get_yesterday_current_limit_up_records() |
| | | CodePlateKeyBuyManager.update_can_buy_blocks(code, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, |
| | | yesterday_codes, |
| | | yesterday_current_limit_up_records, |
| | | block_info.get_before_blocks_dict(), |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reason_codes_dict()) |
| | | |