From cf551c3d66c1410bfdfd9f808e98cba77dec5cd1 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 16 七月 2024 17:16:15 +0800 Subject: [PATCH] 上证S重砸优化/逼近成交时L后囊括范围修改 --- cancel_strategy/s_l_h_cancel_strategy.py | 107 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 97 insertions(+), 10 deletions(-) diff --git a/cancel_strategy/s_l_h_cancel_strategy.py b/cancel_strategy/s_l_h_cancel_strategy.py index 2c4030e..64893ad 100644 --- a/cancel_strategy/s_l_h_cancel_strategy.py +++ b/cancel_strategy/s_l_h_cancel_strategy.py @@ -57,12 +57,6 @@ elif half_must_buy: return round((constant.S_FAST_RATE + constant.S_FAST_BIG_RATE_WITH_MUST_BUY) / 2, 2), "鍗婄孩" else: - # 涓婅瘉 濡傛灉娌℃湁澶у崟鎴愪氦,涓嶉渶瑕佺湅姣斾緥 - if tool.is_sh_code(code): - # 鑾峰彇澶у崟鎴愪氦 - deal_big_order_count = BigOrderDealManager().get_total_buy_count(code) - if deal_big_order_count < 1: - return 0, "甯歌锛堟棤澶у崟鎴愪氦锛�" return constant.S_FAST_RATE, "甯歌" elif cancel_type == cls.TYPE_S_SLOW: if must_buy: @@ -350,6 +344,7 @@ total_datas = local_today_datas.get(code) real_order_index_info = self.__get_real_place_order_index_info_cache(code) real_order_time_ms = None + real_order_index = None if real_order_index_info and not real_order_index_info[1]: real_order_index = real_order_index_info[0] real_order_time_ms = total_datas[real_order_index]["val"]["time"] + ".{0:0>3}".format( @@ -374,10 +369,20 @@ if total_deal_money >= threshold_big_deal: # S閲嶇牳蹇呮挙鐨勯噾棰濇弧瓒充互鍚庯紝浠ュ墠鏄棤鑴戞挙銆傜幇鍦ㄤ紭鍖栦竴涓嬶紝鐪嬫垚浜よ繘搴︿綅---鐪熷疄涓嬪崟浣嶇殑鍖洪棿棰濃墹閲嶇牳閲戦*3.3鍊嶏紝灏辨挙銆� try: - # 涓婅瘉濡傛灉閲嶇牳棰濆ぇ浜庨槇鍊肩殑1.5鍊嶇洿鎺ユ挙鍗� - if tool.is_sh_code(code) and total_deal_money >= threshold_big_deal * 1.5: - if not gpcode_manager.MustBuyCodesManager().is_in_cache(code): - return True, f"1s鍐呮垚浜�({threshold_big_deal}) 澶т簬澶у崠鍗曪紙{total_deal_money}锛夌殑1.5鍊�" + # 涓婅瘉锛屼笅鍗�3鍒嗛挓鍐� + try: + if tool.is_sh_code(code) and real_order_index is not None and tool.trade_time_sub( + total_datas[-1]["val"]["time"], total_datas[real_order_index]["val"]["time"]) < 3 * 60: + # 涓婅瘉濡傛灉閲嶇牳棰濆ぇ浜庨槇鍊肩殑1.5鍊嶇洿鎺ユ挙鍗� + if not gpcode_manager.MustBuyCodesManager().is_in_cache(code): + if total_deal_money >= threshold_big_deal * 1.5: + return True, f"1s鍐呮垚浜�({total_deal_money}) 澶т簬澶у崠鍗曪紙{threshold_big_deal}锛夌殑1.5鍊�" + # 濡傛灉娌℃湁澶у崟鎴愪氦涔熺洿鎺ユ挙鍗� + deal_big_order_count = BigOrderDealManager().get_total_buy_count(code) + if deal_big_order_count < 1: + return True, f"1s鍐呮垚浜�({total_deal_money}) 澶т簬澶у崠鍗曪紙{threshold_big_deal}锛変笖鏃犲ぇ鍗曟垚浜�" + except Exception as e: + l2_log.s_cancel_debug(code, "S閲嶇牳鍑洪敊浜嗭細{}", str(e)) need_compute = False trade_index, is_default = TradeBuyQueue().get_traded_index(code) @@ -652,6 +657,8 @@ __last_l_up_compute_info = {} + __l_down_after_by_big_order_dict = {} + __instance = None def __new__(cls, *args, **kwargs): @@ -764,6 +771,8 @@ def clear(self, code=None): if code: self.del_watch_index(code) + if code in self.__l_down_after_by_big_order_dict: + self.__l_down_after_by_big_order_dict.pop(code) if code in self.__real_place_order_index_dict: self.__real_place_order_index_dict.pop(code) RedisUtils.delete_async(self.__db, f"l_cancel_real_place_order_index-{code}") @@ -787,6 +796,7 @@ keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_down_after_place_order_index-*") for k in keys: RedisUtils.delete(self.__get_redis(), k) + self.__l_down_after_by_big_order_dict.clear() # 閲嶆柊璁$畻L涓� @@ -1048,6 +1058,55 @@ pass return watch_indexes + def __compute_l_down_watch_index_after_by(self, code): + """ + 璁$畻L鍚庡悗鍗婃澶у崟澶囩敤 + @param code: + @return: + """ + if self.__l_down_after_by_big_order_dict.get(code): + # 涓嶇敤閲嶅璁$畻 + return + real_place_order_info = self.__real_place_order_index_dict.get(code) + if not real_place_order_info or real_place_order_info[1]: + return + real_place_order_index = real_place_order_info[0] + total_datas = local_today_datas.get(code) + limit_up_price = gpcode_manager.get_limit_up_price(code) + limit_up_price = round(float(limit_up_price), 2) + bigger_num = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code)) // (limit_up_price * 100) + min_num = 500000 // (limit_up_price * 100) + count = -1 + watch_indexes = set() + for i in range(real_place_order_index + 1, total_datas[-1]["index"]): + data = total_datas[i] + val = data["val"] + if not L2DataUtil.is_limit_up_price_buy(val): + continue + if val["num"] < min_num: + continue + + if val["num"] < bigger_num: + continue + + left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, i, + total_datas, + local_today_canceled_buyno_map.get( + code)) + if left_count > 0: + if val["num"] >= bigger_num: + if count < 0: + # 寮�濮嬭鏁� + count = 0 + # 鍔犲叆澶у崟鐩戝惉 + watch_indexes.add(i) + if count >= 0: + count += 1 + if count > 10: + break + self.__l_down_after_by_big_order_dict[code] = watch_indexes + l2_log.l_cancel_debug(code, f"L鍚庡悗鍗婃澶у崟澶囩敤鍥婃嫭鑼冨洿锛歿watch_indexes}") + # 璁剧疆鐪熷疄涓嬪崟浣嶇疆 def set_real_place_order_index(self, code, index, buy_single_index=None, is_default=False): l2_log.l_cancel_debug(code, f"璁剧疆鐪熷疄涓嬪崟浣�-{index}锛宐uy_single_index-{buy_single_index}") @@ -1184,7 +1243,13 @@ if not self.__is_l_down_can_cancel(code, buy_single_index): # L鍚庡凡缁忎笉鑳藉畧鎶� l2_log.l_cancel_debug(code, f"L鍚庡凡缁忔棤娉曠敓鏁堬細buy_single_index-{buy_single_index}") + HourCancelBigNumComputer().start_compute_watch_indexes(code, buy_single_index) + try: + # 璁$畻L鍚庡悗鍗婃澶у崟鐩戞帶鑼冨洿 + self.__compute_l_down_watch_index_after_by(code) + except Exception as e: + l2_log.l_cancel_debug(code, "__compute_l_down_watch_index_after_by鍑洪敊") real_place_order_index_info = self.__real_place_order_index_dict.get(code) real_place_order_index = None @@ -1257,6 +1322,7 @@ left_count_after += 1 if l2_data_util.is_big_money(val, is_ge_code) and j not in watch_indexes: watch_indexes.add(j) + l2_log.l_cancel_debug(code, f"L鍚庢湁鎴愪氦鍚庡崐娈靛鍔犲泭鎷細{j}") self.__set_cancel_l_down_after_place_order_index(code, j, left_count_after - 1) break except: @@ -1280,6 +1346,20 @@ if not watch_indexes_info: return False, None watch_indexes = set([int(i) for i in watch_indexes_info[2]]) + try: + # 灏嗗鐢ㄨ鍗曞姞杩涘幓 + watch_indexes_by = self.__l_down_after_by_big_order_dict.get(code) + if watch_indexes_by: + # 鏄惁鏄笅鍗�30鍒嗛挓鍐� + real_place_order_info = self.__real_place_order_index_dict.get(code) + if real_place_order_info and tool.trade_time_sub(total_data[-1]["val"]["time"] , total_data[real_place_order_info[0]]["val"]["time"]) < 30*60: + # 涓嬪崟30鍒嗛挓鍐呮湁鏁� + watch_indexes|=watch_indexes_by + else: + # 娓呴櫎澶囩敤澶у崟 + watch_indexes_by.clear() + except Exception as e: + l2_log.l_cancel_debug(code,"灏哃2鍚庡悗鍗婃澶囩敤澶у崟鍔犲叆璁$畻鍑洪敊锛歿}", str(e)) # 璁$畻鐩戝惉鐨勬�绘潯鏁� total_num = 0 max_num = 0 @@ -1464,11 +1544,18 @@ trade_index = 0 if trade_index is None: return True + real_place_order_index_info = self.__real_place_order_index_dict.get(code) + if not real_place_order_index_info: + return True + # 璁$畻宸茬粡鎴愪氦鐨勬瘮渚� total_datas = local_today_datas.get(code) total_deal_nums = 0 total_nums = 1 for index in watch_indexes_info[2]: + # 涓嶈兘璁$畻L鍚庡悗鍗婃 + if index > real_place_order_index_info[0]: + continue data = total_datas[index] val = data["val"] left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, -- Gitblit v1.8.0