From 4cd4b226ac4a8816ab78ff44fadafa1eb98acb1a Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 02 四月 2024 09:44:10 +0800 Subject: [PATCH] 板块修改 --- third_data/code_plate_key_manager.py | 183 ++++++++++++++++++++++++++++++++------------- 1 files changed, 128 insertions(+), 55 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index 4977c5a..87315a2 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -132,7 +132,8 @@ start_time = time.time() blocks = kpl_api.getCodeBlocks(code) 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") + async_log_util.info(logger_kpl_block_can_buy, + f"{code}:鑾峰彇鍒扮簿閫夋澘鍧�(澶囩敤)-{blocks} 鑰楁椂:{int(time.time() - start_time)}s") except Exception as e: logger_kpl_block_can_buy.error(f"{code} 鑾峰彇鏉垮潡鍑洪敊") logger_kpl_block_can_buy.exception(e) @@ -178,7 +179,7 @@ class LimitUpCodesPlateKeyManager: # 浠婃棩娑ㄥ仠鍘熷洜 today_limit_up_reason_dict = {} - today_total_limit_up_reason_dict = {} + __today_total_limit_up_reason_dict = {} total_code_keys_dict = {} total_key_codes_dict = {} __redisManager = redis_manager.RedisManager(1) @@ -186,7 +187,7 @@ def __get_redis(self): return self.__redisManager.getRedis() - # 鑾峰彇浠婃棩娑ㄥ仠鏁版嵁锛屾牸寮忥細[(浠g爜,娑ㄥ仠鍘熷洜)] + # 鑾峰彇浠婃棩娑ㄥ仠鏁版嵁锛屾牸寮忥細[(浠g爜,娑ㄥ仠鍘熷洜,绮鹃�夋澘鍧楀垪琛�)] def set_today_limit_up(self, datas): temp_dict = {} if datas: @@ -199,10 +200,17 @@ self.set_today_total_limit_up(datas) # 璁剧疆浠婃棩鍘嗗彶娑ㄥ仠鏁版嵁 - def set_today_total_limit_up(self, datas): + # 鏍煎紡锛�(浠g爜,娑ㄥ仠鍘熷洜,绮鹃�夋澘鍧楀垪琛�) + @classmethod + def set_today_total_limit_up(cls, datas): for item in datas: code = item[0] - self.today_total_limit_up_reason_dict[code] = item[1] + # 璁剧疆娑ㄥ仠浠g爜鐨勬澘鍧楀強鍘熷洜 + cls.__today_total_limit_up_reason_dict[code] = (item[1], item[2]) + + @classmethod + 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): @@ -437,8 +445,10 @@ def get_plate_keys(self, code): keys = set() k1 = set() - if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict: - k1 = {LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict[code]} + + limit_up_reason_info = LimitUpCodesPlateKeyManager.get_today_limit_up_reason(code) + if limit_up_reason_info: + k1 = {limit_up_reason_info[0]} | set(limit_up_reason_info[1]) # 鍔犺浇浠婃棩鍘嗗彶鍘熷洜,鏆傛椂涓嶉渶瑕佸巻鍙插師鍥犱簡 k11 = set() # RedisUtils.smembers(self.__get_redis(), f"kpl_limit_up_reason_his-{code}") k2 = self.__CodesPlateKeysManager.get_history_limit_up_reason_cache(code) @@ -456,12 +466,14 @@ if jingxuan_block_info: jingxuan_blocks = jingxuan_block_info[0] k4 |= set(jingxuan_blocks) # set([x[1] for x in jingxuan_blocks]) - for k in [k1, k11, k2, k3, k4]: - keys |= k - - # 鎺掗櫎鏃犳晥鐨勬定鍋滃師鍥� - keys = keys - set(constant.KPL_INVALID_BLOCKS) - + if k1: + # 娑ㄥ仠杩� + keys |= k1 + keys = keys - set(constant.KPL_INVALID_BLOCKS) + if not keys: + # 鑾峰彇涓嶅埌娑ㄥ仠鍘熷洜 + keys |= k4 + keys = keys - set(constant.KPL_INVALID_BLOCKS) return keys, k1, k11, k2, k3, k4 @@ -494,7 +506,69 @@ l2_trade_util.forbidden_trade(code, msg=msg) logger_kpl_block_can_buy.info(msg) - # 杩斿洖鍐呭(鏄惁鍙拱, 鏄惁涓虹嫭鑻�, 鎻忚堪淇℃伅) + # 鏄惁闇�瑕佹縺杩涗拱 + @classmethod + def __is_need_active_buy(cls, code, block, current_limit_up_datas, limit_up_record_datas, + yesterday_current_limit_up_codes): + code_limit_up_reason_dict = {} + for d in limit_up_record_datas: + code_limit_up_reason_dict[d[3]] = d[2] + + # 鍓嶉潰鏈夐珮浣嶆澘/闈炰富鏉挎定鍋滀笖鏇炬定鍋滀富鏉挎帓鑰佸ぇ鍒欐縺杩涗拱 + block_codes_info = [] + contains_code = False + for d in current_limit_up_datas: + reason = kpl_util.get_current_limit_up_reason(d) + if reason != block: + continue + if d[0] == code: + contains_code = True + # 鏍煎紡锛歔浠g爜,娑ㄥ仠鏃堕棿,鏄惁楂樹綅鏉�, 鑷敱娴侀�氬競鍊糫 + block_codes_info.append((d[0], d[2], d[0] in yesterday_current_limit_up_codes, d[7])) + if not contains_code: + block_codes_info.append((code, int(time.time()), False, global_util.zyltgb_map.get(code))) + block_codes_info.sort(key=lambda x: x[1]) + # 鏆傚瓨鍦ㄥ綋鍓嶄唬鐮佷箣鍓嶆定鍋滅殑楂樹綅鏉�/闈炰富鏉夸唬鐮� + before_codes = [] + for info in block_codes_info: + if info[0] == code: + break + if info[2] or not tool.is_shsz_code(info[0]): + before_codes.append(info[0]) + if before_codes: + # 鍒ゆ柇鍘嗗彶娑ㄥ仠涓绘澘韬綅 + record_shsz_rank, record_shsz_rank_codes = kpl_block_util.get_code_record_rank(code, block, + limit_up_record_datas, + code_limit_up_reason_dict, + yesterday_current_limit_up_codes, + shsz=True) + if record_shsz_rank == 0: + # 鍘嗗彶涓绘澘鑰佸ぇ + return True, f"涓绘澘鑰佸ぇ涓斿墠闈㈡湁闈炰富鏉�/楂樹綅鏉挎定鍋滐紝鍏堜簬娑ㄥ仠浠g爜锛歿before_codes}" + # 鎺掗櫎鑷繁鏈�3涓定鍋滐紝涓旇繖4涓腑鑷敱娴侀�氬競鍊兼渶灏忥紝涓旀定鍋滆繃鐨勪唬鐮佷腑涓绘澘鎺掑悕鍓�4 + if len(block_codes_info) >= 4: + temp_codes = [] + for info in block_codes_info: + # 涓嶆槸楂樹綅鏉夸笖鏄富鏉� + if not info[2] and tool.is_shsz_code(info[0]): + # 鏍煎紡锛�(浠g爜, 鑷敱娴侀�氬競鍊�) + temp_codes.append((info[0], info[3])) + # 鍒ゆ柇鏄惁涓轰富鏉夸腑鑷敱甯傚�兼渶灏� + temp_codes.sort(key=lambda x: x[1]) + if temp_codes[0][0] == code: + # 鑷敱甯傚�兼渶灏� + # 鍒ゆ柇鍘嗗彶韬綅 + record_shsz_rank, record_shsz_rank_codes = kpl_block_util.get_code_record_rank(code, block, + limit_up_record_datas, + code_limit_up_reason_dict, + yesterday_current_limit_up_codes, + shsz=True) + if record_shsz_rank < 4: + return True, f"鏉垮潡鏈夊ぇ浜�3绁ㄦ定鍋滐紝涓旇嚜鐢辨祦閫氬競鍊兼渶灏忥紝韬綅({record_shsz_rank})鍓�4" + + return False, "涓嶆弧瓒虫縺杩涗拱鍏ユ潯浠�" + + # 杩斿洖鍐呭(鏄惁鍙拱, 鏄惁涓虹嫭鑻�, 鎻忚堪淇℃伅, 鏄惁涓哄己鍔夸富绾�, 鏄惁闇�瑕佹縺杩涗拱) @classmethod def __is_block_can_buy(cls, code, block, current_limit_up_datas, code_limit_up_reasons_dict, yesterday_current_limit_up_codes, limit_up_record_datas, current_limit_up_block_codes_dict, @@ -507,13 +581,18 @@ block_codes = current_limit_up_block_codes_dict.get(block) if block_codes is None: block_codes = set() + # 璁$畻鏄惁闇�瑕佹縺杩涗拱鍏� + active_buy = cls.__is_need_active_buy(code, block, current_limit_up_datas, + limit_up_record_datas, + yesterday_current_limit_up_codes) + if not block_codes: # 楂樹綅鏉挎硾鍖栨澘鍧椾腑鏃犳澘鍧� if not high_level_block_codes.get(block): - return False, True, f"{block}:鏉垮潡鏃犳定鍋�", False + return False, True, f"{block}:鏉垮潡鏃犳定鍋�", False, active_buy elif len(block_codes) == 1 and code in block_codes: if not high_level_block_codes.get(block): - return False, True, f"{block}:鏉垮潡鍙湁褰撳墠浠g爜娑ㄥ仠", False + return False, True, f"{block}:鏉垮潡鍙湁褰撳墠浠g爜娑ㄥ仠", False, active_buy # 鍙互涔扮殑鏈�澶ф帓鍚� # open_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, # code_limit_up_reason_dict) @@ -583,10 +662,10 @@ # shsz=True) if int(tool.get_now_time_str().replace(":", "")) <= int("094000") and is_strong_block: # 寮哄娍涓荤嚎鍔犲己鍔�10鍒嗛挓 - return True, False, f"銆恵block}銆戯細寮哄娍涓荤嚎+寮哄娍10鍒嗛挓", is_strong_block + return True, False, f"銆恵block}銆戯細寮哄娍涓荤嚎+寮哄娍10鍒嗛挓", is_strong_block, active_buy if current_shsz_rank < len(current_open_limit_up_codes) + max_rank: - return True, False, f"銆恵block}銆戝墠鎺掍唬鐮侊細{current_shsz_rank}", is_strong_block + return True, False, f"銆恵block}銆戝墠鎺掍唬鐮侊細{current_shsz_rank}", is_strong_block, active_buy else: # k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) # if k_format and k_format[8][0]: @@ -594,12 +673,13 @@ # return True, False, f"銆恵block}銆戝叿鏈夎鲸璇嗗害", is_strong_block # 鐪嬭嚜鐢辨祦閫氬競鍊兼槸鍚﹀皬浜�20浜� if is_strong_block and current_shsz_rank < len(current_open_limit_up_codes) + max_rank + 1: - zyltgb_as_yi = round(global_util.zyltgb_map.get(code) / 100000000, 2) if code in global_util.zyltgb_map else None + zyltgb_as_yi = round(global_util.zyltgb_map.get(code) / 100000000, + 2) if code in global_util.zyltgb_map else None situation = MarketSituationManager().get_situation_cache() zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation) if zyltgb_as_yi and zylt_threshold_as_yi[2] <= zyltgb_as_yi <= zylt_threshold_as_yi[3]: - return True, False, f"銆恵block}銆戝己鍔挎澘鍧� 鑷敱娴侀�氬競鍊�({zyltgb_as_yi})澶т簬{zylt_threshold_as_yi[2]}浜� 灏忎簬{zylt_threshold_as_yi[3]}浜�", is_strong_block - return False, False, f"銆恵block}銆戝墠鎺掍唬鐮侊細{front_current_shsz_rank_codes} 瓒呰繃{len(current_open_limit_up_codes) + max_rank}涓�", is_strong_block + return True, False, f"銆恵block}銆戝己鍔挎澘鍧� 鑷敱娴侀�氬競鍊�({zyltgb_as_yi})澶т簬{zylt_threshold_as_yi[2]}浜� 灏忎簬{zylt_threshold_as_yi[3]}浜�", is_strong_block, active_buy + return False, False, f"銆恵block}銆戝墠鎺掍唬鐮侊細{front_current_shsz_rank_codes} 瓒呰繃{len(current_open_limit_up_codes) + max_rank}涓�", is_strong_block, active_buy # 杩囨椂鐨勪唬鐮� # if open_limit_up_codes: @@ -649,19 +729,6 @@ # 鑾峰彇鐩爣浠g爜鏉垮潡 keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) - # log.logger_kpl_debug.info("{}鍏抽敭璇嶏細浠婃棩-{},浠婃棩鍘嗗彶-{},鍘嗗彶-{},浜岀骇琛屼笟-{},浠g爜鏉垮潡-{}", code, k1, k11, k2, k3, k4) - keys = set() - if k1: - for k in k1: - if k not in constant.KPL_INVALID_BLOCKS: - keys.add(k) - # 濮嬬粓鑾峰彇绮鹃�夋澘鍧� - if True: - # 鑾峰彇 - if k4: - # 褰撴定鍋滃師鍥犳病鏈夋椂鎵嶅彇绮鹃�夋澘鍧� - keys |= k4 - keys = keys - constant.KPL_INVALID_BLOCKS # log.logger_kpl_debug.info("{}鏈�缁堝叧閿瘝锛歿}", code, keys) @@ -673,18 +740,20 @@ code_limit_up_reasons_dict = {} load_code_block() for block in keys: - can_buy, unique, msg, is_strong = cls.__is_block_can_buy(code, block, current_limit_up_datas, - code_limit_up_reasons_dict, - yesterday_current_limit_up_codes, - limit_up_record_datas, - 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)) + can_buy, unique, msg, is_strong, active_buy_info = cls.__is_block_can_buy(code, block, + current_limit_up_datas, + code_limit_up_reasons_dict, + yesterday_current_limit_up_codes, + limit_up_record_datas, + 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, active_buy_info)) return fresults, keys # 鏄惁鍙互涓嬪崟 # 杩斿洖锛氬彲浠ヤ拱鐨勬澘鍧�,鏄惁鐙嫍,娑堟伅 + # 鍙拱鐨勬澘鍧�, 鏄惁鐙嫍, 娑堟伅, 鍙拱鐨勫己鍔挎澘鍧�, 鍏抽敭璇�, 婵�杩涗拱鐨勬澘鍧� @classmethod def can_buy(cls, code): if constant.TEST: @@ -694,7 +763,7 @@ # return True, "涓嶅垽鏂澘鍧楄韩浣�" return cls.__can_buy_compute_result_dict.get(code) - # 杩斿洖:(鍙互涔扮殑鏉垮潡鍒楄〃, 鏄惁鏄嫭鑻�, 娑堟伅绠�浠�,鍙拱鐨勫己鍔夸富绾�) + # 杩斿洖:(鍙互涔扮殑鏉垮潡鍒楄〃, 鏄惁鏄嫭鑻�, 娑堟伅绠�浠�,鍙拱鐨勫己鍔夸富绾�, 婵�杩涗拱鍏ユ澘鍧楀垪琛�) @classmethod def __compute_can_buy_blocks(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, before_blocks_dict, @@ -755,9 +824,9 @@ can_buy_strong_blocks = [] unique_count = 0 msg_list = [] - + active_buy_blocks = [] for r in blocks_compute_results: - # r鐨勬暟鎹粨鏋�(鏉垮潡,鏄惁鍙互涔�,鏄惁鐙嫍,娑堟伅,鏄惁鏄己鍔挎澘鍧�) + # r鐨勬暟鎹粨鏋�(鏉垮潡,鏄惁鍙互涔�,鏄惁鐙嫍,娑堟伅,鏄惁鏄己鍔挎澘鍧�, 婵�杩涗拱鍏ヤ俊鎭�) if r[2]: # 鐙嫍 unique_count += 1 @@ -776,13 +845,17 @@ can_buy_strong_blocks.append(r[0]) if r[3]: msg_list.append(r[3]) + if r[5][0]: + active_buy_blocks.append(r[0]) + msg_list.append(f"銆恵r[0]}銆戞縺杩涗拱鍏�({r[5][1]})") + else: if r[3]: msg_list.append(r[3]) # 鎵�鏈夋澘鍧楅兘鏄嫭鑻� if unique_count == len(blocks_compute_results): - return can_buy_blocks, True, ",".join(msg_list), can_buy_strong_blocks, keys - return can_buy_blocks, False, ",".join(msg_list), can_buy_strong_blocks, keys + return can_buy_blocks, True, ",".join(msg_list), can_buy_strong_blocks, keys, active_buy_blocks + return can_buy_blocks, False, ",".join(msg_list), can_buy_strong_blocks, keys, active_buy_blocks # 鏇存柊浠g爜鏉垮潡鍒ゆ柇鏄惁鍙互涔扮殑缁撴灉 # high_level_general_code_blocks 楂樹綅娉涘寲鏉垮潡 @@ -817,15 +890,15 @@ 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, - high_level_general_code_blocks) + can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks = 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, + high_level_general_code_blocks) # 淇濆瓨鏉垮潡璁$畻缁撴灉 - cls.__can_buy_compute_result_dict[code] = (can_buy_blocks, unique, msg, can_buy_strong_blocks, keys) + cls.__can_buy_compute_result_dict[code] = (can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks) if __name__ == "__main__": -- Gitblit v1.8.0