From 36367e32a8c00cbbacb2cc7f7a09adde3e0cfaa9 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 11 十一月 2024 18:37:32 +0800 Subject: [PATCH] 扫过的单可继续扫/扫了未成交遵循顺位机制/唯一涨停原因的高位板要计算其身位 --- third_data/code_plate_key_manager.py | 372 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 291 insertions(+), 81 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index aeba8a5..64503c2 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -12,17 +12,19 @@ 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.kpl_data_constant import LimitUpDataConstant +from third_data.kpl_data_constant import LimitUpDataConstant, LimitUpCodesBlockRecordManager 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 trade.radical_buy_data_manager import RadicalBuyDataManager, BlockPlaceOrderRecordManager +from trade.trade_data_manager import RadicalBuyDealCodesManager 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 -from log_module.log import logger_kpl_block_can_buy, logger_debug +from log_module.log import logger_kpl_block_can_buy, logger_debug, logger_kpl_jx_out from third_data.kpl_util import KPLPlatManager -from trade import trade_manager, l2_trade_util, trade_constant +from trade import trade_manager, l2_trade_util, trade_constant, radical_buy_data_manager # 浠g爜绮鹃�夋澘鍧楃鐞� from utils.kpl_data_db_util import KPLLimitUpDataUtil @@ -125,6 +127,8 @@ async_log_util.info(logger_kpl_block_can_buy, f"{code}:鑾峰彇鍒扮簿閫夋澘鍧�-{blocks} 鑰楁椂:{int(time.time() - start_time)}s") self.save_jx_blocks(code, blocks, current_limit_up_blocks) + # 璺熼殢绮鹃�夋澘鍧椾竴璧锋洿鏂� + self.load_jx_blocks_radical(code) else: # 杩樻病娑ㄥ仠鐨勯渶瑕佹洿鏂扮簿閫夋澘鍧� 鏇存柊绮鹃�夋澘鍧� if abs(float(buy_1_price) - float(limit_up_price)) >= 0.001: @@ -145,6 +149,8 @@ async_log_util.info(logger_kpl_block_can_buy, f"{code}:鑾峰彇鍒扮簿閫夋澘鍧楋紙鏇存柊锛�-{blocks} 鑰楁椂:{int(time.time() - start_time)}s") self.save_jx_blocks(code, blocks, current_limit_up_blocks) + # 璺熼殢绮鹃�夋澘鍧椾竴璧锋洿鏂� + self.load_jx_blocks_radical(code) elif price_rate > 0.03: # 娣诲姞澶囩敤鏉垮潡 if not self.get_jx_blocks_cache(code, by=True): @@ -153,6 +159,8 @@ 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") + # 璺熼殢绮鹃�夋澘鍧椾竴璧锋洿鏂� + self.load_jx_blocks_radical(code) if price_rate > 0.03: if not self.__code_blocks_for_radical_buy.get(code): @@ -286,12 +294,6 @@ 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): - RedisUtils.sadd(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", from_reason) - RedisUtils.expire(self.__get_redis(), f"kpl_limit_up_reason_his-{code}", tool.get_expire()) - self.__set_total_keys(code) - # 璁剧疆浠g爜鐨勪粖鏃ユ定鍋滃師鍥� def __set_total_keys(self, code): keys = set() @@ -343,11 +345,18 @@ __KPLPlateForbiddenManager = KPLPlateForbiddenManager() __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() __KPLPlatManager = KPLPlatManager() - # 绮鹃�夊墠鍑� + # 绮鹃�夋祦鍏ュ墠鍑� __top_jx_blocks = set() + # 绮鹃�夋祦鍑哄墠鍑� + __top_jx_out_blocks = set() @classmethod def set_market_jingxuan_blocks(cls, datas): + """ + 璁剧疆绮鹃�夋祦鍏ユ暟鎹� + @param datas: + @return: + """ blocks = set() for data in datas: if data[3] <= 0: @@ -356,8 +365,34 @@ cls.__top_jx_blocks = blocks @classmethod + def set_market_jingxuan_out_blocks(cls, datas): + """ + 璁剧疆绮鹃�夋祦鍑烘暟鎹� + @param datas: + @return: + """ + blocks = set() + for i in range(0, len(datas)): + if i >= 10 and int(tool.get_now_time_str().replace(":", "")) < int("100000"): + # 10鐐瑰墠鐪嬪墠10锛屽崄鐐瑰悗涓嶇湅鍓�10 + break + data = datas[i] + if data[3] > 0 - 5e7: + # 杩囨护5鍗冧竾浠ヤ笂鐨� + break + blocks.add(kpl_util.filter_block(data[1])) + + # 璁板綍绮鹃�夋祦鍑烘棩蹇� + async_log_util.info(logger_kpl_jx_out, f"鍘熸暟鎹細{datas[:10]} 鏉垮潡锛歿blocks}") + cls.__top_jx_out_blocks = blocks + + @classmethod def get_top_market_jingxuan_blocks(cls): return cls.__top_jx_blocks + + @classmethod + def get_top_market_jingxuan_out_blocks(cls): + return cls.__top_jx_out_blocks @classmethod def set_top_5_industry(cls, datas): @@ -409,6 +444,14 @@ __history_limit_up_reason_dict = {} # 鏉垮潡 __blocks_dict = {} + + __instance = None + + def __new__(cls, *args, **kwargs): + if not cls.__instance: + cls.__instance = super(CodesHisReasonAndBlocksManager, cls).__new__(cls, *args, **kwargs) + + return cls.__instance def __get_redis(self): return self.__redisManager.getRedis() @@ -492,6 +535,14 @@ except: pass return set() + + def get_history_blocks_cache(self, code): + """ + 鑾峰彇180澶╃殑鍘嗗彶娑ㄥ仠鍘熷洜缂撳瓨 + @param code: + @return: + """ + return self.__history_blocks_dict_cache.get(code) # 鐩爣浠g爜鏉垮潡鍏抽敭璇嶇鐞� @@ -871,7 +922,8 @@ current_limit_up_datas = [] # 鑾峰彇鐩爣浠g爜鏉垮潡 - keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) + # keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) + keys, k1 = RadicalBuyBlockManager.get_code_blocks(code) # log.logger_kpl_debug.info("{}鏈�缁堝叧閿瘝锛歿}", code, keys) @@ -880,6 +932,7 @@ fresults = [] if not keys: return fresults, set() + code_limit_up_reasons_dict = {} load_code_block() for block in keys: @@ -1052,7 +1105,7 @@ class RadicalBuyBlockManager: """ - 婵�杩涗拱鏉垮潡绠$悊 + 鎵叆涔版澘鍧楃鐞� """ __TargetCodePlateKeyManager = TargetCodePlateKeyManager() # 涓婃鐨勬定鍋滀唬鐮� @@ -1124,16 +1177,25 @@ blocks -= constant.KPL_INVALID_BLOCKS # 杩囨护 blocks = BlockMapManager().filter_blocks(blocks) - temp_dict[code] = (kpl_util.get_high_level_count(d[4]), blocks) + # 寮�1鍓旈櫎4鏉夸互涓婄殑 + high_level = kpl_util.get_high_level_count(d[4]) + if high_level >= 4: + continue + temp_dict[code] = (high_level, blocks) + 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, + ignore_open_limit_up=True): """ - 鑾峰彇褰撳墠娑ㄥ仠韬綅 + 鑾峰彇褰撳墠娑ㄥ仠韬綅 @param code: @param block: @param yesterday_limit_up_codes: + @param exclude_codes: + @param limit_up_time: + @param ignore_open_limit_up: 鏄惁蹇界暐寮�1鐨勪唬鐮� @return: 绱㈠紩,鍓嶆帓浠g爜淇℃伅锛圼(浠g爜, 娑ㄥ仠鏃堕棿)]锛� """ if exclude_codes is None: @@ -1141,7 +1203,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: @@ -1149,7 +1212,6 @@ blocks = LimitUpDataConstant.get_blocks_with_history(_code) if not blocks: blocks = set() - blocks = BlockMapManager().filter_blocks(blocks) if _code == code: # 鑾峰彇褰撳墠浠g爜娑ㄥ仠鏃堕棿 limit_up_time = int(k[2]) @@ -1157,10 +1219,15 @@ # 涓嶆槸杩欎釜鏉垮潡 if block not in blocks: continue + + # 鍓旈櫎4鏉夸互涓婄殑鏉� + if kpl_util.get_high_level_count(k[4]) >= 4 and len(blocks) > 1: + continue + if not tool.is_can_buy_code(_code): continue # 鍓旈櫎寮�1鐨勬暟鎹� - if timestamp_start <= int(k[2]) < timestamp_end: + if ignore_open_limit_up and timestamp_start <= int(k[2]) < timestamp_end: continue # 鍓旈櫎楂樹綅鏉� if _code in yesterday_limit_up_codes: @@ -1180,13 +1247,14 @@ return current_index, before_codes_info @classmethod - def __get_history_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None): + def __get_history_index(cls, code, block, yesterday_limit_up_codes, exclude_codes=None, ignore_open_limit_up=True): """ 鑾峰彇鍘嗗彶娑ㄥ仠韬綅 @param code: @param block: - @param current_limit_up_datas: 鏄ㄦ棩娑ㄥ仠浠g爜 - @param current_limit_up_codes: 鐩墠鐨勬定鍋滀唬鐮� + @param yesterday_limit_up_codes: + @param exclude_codes: + @param ignore_open_limit_up: 鏄惁蹇界暐寮�1浠g爜 @return: """ if exclude_codes is None: @@ -1201,19 +1269,23 @@ _code = k[3] if _code in exclude_codes: continue - blocks = LimitUpDataConstant.get_blocks_with_history(_code) - blocks = BlockMapManager().filter_blocks(blocks) if _code == code: # 鑾峰彇褰撳墠浠g爜娑ㄥ仠鏃堕棿 limit_up_time = int(k[5]) continue + + blocks = LimitUpDataConstant.get_blocks_with_history(_code) # 涓嶆槸杩欎釜鏉垮潡 if block not in blocks: continue + # 鍓旈櫎4鏉夸互涓婁笖鏉垮潡鏁伴噺澶т簬1涓� + if kpl_util.get_high_level_count(k[12]) >= 4 and len(blocks) > 1: + continue + if not tool.is_can_buy_code(_code): continue # 鍓旈櫎寮�1鐨勬暟鎹� - if timestamp_start <= int(k[5]) < timestamp_end: + if ignore_open_limit_up and timestamp_start <= int(k[5]) < timestamp_end: continue # 鍓旈櫎楂樹綅鏉� if _code in yesterday_limit_up_codes: @@ -1250,10 +1322,8 @@ """ # 9:45鐐逛箣鍓嶆定鍋滅殑鎵嶈兘涔板叆 # 鑾峰彇褰撳墠浠g爜鐨勬定鍋滄椂闂� - limit_up_timestamp = LimitUpDataConstant.get_first_limit_up_time(code) - if not limit_up_timestamp: - limit_up_timestamp = time.time() - if int(tool.timestamp_format(limit_up_timestamp, "%H%M%S")) > 94500: + limit_up_timestamp = cls.__get_limit_up_timestamp(code) + if tool.get_now_time_as_int() > 100000: return False, "瓒呰繃鐢熸晥鏃堕棿" # 鏍规嵁鏉垮潡鑱氬悎鏁版嵁 open_limit_up_block_codes_dict = {} @@ -1270,40 +1340,107 @@ # ----鑾峰彇鍘嗗彶韬綅---- 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]][ - 0] == 2): + # 鏄惁涓哄己鍔夸簩鏉垮紑1锛氳浠g爜鎵�鏈夌殑鎱ㄥ康蹇呴』閮戒负浜屾澘寮�1涓斿紑1鐨勫彧鑳芥湁浠栬嚜宸� + is_strong_2_level = count == 1 and \ + kpl_data_constant.open_limit_up_code_dict_for_radical_buy[open_limit_up_block_codes[0]][ + 0] == 2 + if is_strong_2_level: + _code = open_limit_up_block_codes[0] + blocks = LimitUpDataConstant.get_blocks_with_history(_code) + if blocks: + # 鎵�鏈夌殑鎱ㄥ康鐨勫紑1浠g爜蹇呴』鍙湁浠栬嚜宸� + for b in blocks: + temp_codes = open_limit_up_block_codes_dict.get(b) + if temp_codes and len(temp_codes) > 1: + is_strong_2_level = False + break + + if count >= 2 or is_strong_2_level: # 寮�濮嬫暟閲忓ぇ浜�2涓垨鑰呭彧鏈変竴涓�2鏉垮紑1 exclude_codes.clear() else: + # 鍙湁涓�涓紑1 # 鑾峰彇鍖呭惈楂樹綅鏉跨殑韬綅 # ----鑾峰彇鍘嗗彶韬綅---- 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]: - # 鍓嶆帓绗竴涓厓绱犳棤鐐告澘 + # 鎺掗櫎绗竴涓潪寮�1鏁版嵁 exclude_codes = {history_before_codes_info[0][0]} else: return False, f"寮�1鏁伴噺锛歿count}锛屽巻鍙�-{history_index + 1} 瀹炴椂-{current_index + 1}" - # 鑾峰彇涓绘澘鐨勮韩浣� + # 鑾峰彇涓绘澘鐨勮韩浣嶏紙宸茬粡鎺掗櫎浜嗗紑1鐨勪唬鐮侊級 history_index, history_before_codes_info = cls.__get_history_index(code, block, yesterday_limit_up_codes, exclude_codes=exclude_codes) + # 杩囨护涓嶆鐨勫師鍥� + history_index, history_before_codes_info = cls.__filter_before_codes(block, history_index, + history_before_codes_info, + yesterday_limit_up_codes) + # 涔伴鏉胯�佸ぇ/鑰佷簩 # 棣栨澘鑰佸ぇ涓嶈兘涔版椂鍙拱鑰佷簩 if history_index > 1: 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], DealAndDelegateWithBuyModeDataManager().get_deal_codes())[0]: + if RadicalBuyDataManager.is_code_can_buy(history_before_codes_info[0][0], + DealAndDelegateWithBuyModeDataManager().get_deal_codes(), + is_refered=True)[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}" + return True, f"寮�1鏁伴噺锛歿count}锛屽墠鎺掍唬鐮佷笉鍙拱锛歿history_before_codes_info[0]}锛屽巻鍙插墠鎺�-{history_before_codes_info}锛屽紑1浠g爜-{open_limit_up_block_codes}" + return True, f"寮�1鏁伴噺锛歿count}锛屽巻鍙�-{history_index + 1} 瀹炴椂-{current_index + 1}锛� 鍓嶆帓浠g爜-{current_before_codes_info}, 寮�1浠g爜-{open_limit_up_block_codes}" + + @classmethod + def __filter_before_codes(cls, block, index, before_codes_info, yesterday_codes): + """ + 杩囨护鍓嶆帓娑ㄥ仠鍘熷洜涓嶆/涓嶇畻韬綅鐨勪唬鐮� + @param code: + @param block:鏉垮潡 + @param index: 鐩爣浠g爜浣嶇疆 + @param before_codes_info: [(浠g爜, 娑ㄥ仠鏃堕棿鎴�)] + @return: 杩囨护涔嬪悗鐨� (index, before_codes_info) + """ + try: + if index == 0 or not before_codes_info: + return index, before_codes_info + temp_index = index + temp_before_codes_info = [] + deal_codes = RadicalBuyDealCodesManager().get_deal_codes() + for b in before_codes_info: + # 褰撲綔鐩爣绁ㄨ幏鍙栨壂鍏ユ澘鍧� + code_ = b[0] + blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code_) + blocks = BlockMapManager().filter_blocks(blocks) + need_delete = False + # 鍒ゆ柇鍘熷洜涓嶆 + if block not in blocks and b[0] not in yesterday_codes: + # 棣栨澘娑ㄥ仠鍘熷洜涓嶆 + need_delete = True + # 鍒ゆ柇鏄惁鏄笉璁$畻韬綅 + if not need_delete: + if radical_buy_data_manager.ExcludeIndexComputeCodesManager.is_in_cache(code_): + need_delete = True + # 鍒ゆ柇鏄笉鏄壂浜嗘病鏈夋壂杩涘叆 + if not need_delete: + if code_ in BlockPlaceOrderRecordManager().get_codes() and code_ not in deal_codes: + need_delete = True + + if need_delete: + temp_index -= 1 + else: + temp_before_codes_info.append(b) + return temp_index, temp_before_codes_info + except Exception as e: + async_log_util.error(logger_debug, f"鎵叆鏉垮潡杩囨护鍑洪敊锛歿str(e)}") + return index, before_codes_info @classmethod def __is_radical_buy_with_block_up(cls, code, block, yesterday_limit_up_codes): @@ -1320,17 +1457,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]: @@ -1338,15 +1475,19 @@ 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')) >= 10 * 60: - return False, f"璺濈涓婁釜浠g爜娑ㄥ仠宸茶繃鍘�10鍒嗛挓锛坽current_before_codes_info[0]}锛�" + return False, f"璺濈涓婁釜浠g爜娑ㄥ仠宸茶繃鍘�10鍒嗛挓锛坽current_before_codes_info[-1]}锛�" - history_index, history_before_codes_info = cls.__get_history_index(code, block, set()) - history_before_codes = [x[0] for x in history_before_codes_info] + # 鍖呭惈楂樹綅鏉跨殑鏁翠綋鎺掑簭 + all_history_index, all_history_before_codes_info = cls.__get_history_index(code, block, set()) + all_history_before_codes = [x[0] for x in all_history_before_codes_info] # 鍓嶄袱涓唬鐮佹槸鍚︽湁鐐告澘 - dif_codes = set(history_before_codes[:2]) - set(current_before_codes[:2]) + dif_codes = set(all_history_before_codes[:2]) - set(current_before_codes[:2]) if dif_codes: - return False, f"鍓�2浠g爜鏈夌偢鏉匡細{dif_codes}" - # 涓嶈绠楀墠2鐨勪唬鐮� + return False, f"鍓�2浠g爜鏈夌偢鏉匡細{dif_codes}, 鍓嶆帓浠g爜锛歿all_history_before_codes}" + # 鍓嶆帓浠g爜鐐告澘涓嶈兘>=2涓� + dif_codes = set(all_history_before_codes) - set(current_before_codes) + if len(dif_codes) >= 2: + return False, f"鏉垮潡鍓嶆帓鏈墈len(dif_codes)}涓偢鏉�" exclude_codes = set() for x in current_before_codes_info: @@ -1365,30 +1506,56 @@ 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, 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]}锛�" + # 杩囨护涓嶆鐨勫師鍥� + history_index, history_before_codes_info = cls.__filter_before_codes(block, history_index, + history_before_codes_info, + yesterday_limit_up_codes) + + # 鑾峰彇鏈澘鍧椾拱鍏ヤ唬鐮佺殑鏈�澶ф暟閲� + 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 RadicalBuyDataManager.is_code_can_buy(pre_code, + DealAndDelegateWithBuyModeDataManager().get_deal_codes(), + is_refered=True)[0]: + return False, f"鍓嶆帓浠g爜鍙拱锛歿pre_code}" + # 鍓嶉潰涓�涓唬鐮佷笉鑳戒拱锛屽墠涓�涓唬鐮佸繀椤讳笌鍓嶅墠涓唬鐮佹定鍋滄椂闂寸浉宸�15鍒嗛挓鍐� + for i in range(len(all_history_before_codes_info) - 1, -1, -1): + if all_history_before_codes_info[i][0] == pre_code: + if tool.trade_time_sub(tool.timestamp_format(all_history_before_codes_info[i][1], '%H:%M:%S'), + tool.timestamp_format(all_history_before_codes_info[i - 1][1], + '%H:%M:%S')) >= 15 * 60: + return False, f"琚『浣嶄唬鐮�({pre_code}) 涓庝笂涓唬鐮佹定鍋滄椂闂�>=15鍒嗛挓 锛坽all_history_before_codes_info[i]}##{all_history_before_codes_info[i - 1]}锛�" + else: + return True, f"琚『浣嶄唬鐮�({pre_code}) 涓庝笂涓唬鐮佹定鍋滄椂闂�<15鍒嗛挓 锛坽all_history_before_codes_info[i]}##{all_history_before_codes_info[i - 1]}锛�" + return False, f"娌℃壘鍒伴『浣嶄唬鐮侊紙{pre_code}锛夌殑鍓嶆帓浠g爜" + else: + # 浠g爜涓虹洰鏍囦唬鐮� + pass + else: + # 浠g爜涓虹洰鏍囦唬鐮� + pass return True, f"婊¤冻涔板叆闇�姹�: 鍓嶆帓浠g爜-{current_before_codes_info}" @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"鏈夊叾浠栫偢鏉�" @@ -1423,12 +1590,24 @@ 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) + keys = TargetCodePlateKeyManager().get_plate_keys(code, contains_today=True) if keys and keys[0]: blocks |= set(keys[0]) return blocks @@ -1440,18 +1619,34 @@ @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 + # 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 + # # 鑾峰彇寮�鐩樺暒鍘嗗彶娑ㄥ仠鍘熷洜 + # kpl_history_blocks = CodesHisReasonAndBlocksManager().get_history_blocks_cache(code) + # if kpl_history_blocks: + # fblocks |= BlockMapManager().filter_blocks(kpl_history_blocks) + # jx_out_blocks = RealTimeKplMarketData.get_top_market_jingxuan_out_blocks() + # if jx_out_blocks: + # fblocks -= jx_out_blocks + # + # return fblocks, match_blocks - return fblocks, match_blocks + # 鏂扮増鏈� + before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) + if not before_fblocks: + before_fblocks = set() + fblocks = BlockMapManager().filter_blocks(before_fblocks) + if fblocks: + fblocks -= constant.KPL_INVALID_BLOCKS + return fblocks, before_fblocks @classmethod def is_radical_buy(cls, code, yesterday_limit_up_codes): @@ -1490,15 +1685,30 @@ 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)) + # 濡傛灉鑳芥壂鍏ュ氨闇�瑕佽幏鍙栦唬鐮佸湪鏉垮潡涓殑韬綅 + # if can_buy_blocks: + # excude_codes = set() + # if kpl_data_constant.open_limit_up_code_dict_for_radical_buy: + # excude_codes |= kpl_data_constant.open_limit_up_code_dict_for_radical_buy.keys() + # # 鍓旈櫎寮�1鐨勪唬鐮� + # for b in keys_: + # history_index, history_before_codes_info = cls.__get_history_index(code, b, yesterday_limit_up_codes, + # excude_codes) + # if history_index >= 4: + # return set(), f"鍦ㄣ�恵b}銆戜腑韬綅({history_index + 1})闈犲悗" return can_buy_blocks, " **** ".join(fmsges) -- Gitblit v1.8.0