From e0062b65da7f3ff34f4c831cc2ef3635b0f44437 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 18 七月 2025 15:19:52 +0800 Subject: [PATCH] 加倍控制中心接口内容优化 --- cancel_strategy/s_l_h_cancel_strategy.py | 81 ++++++++++++++++++++++++++++++---------- 1 files changed, 61 insertions(+), 20 deletions(-) diff --git a/cancel_strategy/s_l_h_cancel_strategy.py b/cancel_strategy/s_l_h_cancel_strategy.py index 19c0e8d..bb67b9b 100644 --- a/cancel_strategy/s_l_h_cancel_strategy.py +++ b/cancel_strategy/s_l_h_cancel_strategy.py @@ -954,10 +954,11 @@ # 閲嶆柊璁$畻L涓� # big_sell_info鍗栧崟淇℃伅锛屾牸寮忥細[鏈�杩戞垚浜ょ储寮�,鏈�杩戞垚浜ゆ椂闂�(甯︽绉�)] - def re_compute_l_down_watch_indexes(self, code, big_sell_info=None): + def re_compute_l_down_watch_indexes(self, code, big_sell_info=None, is_force=False): watch_index_info = self.__cancel_watch_index_info_cache.get(code) - if not watch_index_info or watch_index_info[1] > 0: - return + if not is_force: + if not watch_index_info or watch_index_info[1] > 0: + return # 鑾峰彇鎴愪氦杩涘害浣嶄笌鐪熷疄涓嬪崟浣嶇疆 real_place_order_index_info = self.__real_place_order_index_dict.get(code) last_trade_progress_index, is_default = TradeBuyQueue().get_traded_index(code) @@ -972,19 +973,20 @@ self.compute_watch_index(code, watch_index_info[0], last_trade_progress_index + 1, real_place_order_index_info[0], re_compute=1, min_cancel_time_with_ms=min_cancel_time_with_ms, - msg=f"澶у崟鍗�: 鎴愪氦杩涘害-{big_sell_info}" if big_sell_info is not None else '') + msg=f"澶у崟鍗�: 鎴愪氦杩涘害-{big_sell_info}" if big_sell_info is not None else '', + is_force=is_force) # 璁$畻瑙傚療绱㈠紩锛屽�掑簭璁$畻 # re_compute:鏄惁鏄噸鏂拌绠楃殑 # min_cancel_time_with_ms:鏈�灏忔挙鍗曟椂闂达紝澶т簬绛変簬姝ゆ椂闂寸殑鎾ゅ崟闇�瑕佸泭鎷繘鍘� def compute_watch_index(self, code, buy_single_index, start_index, end_index, re_compute=0, - min_cancel_time_with_ms=None, msg=""): + min_cancel_time_with_ms=None, msg="", is_force=False): try: l2_log.l_cancel_debug(code, f"璁$畻L鍚庡泭鎷寖鍥达細{start_index}-{end_index}") total_datas = local_today_datas.get(code) - if re_compute > 0 and tool.trade_time_sub(total_datas[-1]["val"]["time"], - total_datas[buy_single_index]["val"][ - "time"]) < 2 * 60 and min_cancel_time_with_ms is None: + if not is_force and re_compute > 0 and tool.trade_time_sub(total_datas[-1]["val"]["time"], + total_datas[buy_single_index]["val"][ + "time"]) < 2 * 60 and min_cancel_time_with_ms is None: # 灏佸崟棰濈ǔ浜嗕互鍚庯紝闂撮殧瓒呰繃2鍒嗛挓鎵嶈兘閲嶆柊璁$畻 l2_log.l_cancel_debug(code, f"瑕侀棿闅�2鍒嗛挓杩囧悗鎵嶈兘閲嶆柊璁$畻") return @@ -1523,7 +1525,7 @@ """ 璁$畻L鍚庣殑宸茬粡鎾ゅ崟鐨勬瘮渚� @param code: - @return: 姣斾緥, 宸茬粡鎾ゅ崟鐨勭储寮� + @return: 姣斾緥, 宸茬粡鎾ゅ崟鐨勭储寮�, (鍓嶅崐娈靛泭鎷殑淇℃伅锛堢储寮�, 鎵嬫暟锛�, 鍓嶅崐娈靛凡鎾ょ殑淇℃伅锛堢储寮�,鎵嬫暟锛�) """ watch_indexes_info = self.__get_watch_indexes_cache(code) if not watch_indexes_info: @@ -1582,7 +1584,7 @@ watch_indexes_list.sort() canceled_num = 0 # 璁板綍鎾ゅ崟绱㈠紩 - canceled_indexes = [] + canceled_data_indexes = [] deal_order_nos = HuaXinBuyOrderManager().get_deal_buy_order_nos(code) if deal_order_nos is None: @@ -1591,22 +1593,31 @@ if is_default: trade_index = None canceled_buyno_map = local_today_canceled_buyno_map.get(code) + # 鐪熷疄涓嬪崟浣嶄箣鍓嶇殑鎵嬫暟 + before_nums_info = [] + before_canceled_nums_info = [] for wi in watch_indexes: + data = total_data[wi] + val = data["val"] cancel_data = L2DataComputeUtil.is_canceled(code, wi, total_data, canceled_buyno_map, trade_index, deal_order_nos) - if cancel_data: - if str(wi) in after_place_order_index_dict: - # 鐪熷疄涓嬪崟浣嶇疆涔嬪悗鐨勬寜鐓ф潈閲嶆瘮渚嬫潵璁$畻 + if str(wi) in after_place_order_index_dict: + # 鐪熷疄涓嬪崟浣嶇疆涔嬪悗鐨勬寜鐓ф潈閲嶆瘮渚嬫潵璁$畻 + if cancel_data: canceled_num += total_data[wi]["val"]["num"] * ( 10 - after_place_order_index_dict[str(wi)]) // 10 - elif str(wi) in after_place_order_index_by_dict: + elif str(wi) in after_place_order_index_by_dict: + if cancel_data: canceled_num += total_data[wi]["val"]["num"] * ( 10 - after_place_order_index_by_dict[str(wi)]) // 10 - else: + else: + before_nums_info.append((wi, val["num"])) + if cancel_data: + before_canceled_nums_info.append((wi, val['num'])) canceled_num += total_data[wi]["val"]["num"] - canceled_indexes.append(cancel_data["index"]) + canceled_data_indexes.append(cancel_data["index"]) rate = round(canceled_num / total_num, 3) - return rate, canceled_indexes + return rate, canceled_data_indexes, (before_nums_info, before_canceled_nums_info) def __compute_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code): """ @@ -2025,7 +2036,7 @@ """ 缁熻L鍚庣洃鍚暟鎹俊鎭� @param code: - @return:((鎬荤瑪鏁�, 鎬婚噾棰�), (宸叉挙绗旀暟,宸叉挙閲戦), (宸叉垚浜ょ瑪鏁�,宸叉垚浜ら噾棰�), 缁煎悎鎾ゅ崟姣斾緥, 鎾ゅ崟姣斾緥闃堝��) + @return:((鎬荤瑪鏁�, 鎬婚噾棰�), (宸叉挙绗旀暟,宸叉挙閲戦), (宸叉垚浜ょ瑪鏁�,宸叉垚浜ら噾棰�), 缁煎悎鎾ゅ崟姣斾緥, 鎾ゅ崟姣斾緥闃堝��, (200w浠ヤ笅鎾ゅ崟鐧惧垎鏁�, 200-300W鎾ゅ崟鐧惧垎鏁�, 300w浠ヤ笂鎾ゅ崟鐧惧垎鏁�)) """ watch_indexes_info = self.__get_watch_indexes_cache(code) if not watch_indexes_info: @@ -2073,8 +2084,38 @@ fresults.append(100.00) else: rate_info = self.__compute_l_down_canceled_rate(code, total_datas) - fresults.append(round(rate_info[0]*100, 2)) - fresults.append(LCancelRateManager.get_cancel_rate(code)[0] * 100) + # 宸叉挙姣斾緥 + fresults.append(round(rate_info[0] * 100, 2)) + # 鎾ゅ崟姣斾緥闃堝�� + fresults.append(LCancelRateManager.get_cancel_rate(code)[0] * 100) + + before_watch_indexed_info, before_canceled_watch_indexes_info = rate_info[2][0], rate_info[2][1] + canceled_indexes = set([x[0] for x in before_canceled_watch_indexes_info]) + # [绱鎵嬫暟,绱鎾ゅ崟鎵嬫暟] + watch_index_info_less_of_200 = [0, 0] + watch_index_info_200_to_300 = [0, 0] + watch_index_info_more_than_300 = [0, 0] + + for x in before_watch_indexed_info: + money = limit_up_price * x[1] + if money >= 300 * 100: + watch_index_info_more_than_300[0] += x[1] + if x[0] in canceled_indexes: + watch_index_info_more_than_300[1] += x[1] + elif money >= 200 * 100: + watch_index_info_200_to_300[0] += x[1] + if x[0] in canceled_indexes: + watch_index_info_200_to_300[1] += x[1] + else: + watch_index_info_less_of_200[0] += x[1] + if x[0] in canceled_indexes: + watch_index_info_less_of_200[1] += x[1] + fresults.append(( + round(watch_index_info_less_of_200[1] * 100 / max(watch_index_info_less_of_200[0], 1)), + round(watch_index_info_200_to_300[1] * 100 / max(watch_index_info_200_to_300[0], 1)), + round(watch_index_info_more_than_300[1] * 100 / max(watch_index_info_more_than_300[0], 1)), + )) + return fresults -- Gitblit v1.8.0