From ba52d7ac92a36f413eacaa686f8535e859664ec6 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 28 八月 2023 09:45:11 +0800 Subject: [PATCH] bug修改 --- third_data/code_plate_key_manager.py | 178 +++++++++++++++++++++++++++-------------------------------- 1 files changed, 81 insertions(+), 97 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index 30bed59..74497b6 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -21,28 +21,54 @@ class KPLCodeJXBlockManager: __redisManager = redis_manager.RedisManager(3) __code_blocks = {} + # 澶囩敤 + __code_by_blocks = {} def __get_redis(self): return self.__redisManager.getRedis() - def save_jx_blocks(self, code, blocks): + def save_jx_blocks(self, code, blocks, by=False): if blocks is None: return + if len(blocks) > 2: + blocks = blocks[:2] + # 淇濆瓨鍓�2鏉℃暟鎹� - RedisUtils.setex(self.__get_redis(), f"kpl_jx_blocks-{code}", tool.get_expire(), json.dumps(blocks)) - self.__code_blocks[code] = blocks + if by: + RedisUtils.setex(self.__get_redis(), f"kpl_jx_blocks_by-{code}", tool.get_expire(), json.dumps(blocks)) + self.__code_by_blocks[code] = blocks + else: + RedisUtils.setex(self.__get_redis(), f"kpl_jx_blocks-{code}", tool.get_expire(), json.dumps(blocks)) + self.__code_blocks[code] = blocks # 鑾峰彇绮鹃�夋澘鍧� - def get_jx_blocks(self, code): - if code in self.__code_blocks: - return self.__code_blocks[code] - val = RedisUtils.get(self.__get_redis(), f"kpl_jx_blocks-{code}") - if val is None: - return None + def get_jx_blocks(self, code, by=False): + if by: + if code in self.__code_by_blocks: + return self.__code_by_blocks[code] + val = RedisUtils.get(self.__get_redis(), f"kpl_jx_blocks_by-{code}") + if val is None: + return None + else: + val = json.loads(val) + self.__code_by_blocks[code] = val + return self.__code_by_blocks[code] else: - val = json.loads(val) - self.__code_blocks[code] = val - return self.__code_blocks[code] + if code in self.__code_blocks: + return self.__code_blocks[code] + val = RedisUtils.get(self.__get_redis(), f"kpl_jx_blocks-{code}") + if val is None: + return None + else: + val = json.loads(val) + self.__code_blocks[code] = val + return self.__code_blocks[code] + + def get_jx_blocks_cache(self, code, by=False): + if by: + return self.__code_by_blocks.get(code) + else: + return self.__code_blocks.get(code) # 寮�鐩樺暒绂佹浜ゆ槗鏉垮潡绠$悊 @@ -301,6 +327,10 @@ else: return reasons + def get_history_limit_up_reason_cache(self, code): + reasons = self.__history_limit_up_reason_dict.get(code) + return reasons + def set_blocks(self, code, blocks): self.__blocks_dict[code] = set(blocks) RedisUtils.setex(self.__get_redis(), f"kpl_blocks-{code}", tool.get_expire(), json.dumps(list(blocks))) @@ -347,7 +377,7 @@ k1 = {LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict[code]} # 鍔犺浇浠婃棩鍘嗗彶鍘熷洜,鏆傛椂涓嶉渶瑕佸巻鍙插師鍥犱簡 k11 = set() # RedisUtils.smembers(self.__get_redis(), f"kpl_limit_up_reason_his-{code}") - k2 = self.__CodesPlateKeysManager.get_history_limit_up_reason(code) + k2 = self.__CodesPlateKeysManager.get_history_limit_up_reason_cache(code) if k2 is None: k2 = set() k3 = set() @@ -356,8 +386,11 @@ k3 = {industry} k4 = set() - jingxuan_blocks = self.__KPLCodeJXBlockManager.get_jx_blocks(code) + jingxuan_blocks = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code) + if not jingxuan_blocks: + jingxuan_blocks = self.__KPLCodeJXBlockManager.get_jx_blocks_cache(code, by=True) if jingxuan_blocks: + jingxuan_blocks = jingxuan_blocks[:2] k4 |= set([x[1] for x in jingxuan_blocks]) for k in [k1, k11, k2, k3, k4]: keys |= k @@ -383,6 +416,8 @@ __TargetCodePlateKeyManager = TargetCodePlateKeyManager() __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() __CodesHisReasonAndBlocksManager = CodesHisReasonAndBlocksManager() + __CodesTradeStateManager = trade_manager.CodesTradeStateManager() + __can_buy_compute_result_dict = {} # 鑾峰彇鍙互涔扮殑鏉垮潡 # current_limit_up_datas: 浠婃棩瀹炴椂娑ㄥ仠 @@ -417,10 +452,6 @@ for k in k1: if k not in constant.KPL_INVALID_BLOCKS: keys.add(k) - if not keys: - for k in k2: - if k not in constant.KPL_INVALID_BLOCKS: - keys.add(k) # 濮嬬粓鑾峰彇绮鹃�夋澘鍧� if True: # 鑾峰彇 @@ -440,13 +471,13 @@ can_buy_blocks = [] for block in keys: log.logger_kpl_debug.info(f"鍒ゆ柇鏉垮潡鏄惁鍙拱锛歿block}") - is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas, - yesterday_current_limit_up_codes, 50) - is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas, - yesterday_current_limit_up_codes, 50) - is_top_4 = is_top_8_record and is_top_4_current - msg_list.append(f"\n瀹炴椂top10(娑ㄥ仠鏁伴噺锛歿len(current_limit_up_datas)})") - msg_list.append(f"鍘嗗彶top20(娑ㄥ仠鏁伴噺锛歿len(top_8_record)})") + # is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas, + # yesterday_current_limit_up_codes, 50) + # is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas, + # yesterday_current_limit_up_codes, 50) + # is_top_4 = is_top_8_record and is_top_4_current + # msg_list.append(f"\n瀹炴椂top10(娑ㄥ仠鏁伴噺锛歿len(current_limit_up_datas)})") + # msg_list.append(f"鍘嗗彶top20(娑ㄥ仠鏁伴噺锛歿len(top_8_record)})") # 鑾峰彇涓绘澘瀹炴椂韬綅,鍓旈櫎楂樹綅鏉� current_shsz_rank = kpl_block_util.get_code_current_rank(code, block, current_limit_up_datas, @@ -456,7 +487,7 @@ code_limit_up_reason_dict, yesterday_current_limit_up_codes, shsz=True) # 鑾峰彇涓绘澘鍘嗗彶韬綅 - if is_top_4: + if True: pen_limit_up_codes = kpl_block_util.get_shsz_open_limit_up_codes(code, block, limit_up_record_datas, code_limit_up_reason_dict) if pen_limit_up_codes: @@ -506,68 +537,24 @@ # 鏄惁鍙互涓嬪崟 # 杩斿洖锛氭槸鍚﹀彲浠ヤ笅鍗�,娑堟伅,鏉垮潡绫诲瀷 @classmethod - def can_buy(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, - before_blocks_dict): - if constant.TEST: - return True, cls.BLOCK_TYPE_NONE + def can_buy(cls, code): + # if constant.TEST: + # return True, cls.BLOCK_TYPE_NONE + 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): blocks, block_msg = cls.get_can_buy_block(code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, before_blocks_dict) if not blocks: return False, block_msg - - # ---------------------------------鍒ゆ柇鐩爣浠g爜鐨勬澘鍧�-------------------start------------ - # 鍒ゆ柇鍖归厤鍑虹殑娑ㄥ仠鍘熷洜锛屽垽鏂槸鍚︽湁宸茬粡涓嬪崟鐨勭エ - # reason_need_buy_dict = {} - # for k in match_limit_up_result: - # codes = match_limit_up_result[k] - # final_codes_keys = [keys] - # for code_ in codes: - # temp_key_set = set() - # temp_key_set |= cls.__CodesHisReasonAndBlocksManager.get_total_keys(code_) - # temp = cls.__LimitUpCodesPlateKeyManager.total_code_keys_dict.get(code_) - # if temp: - # temp_key_set |= temp - # # 浜岀骇 - # industry = global_util.code_industry_map.get(code_) - # if industry: - # temp_key_set.add(industry) - # - # final_codes_keys.append(temp_key_set) - # # 姹傚叡鍚岀殑鍏抽敭璇� - # intersection = set(final_codes_keys[0]) - # for s in final_codes_keys: - # intersection &= s - # log.logger_kpl_debug.info("{}鐨勬澘鍧楁眰浜ら泦锛歿}-{}", code, k, intersection) - # - # # 姹傚叕鍏辩殑鏉垮潡鏄惁鍦ㄦ祦鍏ュ墠5涓� - # is_in, valid_keys = RealTimeKplMarketData.is_in_top(intersection) - # if is_in: - # reason_need_buy_dict[k] = (is_in, valid_keys) - # ---------------------------------鍒ゆ柇鐩爣浠g爜鐨勬澘鍧�-------------------end------------ - - # 鑾峰彇鏉垮潡鍙互涓嬪崟鐨勪釜鏁� - # can_buy_codes_count_dict = {} - # - # for key__ in match_limit_up_result: - # can_buy_count, msg = RealTimeKplMarketData.get_can_buy_codes_count(code, key__) - # can_buy_codes_count_dict[key__] = can_buy_count - - # has_available_key = False - # for key in can_buy_codes_count_dict: - # if can_buy_codes_count_dict[key] > 0: - # has_available_key = True - # break - # if not has_available_key: - # return False, f"鍖归厤鍒扮殑銆恵','.join(match_limit_up_result.keys())}銆戞病鍦ㄧ簿閫�/琛屼笟鍙互涔板叆鐨勬澘鍧椾腑" - - # ---------------------------------鍔犺浇宸茬粡涓嬪崟/鎴愪氦鐨勪唬鐮佷俊鎭�------------start------------- - # match_reasons = match_limit_up_result.keys() - # 鍒ゆ柇鍖归厤鍒扮殑鍘熷洜鏄惁宸茬粡鏈変笅鍗�/涔板叆鎴愬姛鐨勪唬鐮� - codes_delegate = set(trade_manager.CodesTradeStateManager().get_codes_by_trade_states_cache( + log.logger_kpl_debug.info(f"{code}:鑾峰彇濮旀墭/涔板叆浠g爜") + codes_delegate = set(cls.__CodesTradeStateManager.get_codes_by_trade_states_cache( {trade_manager.TRADE_STATE_BUY_DELEGATED, trade_manager.TRADE_STATE_BUY_PLACE_ORDER})) - codes_success = set(trade_manager.CodesTradeStateManager().get_codes_by_trade_states_cache( + codes_success = set(cls.__CodesTradeStateManager.get_codes_by_trade_states_cache( {trade_manager.TRADE_STATE_BUY_SUCCESS})) codes = codes_delegate | codes_success @@ -576,11 +563,13 @@ trade_codes_blocks_dict = {} # 宸茬粡鎴愪氦鐨勬澘鍧� trade_success_blocks_count = {} + log.logger_kpl_debug.info(f"{code}:鑾峰彇浠g爜鏉垮潡") for c in codes: keys_, k1_, k11_, k2_, k3_, k4_ = cls.__TargetCodePlateKeyManager.get_plate_keys(c) # 瀹炴椂娑ㄥ仠鍘熷洜 trade_codes_blocks_dict[c] = k1_ | k4_ # 缁熻鏉垮潡涓殑浠g爜 + log.logger_kpl_debug.info(f"{code}:缁熻鏉垮潡涓殑浠g爜") trade_block_codes_dict = {} for c in trade_codes_blocks_dict: for b in trade_codes_blocks_dict[c]: @@ -593,7 +582,7 @@ trade_block_codes_dict[b].add(c) # ---------------------------------鍔犺浇宸茬粡涓嬪崟/鎴愪氦鐨勪唬鐮佷俊鎭�------------end------------- - + log.logger_kpl_debug.info(f"{code}:寮�濮嬭绠楁槸鍚﹀彲浠ヤ拱") msg_list = [] for key in blocks: # 鏉垮潡涓凡缁忔湁鎴愪氦鐨勫氨涓嶄笅鍗曚簡 @@ -603,25 +592,20 @@ msg_list.append(f"銆恵key}銆戜腑宸茬粡鏈墈success_codes_count}涓垚浜や唬鐮�") log.logger_kpl_debug.debug(f"{code}锛氭澘鍧楋紙{key}锛夊凡缁忔湁鎴愪氦銆恵trade_success_blocks_count[key]}銆�") continue - # 10:30浠ュ悗涔�1涓� - if int(tool.get_now_time_str().replace(":", "")) > int("103000") and success_codes_count >= 1: - msg_list.append(f"銆恵key}銆戜腑宸茬粡鏈墈success_codes_count}涓垚浜や唬鐮�") - log.logger_kpl_debug.debug(f"{code}锛氭澘鍧楋紙{key}锛夊凡缁忔湁鎴愪氦銆恵trade_success_blocks_count[key]}銆�") - continue return True, block_msg - # 鏉垮潡鍙互涓嬪崟鏁伴噺 - # if trade_block_codes_dict.get(key) is None or len(trade_block_codes_dict.get(key)) < \ - # can_buy_codes_count_dict[key]: - # order_count = len(trade_block_codes_dict.get(key)) if key in trade_block_codes_dict else 0 - # logger_kpl_block_can_buy.info( - # f"code={code}锛氥�恵key}銆戝彲浠ヤ笅鍗曪紝鐜版湁鏁伴噺锛歿order_count} 鏈�澶ф暟閲忥細{can_buy_codes_count_dict[key]}") - # return True, f"鍙互涓嬪崟锛屾澘鍧�:銆恵key}銆�,鏉垮潡涓凡缁忎笅鍗曠殑鏁伴噺锛歿order_count}" - # else: - # order_count = len(trade_block_codes_dict.get(key)) - # msg_list.append(f"銆恵key}銆戜腑涓嬪崟浠g爜鏁伴噺{order_count}/鍏佽涓嬪崟鏁伴噺{can_buy_codes_count_dict[key]}") return False, ",".join(msg_list) + @classmethod + def update_can_buy_blocks(cls, code, current_limit_up_datas, limit_up_record_datas, + yesterday_current_limit_up_codes, + before_blocks_dict): + can_buy, msg = cls.__compute_can_buy_blocks(code, current_limit_up_datas, limit_up_record_datas, + yesterday_current_limit_up_codes, + before_blocks_dict) + # 淇濆瓨鏉垮潡璁$畻缁撴灉 + cls.__can_buy_compute_result_dict[code] = (can_buy, msg) + if __name__ == "__main__": pass -- Gitblit v1.8.0