From aacc6148dd43a9cffbff9a23a273a55b64bf3d8c Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期六, 12 十月 2024 17:21:42 +0800 Subject: [PATCH] bug修复 --- third_data/code_plate_key_manager.py | 202 +++++++++++++++++++++++++++----------------------- 1 files changed, 110 insertions(+), 92 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index 5521fa7..884d33d 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -12,12 +12,12 @@ from db.redis_manager_delegate import RedisUtils from third_data import kpl_block_util, kpl_api, kpl_util, kpl_data_constant, huaxin_l1_data_manager from settings.trade_setting import MarketSituationManager -from third_data.history_k_data_manager import HistoryKDataManager -from third_data.history_k_data_util import HistoryKDatasUtils from third_data.kpl_data_constant import LimitUpDataConstant from third_data.third_blocks_manager import BlockMapManager, CodeThirdBlocksManager +from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager +from trade.order_statistic import DealAndDelegateWithBuyModeDataManager from trade.radical_buy_data_manager import RedicalBuyDataManager -from utils import global_util, tool, buy_condition_util, init_data_util +from utils import global_util, tool, buy_condition_util from log_module import log, async_log_util from db import redis_manager_delegate as redis_manager @@ -344,31 +344,21 @@ __KPLPlateForbiddenManager = KPLPlateForbiddenManager() __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() __KPLPlatManager = KPLPlatManager() + # 绮鹃�夊墠鍑� + __top_jx_blocks = set() @classmethod - def set_top_5_reasons(cls, datas): - temp_list = [] - for d in datas: - cls.total_reason_dict[d[1]] = d - # 鎺掑簭 - for i in range(0, len(datas)): - if datas[i][1] not in constant.KPL_INVALID_BLOCKS: - # 锛堝悕绉�,鍑�娴佸叆閲戦,鎺掑悕锛� - temp_list.append((datas[i][1], datas[i][3], len(temp_list))) - # 鍙幏鍙栧墠10涓� - if len(temp_list) > 10: - break - if datas[i][3] < 3 * 10000 * 10000: - break + def set_market_jingxuan_blocks(cls, datas): + blocks = set() + for data in datas: + if data[3] <= 0: + break + blocks.add(data[1]) + cls.__top_jx_blocks = blocks - for temp in temp_list: - names = cls.__KPLPlatManager.get_same_plat_names_by_id(temp[0]) - for name in names: - if name == temp[1]: - continue - temp_list.append((name, temp[1], temp[2])) - cls.top_5_reason_list = temp_list - cls.__reset_top_5_dict() + @classmethod + def get_top_market_jingxuan_blocks(cls): + return cls.__top_jx_blocks @classmethod def set_top_5_industry(cls, datas): @@ -400,35 +390,6 @@ def get_can_buy_key_set(cls): temp_set = cls.top_5_key_dict.keys() return temp_set - - # 閫氳繃鍏抽敭瀛楀垽鏂兘涔扮殑浠g爜鏁伴噺 - @classmethod - def get_can_buy_codes_count(cls, code, key): - # 鍒ゆ柇琛屼笟娑ㄥ仠绁ㄦ暟閲忥紝闄ゅ紑鑷繁蹇呴』澶т簬1涓� - temp_codes = LimitUpCodesPlateKeyManager.total_key_codes_dict.get(key) - if temp_codes is None: - temp_codes = set() - else: - temp_codes = set(temp_codes) - temp_codes.discard(code) - if len(temp_codes) < 1: - # 鍚庢帓鎵嶈兘鎸傚崟 - return 0, "韬綅涓嶄负鍚庢帓" - - forbidden_plates = cls.__KPLPlateForbiddenManager.list_all_cache() - if key in forbidden_plates: - return 0, "涓嶄拱璇ユ澘鍧�" - - # 10:30浠ュ墠鍙互鎸�2涓崟 - if int(tool.get_now_time_str().replace(':', '')) < int("100000"): - return 2, "10:00浠ュ墠鍙互鎸�2涓崟" - # 10:30浠ュ悗 - if key not in cls.top_5_key_dict: - return 0, "鍑�娴佸叆娌″湪鍓�5" - if cls.top_5_key_dict[key][1] > 3 * 10000 * 10000: - return 2, "鍑�娴佸叆鍦ㄥ墠5涓斿ぇ浜�3浜�" - else: - return 1, "鍑�娴佸叆鍦ㄥ墠5" @classmethod def is_in_top(cls, keys): @@ -1168,7 +1129,7 @@ kpl_data_constant.open_limit_up_code_dict_for_radical_buy = temp_dict @classmethod - def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None): + def __get_current_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, limit_up_time=None): """ 鑾峰彇褰撳墠娑ㄥ仠韬綅 @param code: @@ -1181,7 +1142,8 @@ current_index = 0 block_codes_infos = [] timestamp_start, timestamp_end = kpl_block_util.open_limit_up_time_range - limit_up_time = time.time() + if limit_up_time is None: + limit_up_time = time.time() for k in LimitUpDataConstant.current_limit_up_datas: _code = k[0] if _code in exclude_codes: @@ -1290,9 +1252,7 @@ """ # 9:45鐐逛箣鍓嶆定鍋滅殑鎵嶈兘涔板叆 # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂� - limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) - if not limit_up_timestamp: - limit_up_timestamp = time.time() + limit_up_timestamp = cls.__get_limit_up_timestamp(code) if int(tool.timestamp_format(limit_up_timestamp, "%H%M%S")) > 94500: return False, "瓒呰繃鐢熸晥鏃堕棿" # 鏍规嵁鏉垮潡鑱氬悎鏁版嵁 @@ -1310,7 +1270,8 @@ # ----鑾峰彇鍘嗗彶韬綅---- history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes) # ----鑾峰彇瀹炴椂韬綅---- - current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes) + current_index, current_before_codes_info = cls.__get_current_index(code, block, yesterday_limit_up_codes, + limit_up_time=limit_up_timestamp) exclude_codes = set() if count >= 2 or ( count == 1 and kpl_data_constant.open_limit_up_code_dict_for_radical_buy[open_limit_up_block_codes[0]][ @@ -1322,7 +1283,8 @@ # ----鑾峰彇鍘嗗彶韬綅---- history_index, history_before_codes_info = cls.__get_history_index(code, block, set()) # ----鑾峰彇瀹炴椂韬綅---- - current_index, current_before_codes_info = cls.__get_current_index(code, block, set()) + current_index, current_before_codes_info = cls.__get_current_index(code, block, set(), + limit_up_time=limit_up_timestamp) if history_before_codes_info and current_before_codes_info and history_before_codes_info[0][0] == \ current_before_codes_info[0][0]: # 鍓嶆帓绗竴涓厓绱犳棤鐐告澘 @@ -1340,7 +1302,8 @@ return False, f"寮�1鏁伴噺锛歿count}锛岄潪寮�1棣栨澘韬綅涓嶅尮閰嶏細鍘嗗彶-{history_index + 1} 瀹炴椂-{current_index + 1}" if history_index == 1: # 褰撳墠浠g爜涓鸿��2锛岃鍒ゆ柇鑰佸ぇ鏄惁鍙拱 - if RedicalBuyDataManager.can_buy(history_before_codes_info[0][0])[0]: + 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}" @@ -1360,17 +1323,17 @@ @param yesterday_limit_up_codes: @return: """ + + # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂� + limit_up_timestamp = cls.__get_limit_up_timestamp(code) + # 鑾峰彇褰撳墠鐨勬澘鍧� - current_index, current_before_codes_info = cls.__get_current_index(code, block, set()) + current_index, current_before_codes_info = cls.__get_current_index(code, block, set(), + limit_up_time=limit_up_timestamp) current_before_codes = [x[0] for x in current_before_codes_info] if len(current_before_codes_info) < 2: return False, f"鍓嶆帓浠g爜灏忎簬2涓細{current_before_codes_info}" - - # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂� - limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) - if not limit_up_timestamp: - limit_up_timestamp = time.time() # 褰撳墠浠g爜寮�1涓嶈兘涔� if limit_up_timestamp < kpl_block_util.open_limit_up_time_range[1]: @@ -1389,7 +1352,7 @@ # 涓嶈绠楀墠2鐨勪唬鐮� exclude_codes = set() - for x in current_before_codes: + for x in current_before_codes_info: if x[1] < kpl_block_util.open_limit_up_time_range[1]: exclude_codes.add(x[0]) # 闄ゅ幓鍓嶄簩浠g爜涓庡紑1浠g爜涔嬪悗鏄惁涓洪鏉胯�佸ぇ锛氭墍鏈夊紑1鐨勮涓�1涓� @@ -1405,20 +1368,28 @@ exclude_codes |= set(open_limit_up_code_dict.keys()) history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes, exclude_codes) - if history_index > 1: - return False, f"鎺掗櫎鍓�2锛岀洰鏍囦唬鐮佷綅浜庡巻鍙茶韩浣�-{history_index + 1}锛屽墠鎺掍唬鐮侊細{history_before_codes_info}" - elif history_index == 1: - # 棣栨澘鑰�2锛屽垽鏂墠闈㈢殑鑰佸ぇ鏄惁鏄睘浜庝笉鑳戒拱鐨勮寖鐣� - pre_code = history_before_codes_info[0][0] - # pre_code涓嶈兘涔帮紝鎵嶈兘涔� - if RedicalBuyDataManager.can_buy(pre_code)[0]: - return False, f"鍓嶆帓浠g爜鍙拱锛歿pre_code}" - # 璺濈鍓嶄竴涓槸鍚﹀湪10鍒嗛挓鍐� - if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'), - tool.timestamp_format(history_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60: - return False, f"璺濈涓婁釜涓嶈兘涔扮殑浠g爜娑ㄥ仠宸茶繃鍘�10鍒嗛挓锛坽history_before_codes_info[0]}锛�" + # 鑾峰彇鏈澘鍧椾拱鍏ヤ唬鐮佺殑鏈�澶ф暟閲� + max_count = RadicalBuyBlockCodeCountManager().get_block_code_count(block) + if history_index > max_count: + return False, f"鎺掗櫎鍓�2锛岀洰鏍囦唬鐮佷綅浜庡巻鍙茶韩浣�-{history_index + 1}锛屽墠鎺掍唬鐮侊細{history_before_codes_info}, 鏉垮潡鏈�澶氬彲涔皗max_count}" + + if max_count == 1: + if history_index == 1: + # 棣栨澘鑰�2锛屽垽鏂墠闈㈢殑鑰佸ぇ鏄惁鏄睘浜庝笉鑳戒拱鐨勮寖鐣� + pre_code = history_before_codes_info[0][0] + # pre_code涓嶈兘涔帮紝鎵嶈兘涔� + if RedicalBuyDataManager.can_buy(pre_code, DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]: + return False, f"鍓嶆帓浠g爜鍙拱锛歿pre_code}" + # 璺濈鍓嶄竴涓槸鍚﹀湪10鍒嗛挓鍐� + if tool.trade_time_sub(tool.timestamp_format(limit_up_timestamp, '%H:%M:%S'), + tool.timestamp_format(history_before_codes_info[-1][1], '%H:%M:%S')) >= 10 * 60: + return False, f"璺濈涓婁釜涓嶈兘涔扮殑浠g爜娑ㄥ仠宸茶繃鍘�10鍒嗛挓锛坽history_before_codes_info[0]}锛�" + else: + # 璺濈涓婁釜浠g爜娑ㄥ仠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"璺濈涓婁釜浠g爜娑ㄥ仠宸茶繃鍘�5鍒嗛挓锛坽current_before_codes_info[-1]}锛�" else: - # 璺濈涓婁釜浠g爜娑ㄥ仠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"璺濈涓婁釜浠g爜娑ㄥ仠宸茶繃鍘�5鍒嗛挓锛坽current_before_codes_info[-1]}锛�" @@ -1427,8 +1398,16 @@ @classmethod def __is_re_limit_up(cls, code, block): + """ + 鏄惁鏄偢鏉垮洖灏佸彲涔� + @param code: + @param block: + @return: + """ # 鑾峰彇韬綅 - current_index, current_before_codes_info = cls.__get_current_index(code, block, set()) + current_index, current_before_codes_info = cls.__get_current_index(code, block, set(), + limit_up_time=cls.__get_limit_up_timestamp( + code)) history_index, history_before_codes_info = cls.__get_history_index(code, block, set()) if current_index != history_index: return False, f"鏈夊叾浠栫偢鏉�" @@ -1463,6 +1442,49 @@ return True, "" @classmethod + def __get_limit_up_timestamp(cls, code): + """ + 鑾峰彇浠g爜鐨勬定鍋滄椂闂达紝榛樿褰撳墠鏃堕棿 + @param code: + @return: + """ + limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) + if not limit_up_timestamp: + limit_up_timestamp = time.time() + return limit_up_timestamp + + @classmethod + def get_code_kpl_blocks(cls, code): + blocks = KPLCodeJXBlockManager().get_jx_blocks_radical(code) + if blocks is None: + blocks = set() + # 灏嗚幏鍙栨定鍋滃師鍥犱笌娑ㄥ仠鎺ㄨ崘 + keys = TargetCodePlateKeyManager().get_plate_keys(code, contains_today=False) + if keys and keys[0]: + blocks |= set(keys[0]) + return blocks + + @classmethod + def get_code_blocks(cls, code): + """ + 鑾峰彇鐩爣浠g爜鐨勬澘鍧� + @param code: + @return: 杩囨护鍚庣殑鏉垮潡,杩囨护鍓嶇殑鏉垮潡 + """ + blocks = cls.get_code_kpl_blocks(code) + match_blocks, info = CodeThirdBlocksManager().get_intersection_blocks_info(code, blocks) + match_blocks -= constant.KPL_INVALID_BLOCKS + fblocks = match_blocks & RealTimeKplMarketData.get_top_market_jingxuan_blocks() + if not fblocks: + fblocks = set() + match_blocks_3, info = CodeThirdBlocksManager().get_intersection_blocks_info(code, blocks, same_count=3) + if match_blocks_3: + match_blocks_3 -= constant.KPL_INVALID_BLOCKS + fblocks |= match_blocks_3 + + return fblocks, match_blocks + + @classmethod def is_radical_buy(cls, code, yesterday_limit_up_codes): """ 鏄惁鏄縺杩涗拱 @@ -1477,14 +1499,7 @@ for c in open_limit_up_code_dict: open_limit_up_blocks |= open_limit_up_code_dict[c][1] # 鑾峰彇浠g爜鐨勬澘鍧� - keys_ = KPLCodeJXBlockManager().get_jx_blocks_radical(code) - if not keys_: - return set(), "娌¤幏鍙栧埌鏉垮潡" - keys_ = BlockMapManager().filter_blocks(keys_) - if not keys_: - return set(), "杩囨护鍚庢病鑾峰彇鍒版澘鍧�" - # 鑾峰彇浜ら泦 - keys_, info = CodeThirdBlocksManager().get_intersection_blocks_info(code, keys_) + keys_, info = cls.get_code_blocks(code) if not keys_: return set(), "娌¤幏鍙栧埌鏉垮潡浜ら泦" @@ -1506,15 +1521,18 @@ result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes) if result[0]: can_buy_blocks.add(b) + msges.append(f"銆恵b}銆�:{result[1]}") fmsges.append("鏉垮潡蹇�熷惎鍔ㄥ垽鏂�##" + ",".join(msges)) if not can_buy_blocks: + msges.clear() for b in keys_: result = cls.__is_re_limit_up(code, b) if result[0]: can_buy_blocks.add(b) - + msges.append(f"銆恵b}銆�:{result[1]}") + fmsges.append("鏉垮潡鍥炲皝鍒ゆ柇##" + ",".join(msges)) return can_buy_blocks, " **** ".join(fmsges) -- Gitblit v1.8.0