From 0e68e24f54db11d340785b17570fff2bc5fc7ac6 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 24 七月 2023 13:05:16 +0800 Subject: [PATCH] bug修复 --- third_data/code_plate_key_manager.py | 231 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 173 insertions(+), 58 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index f7a9e9c..cb77e22 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -6,12 +6,12 @@ import json import constant -import global_util -import log -import tool +from third_data import kpl_block_util +from utils import global_util, tool +from log_module import log from db import redis_manager -from log import logger_kpl_limit_up, logger_kpl_block_can_buy +from log_module.log import logger_kpl_limit_up, logger_kpl_block_can_buy, logger_kpl_debug from third_data.kpl_util import KPLPlatManager from trade import trade_manager @@ -66,12 +66,14 @@ self.__get_redis().expire(f"kpl_limit_up_reason_his-{code}", tool.get_expire()) self.__set_total_keys(code) + # 璁剧疆浠g爜鐨勪粖鏃ユ定鍋滃師鍥� def __set_total_keys(self, code): keys = set() - keys_his = self.__get_redis().smembers(f"kpl_limit_up_reason_his-{code}") - keys |= keys_his + # keys_his = self.__get_redis().smembers(f"kpl_limit_up_reason_his-{code}") + # keys |= keys_his if code in self.today_limit_up_reason_dict: - keys.add(self.today_limit_up_reason_dict.get(code)) + if self.today_limit_up_reason_dict.get(code) not in constant.KPL_INVALID_BLOCKS: + keys.add(self.today_limit_up_reason_dict.get(code)) self.total_code_keys_dict[code] = keys for k in keys: if k not in self.total_key_codes_dict: @@ -79,6 +81,8 @@ self.total_key_codes_dict[k].add(code) logger_kpl_limit_up.info("{}鏉垮潡鍏抽敭璇�:{}", code, keys) + + # 鏍规嵁浼犲叆鐨勫叧閿瘝涓庢定鍋滀唬鐮佷俊鎭尮閰嶈韩浣� def get_codes_by_key_without_mine(self, key, code): # 鍙瘮杈冧粖鏃ユ定鍋滃師鍥� @@ -125,9 +129,9 @@ # 锛堝悕绉�,鍑�娴佸叆閲戦,鎺掑悕锛� temp_list.append((datas[i][1], datas[i][3], len(temp_list))) # 鍙幏鍙栧墠10涓� - if len(temp_list) > 5: + if len(temp_list) > 10: break - if datas[i][3] < 1 * 10000 * 10000: + if datas[i][3] < 3 * 10000 * 10000: break for temp in temp_list: @@ -148,9 +152,9 @@ if datas[i][1] in constant.KPL_INVALID_BLOCKS: continue temp_list.append((datas[i][1], datas[i][2], len(temp_list))) - if len(temp_list) > 5: + if len(temp_list) > 10: break - if datas[i][2] < 1 * 10000 * 10000: + if datas[i][2] < 3 * 10000 * 10000: break cls.top_5_industry_list = temp_list cls.__reset_top_5_dict() @@ -213,7 +217,7 @@ return False, None -# +# 浠g爜鍘嗗彶娑ㄥ仠鍘熷洜涓庢澘鍧楃鐞� class CodesHisReasonAndBlocksManager: __redisManager = redis_manager.RedisManager(1) # 鍘嗗彶娑ㄥ仠鍘熷洜 @@ -227,9 +231,9 @@ def set_history_limit_up_reason(self, code, reasons): self.__history_limit_up_reason_dict[code] = set(reasons) self.__get_redis().setex(f"kpl_his_limit_up_reason-{code}", tool.get_expire(), json.dumps(list(reasons))) + logger_kpl_debug.debug(f"璁剧疆鍘嗗彶娑ㄥ仠鍘熷洜锛歿code}-{reasons}") - # 濡傛灉杩斿洖鍊间笉涓篘one琛ㄧず宸茬粡鍔犺浇杩囧巻鍙插師鍥犱簡 - + # 濡傛灉杩斿洖鍊间笉涓篘one琛ㄧず宸茬粡鍔犺浇杩囧巻鍙插師鍥犱簡 def get_history_limit_up_reason(self, code): reasons = self.__history_limit_up_reason_dict.get(code) if reasons is None: @@ -274,7 +278,7 @@ return reasons | blocks -# 鐩爣浠g爜鍏抽敭璇嶇鐞� +# 鐩爣浠g爜鏉垮潡鍏抽敭璇嶇鐞� class TargetCodePlateKeyManager: __redisManager = redis_manager.RedisManager(1) __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() @@ -288,7 +292,7 @@ k1 = set() if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict: k1 = {LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict[code]} - # 鍔犺浇鍘嗗彶鍘熷洜 + # 鍔犺浇浠婃棩鍘嗗彶鍘熷洜 k11 = self.__get_redis().smembers(f"kpl_limit_up_reason_his-{code}") k2 = self.__CodesPlateKeysManager.get_history_limit_up_reason(code) if k2 is None: @@ -311,22 +315,126 @@ class CodePlateKeyBuyManager: + # 鏃犳澘鍧� + BLOCK_TYPE_NONE = -1 + # 涓�鑸澘鍧� + BLOCK_TYPE_COMMON = 0 + # 寮哄娍鏉垮潡 + BLOCK_TYPE_STRONG = 1 + # 鐚涙媺鏉垮潡 + BLOCK_TYPE_SOON_LIMIT_UP = 2 + # 娼滀紡鏉垮潡 + BLOCK_TYPE_START_UP = 3 + __TargetCodePlateKeyManager = TargetCodePlateKeyManager() __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() __CodesHisReasonAndBlocksManager = CodesHisReasonAndBlocksManager() - # 鏄惁鍙互涓嬪崟 + # 鑾峰彇鍙互涔扮殑鏉垮潡 + # current_limit_up_datas: 浠婃棩瀹炴椂娑ㄥ仠 + # latest_2_day_limit_up_datas锛氭渶杩�2澶╃殑瀹炴椂娑ㄥ仠锛堜笉鍚粖鏃ワ級 + # limit_up_record_datas锛氫粖鏃ュ巻鍙叉定鍋� @classmethod - def can_buy(cls, code): - if constant.TEST: - return True, "" + def get_can_buy_block(cls, code, current_limit_up_datas, limit_up_record_datas, + before_blocks_dict): + # 鍔犺浇娑ㄥ仠浠g爜鐨勭洰鏍囨澘鍧� + def load_code_block(): + for d in limit_up_record_datas: + if d[2] in constant.KPL_INVALID_BLOCKS and d[3] in before_blocks_dict: + code_limit_up_reason_dict[d[3]] = list(before_blocks_dict.get(d[3]))[0] + else: + code_limit_up_reason_dict[d[3]] = d[2] + return code_limit_up_reason_dict + + now_time = int(tool.get_now_time_str().replace(":", "")) + times = [100000, 103000, 110000, 133000, 150000] + time_index = 0 + for i in range(len(times)): + if now_time < times[i]: + time_index = i + break + # 鑾峰彇鐩爣浠g爜鏉垮潡 keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) - log.logger_kpl_debug.info("{}鍏抽敭璇嶏細{},{},{},{},{},{}", code, keys, k1, k11, k2, k3, k4) - # 娑ㄥ仠鍒楄〃涓尮閰嶅叧閿瘝 - match_limit_up_result = cls.__LimitUpCodesPlateKeyManager.match_limit_up_reason_keys(code, keys) - log.logger_kpl_debug.info("{}鍏抽敭璇嶈韩浣嶅尮閰嶇粨鏋滐細{}", code, match_limit_up_result) - if not match_limit_up_result: - return False, "鏈湪娑ㄥ仠鍒楄〃涓湭鍖归厤鍒版定鍋滃師鍥�" + 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 not keys: + for k in k2: + if k not in constant.KPL_INVALID_BLOCKS: + keys.add(k) + if not keys: + if k3: + keys |= k3 + log.logger_kpl_debug.info("{}鏈�缁堝叧閿瘝锛歿}", code, keys) + + # 娑ㄥ仠鍒楄〃涓尮閰嶅叧閿瘝锛岃繑鍥烇紙鏉垮潡:浠g爜闆嗗悎锛夛紝浠g爜闆嗗悎涓凡缁忔帓闄よ嚜韬� + if not keys: + return cls.BLOCK_TYPE_NONE, None, "灏氭湭鎵惧埌娑ㄥ仠鍘熷洜" + code_limit_up_reason_dict = {} + load_code_block() + msg_list = [] + for block in keys: + is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas, 8) + is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas, 4) + is_top_4 = is_top_8_record and is_top_4_current + msg_list.append(f"瀹炴椂top4: {top_4_current}") + msg_list.append(f"鍘嗗彶top8: {top_8_record}") + + # 鑾峰彇涓绘澘瀹炴椂韬綅 + current_shsz_rank = kpl_block_util.get_code_current_rank(code, block, current_limit_up_datas, + code_limit_up_reason_dict, shsz=True) + record_shsz_rank = kpl_block_util.get_code_record_rank(code, block, limit_up_record_datas, + code_limit_up_reason_dict, shsz=True) + # 鑾峰彇涓绘澘鍘嗗彶韬綅 + if is_top_4: + is_open_limit_up, msg = kpl_block_util.is_shsz_open_limit_up(code, block, limit_up_record_datas, + code_limit_up_reason_dict) + if is_open_limit_up: + # 涓绘澘寮�1 + if current_shsz_rank < 2 and record_shsz_rank < 2: + # 灞炰簬榫�1,榫�2 + return block, f"{block}锛歵op4娑ㄥ仠鏉垮潡锛屼富鏉垮紑1,灞炰簬榫�1/榫�2(瀹炴椂韬綅-{current_shsz_rank})" + else: + msg_list.append( + f"鏉垮潡-{block}: top4娑ㄥ仠鏉垮潡锛屼富鏉垮紑1锛坽msg}锛�,涓嶄负涓绘澘榫�1榫�2锛堝疄鏃惰韩浣�-{current_shsz_rank},鍘嗗彶韬綅-{record_shsz_rank}锛�") + continue + else: + if current_shsz_rank == 0 and record_shsz_rank < 2: + return block, f"{block}锛歵op4娑ㄥ仠鏉垮潡锛岄潪涓绘澘寮�1锛屽睘浜庨緳1" + else: + msg_list.append( + f"鏉垮潡-{block}: top4娑ㄥ仠鏉垮潡锛岄潪涓绘澘寮�1,涓嶄负涓绘澘榫�1锛堝疄鏃惰韩浣�-{current_shsz_rank},鍘嗗彶韬綅-{record_shsz_rank}锛�") + continue + else: + # 鏄惁婊¤冻琛屼笟绮鹃�夋祦鍏ヨ姹� + is_in_top_input = RealTimeKplMarketData.is_in_top(set([block]))[0] + if not is_in_top_input: + msg_list.append( + f"鏉垮潡-{block}: 闈瀟op4娑ㄥ仠鏉垮潡锛屼笉婊¤冻绮鹃��/琛屼笟娴佸叆瑕佹眰") + continue + else: + # 鏄惁涓轰富鏉块緳1锛堝疄鏃堕緳1锛屽巻鍙查緳2浠ュ唴锛� + if current_shsz_rank == 0 and record_shsz_rank < 2: + return block, f"{block}锛氫笉鏄痶op4娑ㄥ仠鏉垮潡锛屾弧瓒崇簿閫�/琛屼笟娴佸叆瑕佹眰锛屾弧瓒充富鏉块緳1" + else: + msg_list.append( + f"鏉垮潡-{block}: 涓嶆槸top4娑ㄥ仠鏉垮潡锛屾弧瓒崇簿閫�/琛屼笟娴佸叆瑕佹眰,涓嶄负涓绘澘榫�1锛堝疄鏃惰韩浣�-{current_shsz_rank},鍘嗗彶韬綅-{record_shsz_rank}锛�") + continue + return None, "\r\n".join(msg_list) + + # 鏄惁鍙互涓嬪崟 + # 杩斿洖锛氭槸鍚﹀彲浠ヤ笅鍗�,娑堟伅,鏉垮潡绫诲瀷 + @classmethod + def can_buy(cls, code, current_limit_up_datas, limit_up_record_datas, before_blocks_dict): + if constant.TEST: + return True, "", cls.BLOCK_TYPE_NONE + block, block_msg = cls.get_can_buy_block(code, current_limit_up_datas, + limit_up_record_datas, before_blocks_dict) + if block is None: + return False, block_msg # ---------------------------------鍒ゆ柇鐩爣浠g爜鐨勬澘鍧�-------------------start------------ # 鍒ゆ柇鍖归厤鍑虹殑娑ㄥ仠鍘熷洜锛屽垽鏂槸鍚︽湁宸茬粡涓嬪崟鐨勭エ @@ -359,22 +467,22 @@ # ---------------------------------鍒ゆ柇鐩爣浠g爜鐨勬澘鍧�-------------------end------------ # 鑾峰彇鏉垮潡鍙互涓嬪崟鐨勪釜鏁� - can_buy_codes_count_dict = {} + # 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 - 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())}銆戞病鍦ㄧ簿閫�/琛屼笟鍙互涔板叆鐨勬澘鍧椾腑" + # 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() + # match_reasons = match_limit_up_result.keys() # 鍒ゆ柇鍖归厤鍒扮殑鍘熷洜鏄惁宸茬粡鏈変笅鍗�/涔板叆鎴愬姛鐨勪唬鐮� codes_delegate = set(trade_manager.get_codes_by_trade_states( {trade_manager.TRADE_STATE_BUY_DELEGATED, trade_manager.TRADE_STATE_BUY_PLACE_ORDER})) @@ -386,7 +494,7 @@ # 缁熻鎴愪氦浠g爜鐨勬澘鍧� trade_codes_blocks_dict = {} # 宸茬粡鎴愪氦鐨勬澘鍧� - trade_success_blocks = set() + trade_success_blocks_count = {} for c in codes: keys_, k1_, k11_, k2_, k3_, k4_ = cls.__TargetCodePlateKeyManager.get_plate_keys(c) # 瀹炴椂娑ㄥ仠鍘熷洜 @@ -396,7 +504,9 @@ for c in trade_codes_blocks_dict: for b in trade_codes_blocks_dict[c]: if c in codes_success: - trade_success_blocks.add(b) + if b not in trade_success_blocks_count: + trade_success_blocks_count[b] = set() + trade_success_blocks_count[b].add(c) if b not in trade_block_codes_dict: trade_block_codes_dict[b] = set() trade_block_codes_dict[b].add(c) @@ -404,25 +514,30 @@ # ---------------------------------鍔犺浇宸茬粡涓嬪崟/鎴愪氦鐨勪唬鐮佷俊鎭�------------end------------- msg_list = [] - for key in can_buy_codes_count_dict: - log.logger_kpl_debug.debug(f"{code}锛氭澘鍧楀彲浠ヤ笅鍗曠殑鏁伴噺銆恵key}銆�-{can_buy_codes_count_dict[key]}") - if can_buy_codes_count_dict[key] < 1: - continue + for key in [block]: # 鏉垮潡涓凡缁忔湁鎴愪氦鐨勫氨涓嶄笅鍗曚簡 - if key in trade_success_blocks: - msg_list.append(f"銆恵key}銆戜腑宸茬粡鏈夋垚浜や唬鐮�") - log.logger_kpl_debug.debug(f"{code}锛氭澘鍧楀凡缁忔湁鎴愪氦銆恵key}銆�") - continue + if key in trade_success_blocks_count: + success_codes_count = len(trade_success_blocks_count[key]) + if success_codes_count >= 2: + 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]}") + # 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) -- Gitblit v1.8.0