From a846b46f15ad309a62fe400cf78dd7fc888155d7 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 26 五月 2025 16:39:19 +0800 Subject: [PATCH] 完善大单够了加白机制 --- trade/trade_result_manager.py | 5 + trade/buy_radical/radical_buy_data_manager.py | 66 +++++++++++++++- api/outside_api_command_callback.py | 4 l2/l2_data_manager.py | 4 trade/buy_radical/radical_buy_strategy.py | 4 code_attribute/gpcode_manager.py | 30 +++++++ servers/huaxin_trade_server.py | 12 ++ l2/l2_data_manager_new.py | 73 ++++++++++------- 8 files changed, 151 insertions(+), 47 deletions(-) diff --git a/api/outside_api_command_callback.py b/api/outside_api_command_callback.py index a1f6ea6..db672cd 100644 --- a/api/outside_api_command_callback.py +++ b/api/outside_api_command_callback.py @@ -344,14 +344,14 @@ fresult = {"code": 0, "data": datas} elif code_list_type == outside_api_command_manager.CODE_LIST_WHITE: if operate == outside_api_command_manager.OPERRATE_SET: - gpcode_manager.WhiteListCodeManager().add_code(code) + gpcode_manager.WhiteListCodeManager().add_code(code, is_human=True) name = gpcode_manager.get_code_name(code) if not name: results = HistoryKDatasUtils.get_gp_codes_names([code]) if results: gpcode_manager.CodesNameManager.add_first_code_name(code, results[code]) elif operate == outside_api_command_manager.OPERRATE_DELETE: - gpcode_manager.WhiteListCodeManager().remove_code(code) + gpcode_manager.WhiteListCodeManager().remove_code(code, is_human=True) elif operate == outside_api_command_manager.OPERRATE_GET: codes = gpcode_manager.WhiteListCodeManager().list_codes_cache() datas = [] diff --git a/code_attribute/gpcode_manager.py b/code_attribute/gpcode_manager.py index 9ab6e76..4dbcfc1 100644 --- a/code_attribute/gpcode_manager.py +++ b/code_attribute/gpcode_manager.py @@ -401,6 +401,7 @@ class WhiteListCodeManager: __instance = None __redis_manager = redis_manager.RedisManager(2) + __human_remove_codes = set() def __new__(cls, *args, **kwargs): if not cls.__instance: @@ -421,14 +422,21 @@ if data: self.__white_codes_cache |= data - def add_code(self, code): + def add_code(self, code, is_human=False): + + if not is_human and code in self.__human_remove_codes: + # 鏈哄櫒鍔犵櫧锛屼笖琚汉涓虹Щ鐧戒簡灏变笉鑳藉啀鍔犵櫧 + return + self.__white_codes_cache.add(code) RedisUtils.sadd(self.__get_redis(), "white_list_codes", code) RedisUtils.expire(self.__get_redis(), "white_list_codes", tool.get_expire()) - def remove_code(self, code): + def remove_code(self, code, is_human=False): self.__white_codes_cache.discard(code) RedisUtils.srem(self.__get_redis(), "white_list_codes", code) + if is_human: + self.human_remove(code) def is_in(self, code): return RedisUtils.sismember(self.__get_redis(), "white_list_codes", code) @@ -446,6 +454,24 @@ self.__white_codes_cache.clear() RedisUtils.delete(self.__get_redis(), "white_list_codes") + def human_remove(self, code): + """ + 浜轰负绉荤櫧 + @param code: + @return: + """ + self.__human_remove_codes.add(code) + + def clear_huamn_info(self, code): + """ + 绉婚櫎浜轰负骞查淇℃伅 + @param code: + @return: + """ + if code in self.__human_remove_codes: + self.__human_remove_codes.discard(code) + + class BlackListCodeManager: __instance = None diff --git a/l2/l2_data_manager.py b/l2/l2_data_manager.py index c298c01..bbbe0ef 100644 --- a/l2/l2_data_manager.py +++ b/l2/l2_data_manager.py @@ -23,7 +23,7 @@ # mode: 0-鏅�氫氦鏄� 1-蹇�熶氦鏄� def __init__(self, buy_single_index=None, buy_exec_index=-1, buy_compute_index=None, num=0, count=0, max_num_set=None, buy_volume_rate=None, sell_info=None, threshold_money=None, mode=0, mode_desc=None, - at_limit_up=False, first_limit_up_buy=False): + at_limit_up=False, first_limit_up_buy=False, min_order_no = None): self.buy_single_index = buy_single_index self.buy_exec_index = buy_exec_index self.buy_compute_index = buy_compute_index @@ -42,6 +42,8 @@ self.at_limit_up = at_limit_up # 鏄惁涓洪灏佷拱 self.first_limit_up_buy = first_limit_up_buy + # 缁熻鎵规澶у崟鎴愪氦鐨勬渶灏忚鍗曞彿 + self.min_order_no = min_order_no def get_max_num_set(self): if self.max_num_set: diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index 5d2488e..c1b0e7f 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -1522,32 +1522,35 @@ _start_time = tool.get_now_timestamp() total_datas = local_today_datas[code] - if not HumanRadicalBuySingleManager.has_single(code): - # ---------璁$畻婵�杩涗拱鍏ョ殑淇″彿--------- - radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) - else: - human_radical_result = cls.__compute_human_radical_order_begin_pos(code, compute_start_index, - compute_end_index) - l2_log.debug(code, f"澶у崟瓒冲锛屼汉涓轰笅鍗曡绠楃粨鏋�({compute_start_index}-{compute_end_index}):{human_radical_result}") - if human_radical_result[0]: - radical_result = list(human_radical_result[2]) - # 鏀瑰彉鎵ц浣嶇疆 - radical_result[1] = human_radical_result[1]["index"] - else: - radical_result = None + # 涓嶉渶瑕佹牴鎹汉涓轰笅鍗曟潵涓嬪崟 + # if not HumanRadicalBuySingleManager.has_single(code): + # # ---------璁$畻婵�杩涗拱鍏ョ殑淇″彿--------- + # radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) + # else: + # human_radical_result = cls.__compute_human_radical_order_begin_pos(code, compute_start_index, + # compute_end_index) + # l2_log.debug(code, f"澶у崟瓒冲锛屼汉涓轰笅鍗曡绠楃粨鏋�({compute_start_index}-{compute_end_index}):{human_radical_result}") + # if human_radical_result[0]: + # radical_result = list(human_radical_result[2]) + # # 鏀瑰彉鎵ц浣嶇疆 + # radical_result[1] = human_radical_result[1]["index"] + # else: + # radical_result = None + + radical_result = cls.__compute_radical_order_begin_pos(code, compute_start_index, compute_end_index) if radical_result and radical_result[0]: - if not HumanRadicalBuySingleManager.has_single(code): - big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code, - code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( - code), 0) - if big_order_deal_enough_result[6] <= 0: - HumanRadicalBuySingleManager.add_single(code, total_datas[-1], radical_result) - async_log_util.info(logger_l2_not_buy_reasons, f"{code}#澶у崟瓒冲锛岄渶瑕佹牴鎹汉涓轰笅鍗�({compute_start_index}-{compute_end_index})锛歿radical_result[1]}") - return - # 涓嬪崟鍓嶄竴姝ワ紝绉婚櫎浜轰负涓嬪崟淇″彿 - is_human_radical_buy = HumanRadicalBuySingleManager.has_single(code) - HumanRadicalBuySingleManager.remove_single(code) + # if not HumanRadicalBuySingleManager.has_single(code): + # big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code, + # code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( + # code), 0) + # if big_order_deal_enough_result[6] <= 0: + # HumanRadicalBuySingleManager.add_single(code, total_datas[-1], radical_result) + # async_log_util.info(logger_l2_not_buy_reasons, f"{code}#澶у崟瓒冲锛岄渶瑕佹牴鎹汉涓轰笅鍗�({compute_start_index}-{compute_end_index})锛歿radical_result[1]}") + # return + # #涓嬪崟鍓嶄竴姝ワ紝绉婚櫎浜轰负涓嬪崟淇″彿 + # is_human_radical_buy = HumanRadicalBuySingleManager.has_single(code) + # HumanRadicalBuySingleManager.remove_single(code) buy_single_index, buy_exec_index = radical_result[1], radical_result[1] buy_volume_rate = cls.volume_rate_info[code][0] @@ -1566,9 +1569,11 @@ max_num_set=set(), buy_volume_rate=buy_volume_rate, mode=OrderBeginPosInfo.MODE_RADICAL, - mode_desc=f"澶у崟涓嶈冻鎵叆:{radical_result[2]} 鏄惁璺熶汉涔板叆-{is_human_radical_buy}", + mode_desc=f"澶у崟涓嶈冻鎵叆:{radical_result[2]}", sell_info=sell_info, - threshold_money=threshold_money) + threshold_money=threshold_money, + min_order_no=radical_result[5] + ) order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code) ordered = cls.__process_with_find_exec_index(code, order_begin_pos_info, compute_end_index, block_info=radical_result[3]) @@ -2021,11 +2026,10 @@ @param code: @param start_index: @param end_index: - @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅, 鎵叆鏉垮潡澶у崟娴佸叆淇℃伅, 闇�瑕佺洃鍚殑澶у崟) + @return: (鏄惁鑾峰彇鍒颁俊鍙�, 淇″彿浣嶇疆, 鎵叆鏉垮潡/娑堟伅, 鎵叆鏉垮潡澶у崟娴佸叆淇℃伅, 闇�瑕佺洃鍚殑澶у崟, 缁熻涓婃澘澶у崟鎴愪氦鐨勬渶灏忚鍗曞彿) """ # 婵�杩涗拱淇″彿鐨勬椂闂� - def __can_order(): # 鍒ゆ柇鏄惁鏄澘涓婃斁閲� # if cls.__is_at_limit_up_buy(code, start_index): @@ -2126,8 +2130,13 @@ single_index = i break if single_index is not None: - return True, single_index, f"鏈夊ぇ鍗�,澶у崟鎯呭喌锛歿big_order_deal_enough_result[1]}", watch_indexes - return False, None, f"澶у崟涓嶈冻锛歿trade_index}-{end_index} 缂哄皯鐨勫ぇ鍗�-{max(current_lack_money, total_lack_money)} 澶у崟鎯呭喌锛歿big_order_deal_enough_result[1]}", watch_indexes + every_time_big_orders = EveryLimitupBigDealOrderManager.list_big_buy_deal_orders(code) + if every_time_big_orders: + min_order_no = min(min(every_time_big_orders, key=lambda e: e[0])[0], radical_data[1]) + else: + min_order_no = radical_data[1] + return True, single_index, f"鏈夊ぇ鍗�,澶у崟鎯呭喌锛歿big_order_deal_enough_result[1]}", watch_indexes, min_order_no + return False, None, f"澶у崟涓嶈冻锛歿trade_index}-{end_index} 缂哄皯鐨勫ぇ鍗�-{max(current_lack_money, total_lack_money)} 澶у崟鎯呭喌锛歿big_order_deal_enough_result[1]}", watch_indexes, None radical_data = RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.get(code) record_codes = radical_buy_data_manager.BlockPlaceOrderRecordManager().get_codes() @@ -2171,7 +2180,7 @@ # 濡傛灉鏉夸笂鏀鹃噺涓嶅彲涔板叆灏遍渶瑕佸垹闄や俊鍙� if not constant.CAN_RADICAL_BUY_AT_LIMIT_UP and code in RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict: RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.pop(code) - return True, result[1], radical_data[2], radical_data[4], result[3] + return True, result[1], radical_data[2], radical_data[4], result[3], result[4] else: async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{result[2]}") return result @@ -2245,6 +2254,8 @@ @param end_index: @return: 淇″彿淇℃伅锛堜俊鍙蜂綅,鎵ц浣嶏級, 娑堟伅, 鍙拱鍏ョ殑鏉垮潡 """ + if True: + return None, "姝ゆ潯涓嶇敓鏁�", None if not tool.is_sz_code(code): return None, "闈炴繁璇佺殑绁�", None # 鍒ゆ柇鎶涘帇鏄惁澶т簬5000w diff --git a/servers/huaxin_trade_server.py b/servers/huaxin_trade_server.py index eb0827a..0d5f94e 100644 --- a/servers/huaxin_trade_server.py +++ b/servers/huaxin_trade_server.py @@ -839,6 +839,12 @@ if refer_sell_data: sell_info = (refer_sell_data[0], refer_sell_data[1]) threshold_money = 0 + every_deal_orders = EveryLimitupBigDealOrderManager.list_big_buy_deal_orders(code) + if every_deal_orders: + min_order_no = min(every_deal_orders, lambda x: x[0])[0] + else: + min_order_no = transaction_datas[-1][6] + order_begin_pos_info = OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=buy_exec_index, buy_compute_index=buy_exec_index, @@ -846,9 +852,11 @@ max_num_set=set(), buy_volume_rate=buy_volume_rate, mode=OrderBeginPosInfo.MODE_RADICAL, - mode_desc=f"鎵叆涔板叆锛歿buy_blocks}", + mode_desc=f"鎵叆涔板叆锛歿buy_blocks}, 澶у崟鎴愪氦鏈�灏忚鍗曞彿锛歿min_order_no}", sell_info=sell_info, - threshold_money=threshold_money) + threshold_money=threshold_money, + min_order_no= min_order_no + ) L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos_info) buy_result = L2TradeDataProcessor.start_buy(code, total_datas[-1], total_datas[-1]["index"], True, block_info=buy_blocks_with_money) diff --git a/trade/buy_radical/radical_buy_data_manager.py b/trade/buy_radical/radical_buy_data_manager.py index 83d919b..b2d2a64 100644 --- a/trade/buy_radical/radical_buy_data_manager.py +++ b/trade/buy_radical/radical_buy_data_manager.py @@ -11,7 +11,7 @@ import constant import l2_data_util from code_attribute.code_volumn_manager import CodeVolumeManager -from l2 import l2_data_util as l2_data_util_new, l2_log +from l2 import l2_data_util as l2_data_util_new, l2_log, l2_data_manager from code_attribute import code_nature_analyse, code_volumn_manager, gpcode_manager from code_attribute.code_l1_data_manager import L1DataManager from code_attribute.gpcode_manager import WantBuyCodesManager @@ -560,6 +560,7 @@ @param count: @return: """ + cls.__process_add_white(code) if gpcode_manager.MustBuyCodesManager().is_in_cache(code): return total_deal_big_order_result = get_total_deal_big_order_info(code, @@ -570,15 +571,54 @@ @classmethod def place_order_success(cls, code): # 濡傛灉鏄姞鎯筹紝涓旀垚浜ゅぇ鍗曡冻澶熷氨鍔犵孩 + total_deal_big_order_result = get_total_deal_big_order_info(code, + gpcode_manager.get_limit_up_price_as_num(code)) if WantBuyCodesManager().is_in_cache(code): - big_order_deal_enough_result = is_big_order_deal_enough(code, - code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days( - code), - 0) - if big_order_deal_enough_result[6] <= 0: + if total_deal_big_order_result[0] <= 0: # 绱澶у崟瓒冲闇�瑕佸姞绾� gpcode_manager.MustBuyCodesManager().add_code(code) trade_record_log_util.add_must_buy(code, "绱鎴愪氦澶у崟瓒冲") + cls.__process_add_white(code) + + @classmethod + def __process_add_white(cls, code): + """ + 澶勭悊鍔犵櫧 + @param code: + @return: + """ + if gpcode_manager.WhiteListCodeManager().is_in_cache(code): + return + try: + total_deal_big_order_result = get_total_deal_big_order_info(code, + gpcode_manager.get_limit_up_price_as_num(code)) + if total_deal_big_order_result[0] <= 0 and total_deal_big_order_result[2] >= 1e8: + # 1涓嚎浠ヤ笂鐨勪笖鏈壒娆℃垚浜ょ殑澶у崟閲戦澶т簬2鍊嶅ぇ鍗曢噾棰濆氨鍔犵櫧 + order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code) + is_placed_order = l2_data_manager.TradePointManager.is_placed_order(order_begin_pos) + if not is_placed_order: + # 娌℃湁涓嬭繃鍗� + return + if order_begin_pos and order_begin_pos.min_order_no is not None: + # 鍦� min_order_no 涔嬪悗鎴愪氦鐨勫ぇ鍗曢噾棰� + total_buy_data_list = BigOrderDealManager().get_total_buy_data_list(code) + min_order_no = order_begin_pos.min_order_no + if min_order_no is None: + async_log_util.warning(logger_debug, "澶勭悊鎴愪氦澶у崟瓒冲鍔犵櫧: 鏈�灏忚鍗曞彿涓虹┖") + return + bigger_money = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), + tool.is_ge_code(code)) + deal_money = sum( + [x[2] for x in total_buy_data_list if x[0] >= min_order_no and x[2] >= bigger_money]) + # 鑾峰彇鍧囧ぇ鍗� + THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info( + code) + if deal_money >= 2 * THRESHOLD_MONEY: + gpcode_manager.WhiteListCodeManager().add_code(code) + trade_record_log_util.add_common_msg(code, "鍔犵櫧", f"{code}澶у崟鎴愪氦瓒冲鍔犵櫧锛� 鏈壒娆℃垚浜ら噾棰�-{deal_money}/{THRESHOLD_MONEY * 2} 绱澶у崟閲戦锛歿total_deal_big_order_result[1]}/{total_deal_big_order_result[2]}") + except Exception as e: + logger_debug.exception(e) + async_log_util.info(logger_debug, f"澶勭悊鎴愪氦澶у崟瓒冲鍔犵櫧鐨勯棶棰�:{str(e)}") @classmethod def market_info_change(cls, code): @@ -1854,11 +1894,25 @@ @classmethod def get_big_buy_deal_order_money_info(cls, code): + """ + 鑾峰彇鎴愪氦澶у崟鐨勪俊鎭� + @param code: + @return: (鎬诲叡澶у崟鎴愪氦閲戦, 鏈�杩戞垚浜ゅぇ鍗曠殑鏈�鍚庢垚浜ゆ椂闂�) + """ if cls.__deal_big_order_infos_dict.get(code): return sum([x[1] for x in cls.__deal_big_order_infos_dict[code]]), l2_huaxin_util.convert_time( cls.__deal_big_order_infos_dict[code][-1][2]) return None + @classmethod + def list_big_buy_deal_orders(cls, code): + """ + + @param code: + @return:[(璁㈠崟鍙�,閲戦, 鏈�鍚庢垚浜ゆ椂闂�)] + """ + return cls.__deal_big_order_infos_dict.get(code, []) + class EveryLimitupBigDelegateOrderManager: """ diff --git a/trade/buy_radical/radical_buy_strategy.py b/trade/buy_radical/radical_buy_strategy.py index 3e52795..8753d20 100644 --- a/trade/buy_radical/radical_buy_strategy.py +++ b/trade/buy_radical/radical_buy_strategy.py @@ -165,8 +165,8 @@ left_limit_up_sell_money = selling_num * price # 姣忔涓婃澘鐨勫ぇ鍗曚笌閲戦 - big_order_count = radical_buy_data_manager.EveryLimitupBigDealOrderManager().get_big_buy_deal_order_count(code) - big_order_money = radical_buy_data_manager.EveryLimitupBigDealOrderManager().get_big_buy_deal_order_money(code) + big_order_count = radical_buy_data_manager.EveryLimitupBigDealOrderManager.get_big_buy_deal_order_count(code) + big_order_money = radical_buy_data_manager.EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money(code) if big_order_count >= 2: average_big_order_money = int(big_order_money / big_order_count) # 濡傛灉鍧囦环娑ㄥ箙灏忎簬7%鍧囧ぇ鍗曠瓑浜�299w diff --git a/trade/trade_result_manager.py b/trade/trade_result_manager.py index fc503a0..445956d 100644 --- a/trade/trade_result_manager.py +++ b/trade/trade_result_manager.py @@ -4,7 +4,8 @@ from cancel_strategy.s_l_h_cancel_strategy import HourCancelBigNumComputer from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer -from code_attribute.gpcode_manager import MustBuyCodesManager, GreenListCodeManager, WantBuyCodesManager +from code_attribute.gpcode_manager import MustBuyCodesManager, GreenListCodeManager, WantBuyCodesManager, \ + WhiteListCodeManager from l2 import l2_data_manager, place_order_single_data_manager from l2.cancel_buy_strategy import FCancelBigNumComputer, \ NewGCancelBigNumComputer, JCancelBigNumComputer, NBCancelBigNumComputer @@ -111,6 +112,8 @@ # 濡傛灉鏄壂鍏ヤ笅鍗曪紝涓嬪崟涔嬪悗灏卞姞绾� if order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL: + # 绉婚櫎浜轰负绉荤櫧 + WhiteListCodeManager().clear_huamn_info(code) RadicalBuyDataManager.place_order_success(code) # 娓呴櫎涓嬪崟淇″彿 -- Gitblit v1.8.0