From bb2e450c9d0e9d42929ecd6030a1fb65b2034176 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 24 一月 2025 14:33:55 +0800 Subject: [PATCH] bug修复 --- third_data/code_plate_key_manager.py | 160 ++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 121 insertions(+), 39 deletions(-) diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py index 7a08121..1311472 100644 --- a/third_data/code_plate_key_manager.py +++ b/third_data/code_plate_key_manager.py @@ -12,7 +12,7 @@ from db.redis_manager_delegate import RedisUtils from third_data import kpl_block_util, kpl_api, kpl_util from settings.trade_setting import MarketSituationManager -from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager +from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager, ContainsLimitupCodesBlocksManager from third_data.third_blocks_manager import BlockMapManager from utils import global_util, tool, buy_condition_util from log_module import async_log_util @@ -20,7 +20,7 @@ from log_module.log import logger_kpl_block_can_buy, logger_kpl_jx_out, logger_kpl_jx_in, logger_debug from third_data.kpl_util import KPLPlatManager -from trade import trade_manager, l2_trade_util, trade_constant +from trade import l2_trade_util, trade_constant # 浠g爜绮鹃�夋澘鍧楃鐞� from utils.kpl_data_db_util import KPLLimitUpDataUtil @@ -222,8 +222,13 @@ # 寮�鐩樺暒绂佹浜ゆ槗鏉垮潡绠$悊 class KPLPlateForbiddenManager: - __redisManager = redis_manager.RedisManager(3) + """ + 涓嶈兘涔扮殑鏉垮潡绠$悊 + """ + __redis_manager = redis_manager.RedisManager(3) __kpl_forbidden_plates_cache = set() + # 宸茬粡鍒犻櫎浜嗙殑鏉垮潡 + __deleted_kpl_forbidden_plates_cache = set() __instance = None @@ -237,24 +242,45 @@ def __load_datas(cls): __redis = cls.__get_redis() try: - __kpl_forbidden_plates_cache = RedisUtils.smembers(__redis, "kpl_forbidden_plates") + cls.__kpl_forbidden_plates_cache = RedisUtils.smembers(__redis, "kpl_forbidden_plates") + cls.__deleted_kpl_forbidden_plates_cache = RedisUtils.smembers(__redis, "deleted_kpl_forbidden_plates") finally: RedisUtils.realse(__redis) @classmethod def __get_redis(cls): - return cls.__redisManager.getRedis() + return cls.__redis_manager.getRedis() def save_plate(self, plate): self.__kpl_forbidden_plates_cache.add(plate) RedisUtils.sadd(self.__get_redis(), "kpl_forbidden_plates", plate) RedisUtils.expire(self.__get_redis(), "kpl_forbidden_plates", tool.get_expire()) + self.__deleted_kpl_forbidden_plates_cache.discard(plate) + RedisUtils.srem(self.__get_redis(), "deleted_kpl_forbidden_plates", plate) + RedisUtils.expire(self.__get_redis(), "deleted_kpl_forbidden_plates", tool.get_expire()) + + def delete_plate(self, plate): + self.__kpl_forbidden_plates_cache.discard(plate) + RedisUtils.srem(self.__get_redis(), "kpl_forbidden_plates", plate) + RedisUtils.expire(self.__get_redis(), "kpl_forbidden_plates", tool.get_expire()) + self.__deleted_kpl_forbidden_plates_cache.add(plate) + RedisUtils.sadd(self.__get_redis(), "deleted_kpl_forbidden_plates", plate) + RedisUtils.expire(self.__get_redis(), "deleted_kpl_forbidden_plates", tool.get_expire()) + def list_all(self): return RedisUtils.smembers(self.__get_redis(), "kpl_forbidden_plates") def list_all_cache(self): return self.__kpl_forbidden_plates_cache + + def list_all_deleted_cache(self): + return self.__deleted_kpl_forbidden_plates_cache + + def is_in_cache(self, plate): + if self.__kpl_forbidden_plates_cache and plate in self.__kpl_forbidden_plates_cache: + return True + return False class LimitUpCodesPlateKeyManager: @@ -333,7 +359,7 @@ # 瀹炴椂寮�鐩樺暒甯傚満鏁版嵁 class RealTimeKplMarketData: - # 娴佸叆缂撳瓨 + # 娴佸叆缂撳瓨 [ID, 鏉垮潡鍚嶇О, 鏉垮潡娑ㄥ箙, 娴佸叆閲戦] top_in_list_cache = [] # 娴佸嚭缂撳瓨 top_out_list_cache = [] @@ -352,21 +378,39 @@ __top_jx_out_blocks = [] # 绮鹃�夋澘鍧楁祦鍏ラ噾棰� __jx_blocks_in_money_dict = {} + # 甯傚満琛屾儏鐑害锛岄粯璁や负60 + __market_strong = 60 + + @classmethod + def get_jingxuan_in_block_threshold_count(cls): + """ + 鑾峰彇涔扮簿閫夋祦鍏ュ墠鍑� + @return: + """ + score = 60 + if cls.__market_strong is not None: + score = int(cls.__market_strong) + for info in constant.RADICAL_BUY_TOP_IN_COUNT_BY_MARKET_STRONG: + if info[0] <= score < info[1]: + return info[2] + return 10 @classmethod def set_market_jingxuan_blocks(cls, datas): """ 璁剧疆绮鹃�夋祦鍏ユ暟鎹� - @param datas: + @param datas:[(鏉垮潡缂栧彿,鏉垮潡鍚嶇О,娑ㄥ箙, 鏉垮潡娴佸叆閲戦)] @return: """ - # blocks = set() - # 鑰佺増鏈疄鐜版柟寮� - # for data in datas: - # if data[3] <= 0: - # break - # blocks.add(data[1]) - # cls.__top_jx_blocks = blocks + # 娴佸叆闃堝�� + # THRESHOLD_MONEY = 50 * (tool.trade_time_sub(tool.get_now_time_str(), "09:30:00") // 60) + 1000 + # THRESHOLD_MONEY = min(THRESHOLD_MONEY, 10000) + # THRESHOLD_MONEY = max(THRESHOLD_MONEY, 1000) + # THRESHOLD_MONEY = THRESHOLD_MONEY * 10000 + THRESHOLD_MONEY = 0 + # 鏈�澶ф暟閲� + # MAX_COUNT = cls.get_jingxuan_in_block_threshold_count() + cls.top_in_list_cache = datas blocks = set() count = 0 @@ -375,20 +419,38 @@ cls.__jx_blocks_in_money_dict[data[1]] = data[3] if data[1] in constant.KPL_INVALID_BLOCKS: continue - if data[3] < 5e7: + if data[3] < THRESHOLD_MONEY: continue # 杩囨护鍑烘潵涓哄悓涓�涓澘鍧楀氨鍙畻1涓暟閲� fb = BlockMapManager().filter_blocks({data[1]}) if blocks & fb: continue + for b in fb: fblock_money[b] = data[3] blocks |= fb - count += 1 - if count >= 10: - break + + # 濡傛灉璇ュ師鍥犳病鏈夋定鍋滅エ瑕佸線鍚庣Щ涓�浣� + has_code = False + for b in fb: + if ContainsLimitupCodesBlocksManager().get_block_codes(b): + has_code = True + break + if has_code: + count += 1 + if count == 10: + strong = cls.get_market_strong() + if strong is None: + strong = 60 + if data[3] > 3e7: + # 澶т簬3鍗冧竾 + THRESHOLD_MONEY = int((1 - strong / 200) * data[3]) + else: + THRESHOLD_MONEY = data[3] + # if count >= MAX_COUNT: + # break # 璁板綍绮鹃�夋祦鍑烘棩蹇� - async_log_util.info(logger_kpl_jx_in, f"鍘熸暟鎹細{datas[:20]} 鏉垮潡锛歿blocks}") + async_log_util.info(logger_kpl_jx_in, f"鍘熸暟鎹細{datas[:50]} 鏉垮潡锛歿blocks}") blocks = list(blocks) blocks.sort(key=lambda x: fblock_money.get(x), reverse=True) cls.__top_jx_blocks = blocks @@ -423,12 +485,43 @@ cls.__top_jx_out_blocks = list(blocks) @classmethod + def set_market_strong(cls, strong): + """ + 璁剧疆甯傚満琛屾儏寮哄害 + @param strong: + @return: + """ + cls.__market_strong = strong + + @classmethod + def is_ignore_block_in_money(cls): + if cls.__market_strong and cls.__market_strong >= constant.IGNORE_BLOCK_IN_MONEY_MARKET_STRONG: + return True + return False + + @classmethod + def get_market_strong(cls): + return cls.__market_strong + + @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 get_block_info_at_block_in(cls, b): + """ + 鑾峰彇鏉垮潡鐨勫噣娴佸叆鎯呭喌 + @param b: + @return: (鏉垮潡鍚嶇О,韬綅,娴佸叆閲戦) + """ + for i in range(0, len(cls.top_in_list_cache)): + if cls.top_in_list_cache[i][1] == b: + return b, i, cls.top_in_list_cache[i][3] + return b, -1, 0 @classmethod def set_top_5_industry(cls, datas): @@ -660,19 +753,7 @@ __TargetCodePlateKeyManager = TargetCodePlateKeyManager() __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager() __CodesHisReasonAndBlocksManager = CodesHisReasonAndBlocksManager() - __CodesTradeStateManager = trade_manager.CodesTradeStateManager() __can_buy_compute_result_dict = {} - - @classmethod - def __remove_from_l2(cls, code, msg): - # 鏍规嵁韬綅绉婚櫎浠g爜 - # return - # 涓嬭繃鍗曠殑浠g爜涓嶇Щ闄� - if trade_manager.CodesTradeStateManager().get_trade_state_cache(code) != trade_constant.TRADE_STATE_NOT_TRADE: - # 鍙涓嬭繃鍗曠殑灏变笉绉婚櫎 - return - l2_trade_util.forbidden_trade(code, msg=msg) - logger_kpl_block_can_buy.info(msg) # 鏄惁闇�瑕佺Н鏋佷拱 @classmethod @@ -1010,7 +1091,8 @@ @classmethod def __compute_can_buy_blocks(cls, code, current_limit_up_datas, limit_up_record_datas, yesterday_current_limit_up_codes, before_blocks_dict, - current_limit_up_block_codes_dict, high_level_general_code_blocks): + current_limit_up_block_codes_dict, high_level_general_code_blocks, codes_delegate, + codes_success): # 鏍规嵁浠g爜娉涘寲鏉垮潡鑾峰彇娉涘寲鏉垮潡鐨勪唬鐮侀泦鍚� high_level_general_block_codes = {} for c in high_level_general_code_blocks: @@ -1026,10 +1108,7 @@ high_level_general_block_codes) if not blocks_compute_results: return False, True, f"娌℃湁鎵惧埌鏉垮潡", [], keys, [] - codes_delegate = set(cls.__CodesTradeStateManager.get_codes_by_trade_states_cache( - {trade_constant.TRADE_STATE_BUY_DELEGATED, trade_constant.TRADE_STATE_BUY_PLACE_ORDER})) - codes_success = set(cls.__CodesTradeStateManager.get_codes_by_trade_states_cache( - {trade_constant.TRADE_STATE_BUY_SUCCESS})) + codes = codes_delegate | codes_success # 缁熻鎴愪氦浠g爜鐨勬澘鍧� trade_codes_blocks_dict = {} @@ -1108,7 +1187,7 @@ @classmethod def update_can_buy_blocks(cls, code, current_limit_up_datas, limit_up_record_datas, latest_current_limit_up_records, - before_blocks_dict, current_limit_up_block_codes_dict): + before_blocks_dict, current_limit_up_block_codes_dict, delegate_codes, deal_codes): yesterday_current_limit_up_codes = set() yesterday_current_limit_up_records_dict = {} yesterday_current_limit_up_records = latest_current_limit_up_records[0][1] @@ -1142,11 +1221,14 @@ yesterday_current_limit_up_codes, before_blocks_dict, current_limit_up_block_codes_dict, - high_level_general_code_blocks) + high_level_general_code_blocks, + delegate_codes, + deal_codes) # 淇濆瓨鏉垮潡璁$畻缁撴灉 cls.__can_buy_compute_result_dict[code] = ( can_buy_blocks, unique, msg, can_buy_strong_blocks, keys, active_buy_blocks) if __name__ == "__main__": - pass + RealTimeKplMarketData.set_market_strong(120) + print(RealTimeKplMarketData.get_jingxuan_in_block_threshold_count()) -- Gitblit v1.8.0