From 1c76abc59af35931b70b4742038dae0cfe4890d4 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 18 七月 2023 16:28:18 +0800 Subject: [PATCH] 华鑫适配 --- third_data/code_plate_key_manager.py | 235 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 188 insertions(+), 47 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index c092ff4..1306311 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -6,6 +6,7 @@ import json import constant +from third_data import kpl_block_util from utils import global_util, tool from log_module import log from db import redis_manager @@ -124,9 +125,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: @@ -147,9 +148,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() @@ -212,7 +213,7 @@ return False, None -# +# 浠g爜鍘嗗彶娑ㄥ仠鍘熷洜涓庢澘鍧楃鐞� class CodesHisReasonAndBlocksManager: __redisManager = redis_manager.RedisManager(1) # 鍘嗗彶娑ㄥ仠鍘熷洜 @@ -273,7 +274,7 @@ return reasons | blocks -# 鐩爣浠g爜鍏抽敭璇嶇鐞� +# 鐩爣浠g爜鏉垮潡鍏抽敭璇嶇鐞� class TargetCodePlateKeyManager: __redisManager = redis_manager.RedisManager(1) __CodesPlateKeysManager = CodesHisReasonAndBlocksManager() @@ -287,7 +288,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: @@ -310,22 +311,155 @@ 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, latest_2_day_limit_up_datas, limit_up_record_datas): + 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 + # 鑾峰彇鏉垮潡 keys, k1, k11, k2, k3, k4 = cls.__TargetCodePlateKeyManager.get_plate_keys(code) - log.logger_kpl_debug.info("{}鍏抽敭璇嶏細{},{},{},{},{},{}", code, keys, k1, k11, k2, k3, k4) - # 娑ㄥ仠鍒楄〃涓尮閰嶅叧閿瘝 + log.logger_kpl_debug.info("{}鍏抽敭璇嶏細鎵�鏈�-{},浠婃棩-{},浠婃棩鍘嗗彶-{},鍘嗗彶-{},浜岀骇琛屼笟-{},浠g爜鏉垮潡-{}", code, keys, k1, k11, k2, k3, k4) + # 娑ㄥ仠鍒楄〃涓尮閰嶅叧閿瘝锛岃繑鍥烇紙鏉垮潡:浠g爜闆嗗悎锛夛紝浠g爜闆嗗悎涓凡缁忔帓闄よ嚜韬� 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, "鏈湪娑ㄥ仠鍒楄〃涓湭鍖归厤鍒版定鍋滃師鍥�" + return cls.BLOCK_TYPE_NONE, None, "鏈湪娑ㄥ仠鍒楄〃涓湭鍖归厤鍒版定鍋滃師鍥�" + # 鑾峰彇鏉垮潡褰掔被 + for block in match_limit_up_result: + # 鑾峰彇寮哄娍鏉垮潡 + strong_result = kpl_block_util.is_strong_block(block, current_limit_up_datas, latest_2_day_limit_up_datas) + # 鑾峰彇鐚涙媺鏉垮潡 + soon_limit_up_result = kpl_block_util.is_soon_limit_up(code, block, limit_up_record_datas) + + # 鑾峰彇韬綅 + rank = kpl_block_util.get_code_rank(code, block, limit_up_record_datas) + # 涓绘澘韬綅 + sh_sz_rank = kpl_block_util.get_sh_sz_code_rank(code, block, limit_up_record_datas) + # 鏄惁鍚庢帓 + is_back_row = kpl_block_util.is_back_row(code, block, current_limit_up_datas) + + # 鏄惁婊¤冻甯傚満娴佸叆鍓嶅嚑 + is_in_top_input = RealTimeKplMarketData.is_in_top(set([block]))[0] + + log.logger_kpl_debug.info("{}-{} 鏉垮潡鍒ゆ柇缁撴灉锛氬己鍔挎澘鍧�-{} 鐚涙媺鏉垮潡-{} 韬綅-{} 涓绘澘韬綅-{} 鏄惁鍚庢帓-{} 鏄惁鍦ㄦ祦鍏ュ墠鎺�-{}", code, block, + strong_result, soon_limit_up_result, rank, sh_sz_rank, is_back_row, + is_in_top_input) + + if time_index == 0: + # 09:30:00 - 10:00:00 + if strong_result[0]: + # 寮哄娍鏉垮潡 + # 涔颁富鏉块緳1,2,3,4 涔板悗鎺� + if is_back_row and sh_sz_rank <= 3: + return cls.BLOCK_TYPE_STRONG, block, f"{block} 寮哄娍鏉垮潡:涔颁富鏉块緳1,2,3,4 涔板悗鎺�" + + if soon_limit_up_result[0]: + # 鐚涙媺鏉垮潡 + # 鍙拱榫�2 涔板悗鎺� + if is_back_row and rank == 1: + return cls.BLOCK_TYPE_SOON_LIMIT_UP, block, f"{block} 鐚涙媺鏉垮潡:鍙拱榫�2,涔板悗鎺�" + # 鍏朵粬鏉垮潡 + if is_in_top_input and sh_sz_rank <= 1 and is_back_row: + # 鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺� + return cls.BLOCK_TYPE_COMMON, block, f"{block} 鍏朵粬鏉垮潡:鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺�" + + elif time_index == 1: + # 10:00:00 - 10:30:00 + if strong_result[0]: + # 寮哄娍鏉垮潡 + # 涔颁富鏉块緳1,2,3 涔板悗鎺� + if is_back_row and sh_sz_rank <= 2: + return cls.BLOCK_TYPE_STRONG, block, f"{block} 寮哄娍鏉垮潡:涔颁富鏉块緳1,2,3 涔板悗鎺�" + + if soon_limit_up_result[0]: + # 鐚涙媺鏉垮潡 + # 鍙拱榫�2 涔板悗鎺� + if is_back_row and rank == 1: + return cls.BLOCK_TYPE_SOON_LIMIT_UP, block, f"{block} 鐚涙媺鏉垮潡:鍙拱榫�2,涔板悗鎺�" + # 鍏朵粬鏉垮潡 + if is_in_top_input and sh_sz_rank <= 1 and is_back_row: + # 鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺� + return cls.BLOCK_TYPE_COMMON, block, f"{block} 鍏朵粬鏉垮潡:鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺�" + elif time_index == 2: + # 10:30:00 - 11:00:00 + if strong_result[0]: + # 寮哄娍鏉垮潡 + # 涔颁富鏉块緳1,2 涔板悗鎺� + if is_back_row and sh_sz_rank <= 1: + return cls.BLOCK_TYPE_STRONG, block, f"{block} 寮哄娍鏉垮潡:涔颁富鏉块緳1,2 涔板悗鎺�" + + if soon_limit_up_result[0]: + # 鐚涙媺鏉垮潡 + # 鍙拱榫�2 涔板悗鎺� + if is_back_row and rank == 1: + return cls.BLOCK_TYPE_SOON_LIMIT_UP, block, f"{block} 鐚涙媺鏉垮潡:鍙拱榫�2,涔板悗鎺�" + # 鍏朵粬鏉垮潡 + if is_in_top_input and sh_sz_rank <= 1 and is_back_row: + # 鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺� + return cls.BLOCK_TYPE_COMMON, block, f"{block} 鍏朵粬鏉垮潡:鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺�" + elif time_index == 3: + # 11:00:00 - 13:30:00 + if soon_limit_up_result[0]: + # 鐚涙媺鏉垮潡 + # 鍙拱榫�2 涔板悗鎺� + if is_back_row and rank == 1: + return cls.BLOCK_TYPE_SOON_LIMIT_UP, block, f"{block} 鐚涙媺鏉垮潡:鍙拱榫�2,涔板悗鎺�" + # 鍏朵粬鏉垮潡 + if is_in_top_input and sh_sz_rank <= 1 and is_back_row: + # 鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺� + return cls.BLOCK_TYPE_COMMON, block, f"{block} 鍏朵粬鏉垮潡锛氱湅绮鹃��/琛屼笟娴佸叆,涔伴緳涓绘澘1,2 ,涔板悗鎺�" + elif time_index == 4: + # 13:30:00 - 15:00:00 + if soon_limit_up_result[0]: + # 鐚涙媺鏉垮潡 + # 鍙拱榫�2 涔板悗鎺� + if is_back_row and rank == 1: + return cls.BLOCK_TYPE_SOON_LIMIT_UP, block, f"{block} 鐚涙媺鏉垮潡锛氬彧涔伴緳2,涔板悗鎺�" + # 鍏朵粬鏉垮潡 + if is_in_top_input: + # 绮鹃��/琛屼笟娴佸叆绗﹀悎 + if sh_sz_rank <= 1 and is_back_row: + # 鐪嬬簿閫�/琛屼笟娴佸叆 涔伴緳涓绘澘1,2 涔板悗鎺� + return cls.BLOCK_TYPE_COMMON, block, f"{block} 鍏朵粬鏉垮潡锛氱簿閫�/琛屼笟娴佸叆绗﹀悎,涔伴緳涓绘澘1,2,涔板悗鎺�" + else: + if sh_sz_rank == 0 and not is_back_row: + return cls.BLOCK_TYPE_START_UP, block, f"{block} 鍏朵粬鏉垮潡: 涔颁富鏉块緳1,涔颁富鏉跨嫭鑻�" + + return cls.BLOCK_TYPE_NONE, None, f"鏉垮潡({match_limit_up_result.keys()})涓嶇鍚堜拱鍏ユ潯浠�" + + # 鏄惁鍙互涓嬪崟 + # 杩斿洖锛氭槸鍚﹀彲浠ヤ笅鍗�,娑堟伅,鏉垮潡绫诲瀷 + @classmethod + def can_buy(cls, code, current_limit_up_datas, latest_2_day_limit_up_datas, limit_up_record_datas): + if constant.TEST: + return True, "", cls.BLOCK_TYPE_NONE + block_type, block, block_msg = cls.get_can_buy_block(code, current_limit_up_datas, latest_2_day_limit_up_datas, + limit_up_record_datas) + if block_type == cls.BLOCK_TYPE_NONE: + return False, block_msg, block_type # ---------------------------------鍒ゆ柇鐩爣浠g爜鐨勬澘鍧�-------------------start------------ # 鍒ゆ柇鍖归厤鍑虹殑娑ㄥ仠鍘熷洜锛屽垽鏂槸鍚︽湁宸茬粡涓嬪崟鐨勭エ @@ -358,22 +492,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})) @@ -385,7 +519,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) # 瀹炴椂娑ㄥ仠鍘熷洜 @@ -395,7 +529,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) @@ -403,27 +539,32 @@ # ---------------------------------鍔犺浇宸茬粡涓嬪崟/鎴愪氦鐨勪唬鐮佷俊鎭�------------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, block_type # 鏉垮潡鍙互涓嬪崟鏁伴噺 - 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) + return False, ",".join(msg_list), block_type if __name__ == "__main__": -- Gitblit v1.8.0