From ae8d76a456b64c1c6c4ebf11b6ec33b7df217b1a Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 18 八月 2025 13:43:46 +0800 Subject: [PATCH] bug修复 --- third_data/custom_block_in_money_manager.py | 197 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 188 insertions(+), 9 deletions(-) diff --git a/third_data/custom_block_in_money_manager.py b/third_data/custom_block_in_money_manager.py index 22f0fd6..f0d7a12 100644 --- a/third_data/custom_block_in_money_manager.py +++ b/third_data/custom_block_in_money_manager.py @@ -2,36 +2,91 @@ 鑷畾涔夋澘鍧楁祦鍏ラ噾棰� """ import copy +import itertools +import os import constant +import l2_data_util +from db import mysql_data_delegate as mysql_data from huaxin_client import l1_subscript_codes_manager from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager from third_data.third_blocks_manager import BlockMapManager -from utils import tool +from utils import tool, global_util @tool.singleton class CodeInMoneyManager: def __init__(self): + # 鎬荤殑鍑�娴佸叆 self.__code_money_dict = {} + # 鎬讳拱鍗曚俊鎭細{"code":[閲戦, 鏁伴噺]} + self.__code_buy_money_dict = {} + # 鎬诲崠鍗曚俊鎭細{"code":[閲戦, 鏁伴噺]} + self.__code_sell_money_dict = {} + + # 鍑�娴佸叆澶у崟涔伴噾棰� + self.__code_big_buy_money_list_dict = {} + # 鍑�娴佸嚭澶у崟鍗栭噾棰� + self.__code_big_sell_money_list_dict = {} + self.__latest_price = {} self.__load_data() def __load_data(self): - with open(f"{constant.get_path_prefix()}\\logs\\huaxin_local\\l2\\upload.{tool.get_now_date_str()}.log") as f: - lines = f.readlines() - for line in lines: - line = line.split(" - ")[1] - item = eval(line) - self.add_data(item) + _path = f"{constant.get_path_prefix()}/logs/huaxin_local/l2/transaction_big_order.{tool.get_now_date_str()}.log" + if os.path.exists(_path): + with open(_path) as f: + lines = f.readlines() + for line in lines: + line = line.split(" - ")[1] + item = eval(line) + self.add_data(item) def add_data(self, item): + """ + 娣诲姞鏁版嵁 + @param item: (浠g爜,绫诲瀷, 璁㈠崟鏁版嵁) 璁㈠崟鏁版嵁锛�(璁㈠崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�) + @return: + """ code = item[0] if code not in self.__code_money_dict: self.__code_money_dict[code] = 0 + + if code not in self.__code_buy_money_dict: + self.__code_buy_money_dict[code] = [0, 0] + + if code not in self.__code_sell_money_dict: + self.__code_sell_money_dict[code] = [0, 0] + + if not tool.is_ge_code(code): + big_money = l2_data_util.get_big_money_val(item[2][4]) + if item[2][2] < big_money: + # 涓嶆槸甯歌瀹氫箟鐨勫ぇ鍗曞氨杩斿洖 + return + if tool.is_ge_code(code) and item[2][2] < 299e4 and item[2][1] < 290000: + return if item[1] == 0: + # item[2]鐨勬暟鎹粨鏋勶細 (涔板崟鍙�, 閲�, 閲戦, 鏃堕棿, 鏈�鏂版垚浜や环鏍�) self.__code_money_dict[code] += item[2][2] + self.__code_buy_money_dict[code][0] += item[2][2] + self.__code_buy_money_dict[code][1] += 1 + + if code not in self.__code_big_buy_money_list_dict: + self.__code_big_buy_money_list_dict[code] = [] + # 澶т拱鍗曚俊鎭細(閲戦, 鏈�鏂颁环鏍�, 璁㈠崟鍙�) + if len(item[2]) >= 5: + self.__code_big_buy_money_list_dict[code].append((item[2][2], item[2][4], item[2][0])) else: self.__code_money_dict[code] -= item[2][2] + self.__code_sell_money_dict[code][0] += item[2][2] + self.__code_sell_money_dict[code][1] += 1 + # 澶у崠鍗曚俊鎭� + if code not in self.__code_big_sell_money_list_dict: + self.__code_big_sell_money_list_dict[code] = [] + if len(item[2]) >= 5: + # 澶у崠鍗曚俊鎭細(閲戦, 鏈�鏂颁环鏍�, 璁㈠崟鍙�) + self.__code_big_sell_money_list_dict[code].append((item[2][2], item[2][4], item[2][0])) + + self.__latest_price[code] = item[2][4] def get_code_money_dict(self): return self.__code_money_dict @@ -41,8 +96,36 @@ return self.__code_money_dict.get(code) return 0 + def get_money_info(self, code): + """ + 鑾峰彇浠g爜娴佸叆淇℃伅 + @param code: 浠g爜淇℃伅 + @return: 鍑�娴佸叆閲戦,[澶у崟涔伴噾棰�, 澶у崟涔版暟閲廬,[澶у崟鍗栭噾棰�,澶у崟鍗栨暟閲廬 + """ + return self.__code_money_dict.get(code), self.__code_buy_money_dict.get(code), self.__code_sell_money_dict.get( + code) + def set_money(self, code, money): self.__code_money_dict[code] = money + + def get_big_buy_money_list(self, code): + """ + 鑾峰彇浠g爜鐨勫ぇ涔板崟鍒楄〃 + @param code: + @return:[(閲戦, 浠锋牸, 璁㈠崟鍙�)] + """ + return self.__code_big_buy_money_list_dict.get(code) + + def get_big_sell_money_list(self, code): + """ + 鑾峰彇浠g爜鐨勫ぇ涔板崟鍒楄〃 + @param code: + @return:[(閲戦, 浠锋牸, 璁㈠崟鍙�)] + """ + return self.__code_big_sell_money_list_dict.get(code) + + def get_latest_price(self, code): + return self.__latest_price.get(code) @tool.singleton @@ -50,11 +133,15 @@ """ 鏉垮潡娴佸叆娴佸嚭绠$悊 """ - + __mysql_db = mysql_data.Mysqldb() __code_blocks = {} __in_list = [] __out_list = [] + # 鏈�杩戣繖娈垫椂闂寸殑浠g爜娑ㄥ仠娆℃暟 + __history_code_limit_up_count = {} + # 琚帓闄ょ殑浠g爜 + __exclude_codes = set() def __load_codes(self): codes = [] @@ -76,9 +163,59 @@ fblocks -= constant.KPL_INVALID_BLOCKS self.__code_blocks[code] = fblocks + def __load_exclude_codes(self): + """ + 鑾峰彇涔嬪墠4涓氦鏄撴棩鐨勬暟鎹� + @return: + """ + max_day = tool.get_now_date_str() + min_day = tool.date_sub(max_day, 30) + sql = f"select * from (select distinct(r.`_day`) as 'day' from `kpl_limit_up_record` r where r.`_day`<'{max_day}' and r.`_day`>'{min_day}') a order by a.day desc limit 4" + results = self.__mysql_db.select_all(sql) + dates = [r[0] for r in results] + # 鑾峰彇涔嬪墠4澶╂定鍋滄鏁�>=2娆$殑浠g爜 + day_codes = {} + for day in dates: + sql = f"select distinct(r._code) from kpl_limit_up_record r where r.`_day`='{day}'" + results = self.__mysql_db.select_all(sql) + day_codes[day] = set([x[0] for x in results]) + codes_list = [day_codes[k] for k in day_codes] + # 缁熻浠g爜鐨勬定鍋滃ぉ鏁� + code_limit_up_count_dict = {} + for codes in codes_list: + for c in codes: + if c not in code_limit_up_count_dict: + code_limit_up_count_dict[c] = 0 + code_limit_up_count_dict[c] += 1 + self.__history_code_limit_up_count = code_limit_up_count_dict + self.load_today_limit_up_codes() + + def load_today_limit_up_codes(self): + # 鍔犺浇浠婃棩娑ㄥ仠浠g爜 + day = tool.get_now_date_str() + sql = f"select distinct(r._code) from kpl_limit_up_record r where r.`_day`='{day}'" + results = self.__mysql_db.select_all(sql) + codes = set([x[0] for x in results]) + # 璁$畻闇�瑕佹帓闄ょ殑浠g爜 + temp_limit_up_count = {} + # 缁熻鎬诲叡娑ㄥ仠澶╂暟 + for c in self.__history_code_limit_up_count: + if c in codes: + temp_limit_up_count[c] = self.__history_code_limit_up_count[c] + 1 + else: + temp_limit_up_count[c] = self.__history_code_limit_up_count[c] + exclude_codes = set() + for c in temp_limit_up_count: + if temp_limit_up_count[c] < 3: + continue + exclude_codes.add(c) + self.__exclude_codes = exclude_codes + def __init__(self): self.codes = self.__load_codes() self.__load_blocks() + self.__load_exclude_codes() + print("鎺掗櫎鐨勪唬鐮�", self.__exclude_codes) def get_codes(self): return self.codes @@ -87,9 +224,18 @@ codes = self.codes block_money = {} for code in codes: + if code in self.__exclude_codes: + continue money = CodeInMoneyManager().get_money(code) if money is None: continue + # 澶ц嚜鐢辨祦閫氬競鍊肩殑娴佸嚭涓嶇畻 + if money < 0: + price = CodeInMoneyManager().get_latest_price(code) + zylt_volume = global_util.zylt_volume_map.get(code) + if price and zylt_volume and zylt_volume * price > 200e8: + continue + before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) if not before_fblocks: before_fblocks = set() @@ -107,6 +253,35 @@ temp_list.sort(key=lambda x: x[1]) self.__out_list = temp_list + def get_block_codes_money(self, block): + """ + 鑾峰彇鏉垮潡涓唬鐮佺殑娴佸叆娴佸嚭 + @param block: + @return:(浠g爜, 閲戦, 鏄惁琚帓闄�) + """ + codes = self.codes + fdatas = [] + for code in codes: + if code in self.__exclude_codes: + continue + money = CodeInMoneyManager().get_money(code) + if money is None: + continue + # 澶ц嚜鐢辨祦閫氬競鍊肩殑娴佸嚭涓嶇畻 + if money < 0: + price = CodeInMoneyManager().get_latest_price(code) + zylt_volume = global_util.zylt_volume_map.get(code) + if price and zylt_volume and zylt_volume * price > 200e8: + continue + before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) + if not before_fblocks: + before_fblocks = set() + fblocks = BlockMapManager().filter_blocks(before_fblocks) + if block not in fblocks: + continue + fdatas.append((code, money, code in self.__exclude_codes)) + return fdatas + def get_in_list(self): return self.__in_list @@ -115,7 +290,11 @@ if __name__ == '__main__': - print(CodeInMoneyManager().get_money("300264")) + code = "600839" + before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) + print(before_fblocks) + + # print(CodeInMoneyManager().get_money("300264")) # BlockInMoneyRankManager().compute() # print(BlockInMoneyRankManager().get_in_list()[:20]) # print(BlockInMoneyRankManager().get_out_list()[:20]) -- Gitblit v1.8.0