From 8c7f84cbd0afde7600b0c67a8032fa19c57d8c41 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 05 二月 2024 11:18:33 +0800 Subject: [PATCH] L撤快速成交触发撤单修改 --- l2/l2_transaction_data_processor.py | 9 ++-- huaxin_client/l1_client_for_trade.py | 4 +- l2/cancel_buy_strategy.py | 69 ++++++++++++++++------------------ l2/l2_data_manager_new.py | 18 +++++++++ 4 files changed, 56 insertions(+), 44 deletions(-) diff --git a/huaxin_client/l1_client_for_trade.py b/huaxin_client/l1_client_for_trade.py index 80a8261..4acddc6 100644 --- a/huaxin_client/l1_client_for_trade.py +++ b/huaxin_client/l1_client_for_trade.py @@ -62,8 +62,8 @@ def subscribe(self, codes: set): del_codes = self.__subscribed_codes - codes add_codes = codes - self.__subscribed_codes - if add_codes: - codes_sh, codes_sz = self.__seperate_codes(add_codes) + if codes: + codes_sh, codes_sz = self.__seperate_codes(codes) logger_local_huaxin_l1.info(f"鏂板璁㈤槄锛歿codes_sh} {codes_sz}") if codes_sh: ret = self.__api.SubscribeMarketData(codes_sh, xmdapi.TORA_TSTP_EXD_SSE) diff --git a/l2/cancel_buy_strategy.py b/l2/cancel_buy_strategy.py index 8837171..696c75c 100644 --- a/l2/cancel_buy_strategy.py +++ b/l2/cancel_buy_strategy.py @@ -32,10 +32,11 @@ from utils.tool import CodeDataCacheUtil -def set_real_place_position(code, index, buy_single_index=None, is_default = True): +def set_real_place_position(code, index, buy_single_index=None, is_default=True): # DCancelBigNumComputer().set_real_order_index(code, index) SecondCancelBigNumComputer().set_real_place_order_index(code, index) - LCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index=buy_single_index) + LCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index=buy_single_index, + is_default=is_default) HourCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index) GCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index, is_default) FCancelBigNumComputer().set_real_order_index(code, index) @@ -836,7 +837,7 @@ # 鑾峰彇鎾ゅ崟姣斾緥,杩斿洖锛堟挙鍗曟瘮渚�,鏄惁蹇呬拱锛� @classmethod - def get_cancel_rate(cls, code, buy_exec_time, is_up=False, is_l_down_recomputed = False): + def get_cancel_rate(cls, code, buy_exec_time, is_up=False, is_l_down_recomputed=False): # 涓嬪崟15s鍐呮挙鍗曟瘮渚嬩负璁剧疆涓�29% -- 鏆傛椂涓嶇敓鏁� # if not is_up and tool.trade_time_sub(tool.get_now_time_str(), buy_exec_time) <= 15: # return 0.29, False @@ -958,7 +959,7 @@ for k in keys: code = k.split("-")[-1] val = RedisUtils.get(__redis, k) - val = int(val) + val = json.loads(val) CodeDataCacheUtil.set_cache(cls.__real_place_order_index_dict, code, val) keys = RedisUtils.keys(__redis, "l_cancel_near_by_index-*") @@ -1048,11 +1049,12 @@ if not watch_index_info or watch_index_info[1] > 0: return # 鑾峰彇鎴愪氦杩涘害浣嶄笌鐪熷疄涓嬪崟浣嶇疆 - real_place_order_index = self.__real_place_order_index_dict.get(code) + real_place_order_index_info = self.__real_place_order_index_dict.get(code) last_trade_progress_index = self.__last_trade_progress_dict.get(code) - if not real_place_order_index or not last_trade_progress_index: + if not real_place_order_index_info or not last_trade_progress_index: return - self.compute_watch_index(code, watch_index_info[0], last_trade_progress_index + 1, real_place_order_index, + self.compute_watch_index(code, watch_index_info[0], last_trade_progress_index + 1, + real_place_order_index_info[0], re_compute=1) # 璁$畻瑙傚療绱㈠紩锛屽�掑簭璁$畻 @@ -1168,9 +1170,9 @@ async_log_util.exception(logger_l2_l_cancel, e) # 璁剧疆鐪熷疄涓嬪崟浣嶇疆 - def set_real_place_order_index(self, code, index, buy_single_index=None): + 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}") - self.__real_place_order_index_dict[code] = index + self.__real_place_order_index_dict[code] = (index, is_default) RedisUtils.setex_async(self.__db, f"l_cancel_real_place_order_index-{code}", tool.get_expire(), index) if buy_single_index is not None: self.compute_watch_index(code, buy_single_index, buy_single_index, index) @@ -1189,7 +1191,7 @@ if code not in self.__last_l_up_compute_info or time.time() - self.__last_l_up_compute_info[code][0] >= 3: self.__compute_trade_progress_near_by_indexes(code, buy_single_index, self.__last_trade_progress_dict.get(code) + 1, - self.__real_place_order_index_dict.get(code)) + self.__real_place_order_index_dict.get(code)[0]) # 璁$畻鑼冨洿鍐呯殑鎴愪氦浣嶄复杩戞湭鎾ゅぇ鍗� def __compute_trade_progress_near_by_indexes(self, code, buy_single_index, start_index, end_index): @@ -1234,7 +1236,6 @@ def __compute_total_l_down_not_deal_num(self, code): # 鍙湁鐪熷疄鑾峰彇鍒颁笅鍗曚綅缃悗鎵嶅紑濮嬭绠� - try: if code in self.__total_l_down_not_deal_num_dict and time.time() - \ self.__total_l_down_not_deal_num_dict[code][ @@ -1271,7 +1272,7 @@ dealing_info = HuaXinTransactionDataManager.get_dealing_order_info(code) if dealing_info: if str(val["orderNo"]) == str(dealing_info[0]): - fnum -= dealing_info[1]//100 + fnum -= dealing_info[1] // 100 total_left_num += fnum self.__total_l_down_not_deal_num_dict[code] = (total_left_num, time.time()) except Exception as e: @@ -1289,23 +1290,13 @@ # L鍚庡凡缁忎笉鑳藉畧鎶� HourCancelBigNumComputer().start_compute_watch_indexes(code, buy_single_index) - # 閲嶆柊璁$畻鎴愪氦浣嶇疆涓磋繎澶у崟鎾ゅ崟 - self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, - self.__real_place_order_index_dict.get(code)) + real_place_order_index_info = self.__real_place_order_index_dict.get(code) + real_place_order_index = None + if real_place_order_index_info: + real_place_order_index = real_place_order_index_info[0] - # 鎴愪氦杩涘害涓嶭涓嬫挙鏃犲叧 - # try: - # # 宸茬粡鏈夎绠楃殑鏃犳硶瑙﹀彂璁$畻 - # old_watch_indexes = self.__get_watch_indexes_cache(code) - # if old_watch_indexes and self.__last_trade_progress_dict.get(code): - # return - # finally: - # self.__last_trade_progress_dict[code] = index - # - # if self.__real_place_order_index_dict.get(code): - # # 瑙﹀彂璁$畻 - # self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), - # self.__real_place_order_index_dict.get(code)) + # 閲嶆柊璁$畻鎴愪氦浣嶇疆涓磋繎澶у崟鎾ゅ崟 + self.__compute_trade_progress_near_by_indexes(code, buy_single_index, index + 1, real_place_order_index) def add_transaction_datas(self, code, transaction_datas): if not transaction_datas: @@ -1347,13 +1338,17 @@ if orgin_deal_data is None: return False, "L鍚庢殏鏃舵棤鎴愪氦" + real_place_order_index_info = self.__real_place_order_index_dict.get(code) + if real_place_order_index_info and real_place_order_index_info[1]: + return False, "娌¤幏鍙栧埌鐪熷疄鐨勪笅鍗曚綅" + threshold_rate = constant.L_CANCEL_FAST_DEAL_RATE rate = orgin_deal_data[0] / (total_l_down_not_deal_num[0] * 100) if rate > threshold_rate: limit_up_price = float(gpcode_manager.get_limit_up_price(code)) deal_money = limit_up_price * orgin_deal_data[0] if deal_money >= constant.L_CANCEL_FAST_DEAL_MIN_MONEY: - return True, f"杈惧埌鎾ゅ崟姣斾緥锛歿rate}/{threshold_rate} 鎴愪氦璇︽儏锛歿 orgin_deal_data}/{total_l_down_not_deal_num}" + return True, f"杈惧埌鎾ゅ崟姣斾緥锛歿rate}/{threshold_rate} 鎴愪氦璇︽儏锛歿orgin_deal_data}/{total_l_down_not_deal_num}" else: return False, f"宸茶揪鍒版挙鍗曟瘮渚嬶紝鏈揪鍒版挙鍗曢噾棰濓細{deal_money}" else: @@ -1370,11 +1365,11 @@ if buy_single_index is None: return # 閲嶆柊鍥婃嫭1绗� - real_place_order_index = self.__real_place_order_index_dict.get(code) - if real_place_order_index and real_place_order_index > index: + real_place_order_info = self.__real_place_order_index_dict.get(code) + if real_place_order_info and real_place_order_info[0] > index: total_datas = local_today_datas.get(code) min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code)))) - for j in range(index + 1, real_place_order_index): + for j in range(index + 1, real_place_order_info[0]): data = total_datas[j] val = data['val'] if data["index"] in watch_indexes: @@ -1514,15 +1509,15 @@ l2_log.l_cancel_debug(code, f"璁$畻鑼冨洿锛歿start_index}-{end_index},鎴愪氦浣嶄复杩戝凡鎾ゅ崟姣斾緥锛歿rate}/{thresh_cancel_rate}") if rate >= thresh_cancel_rate: # 璁$畻鎴愪氦杩涘害浣嶇疆鍒板綋鍓嶄笅鍗曚綅缃殑绾拱棰� - real_place_order_index = self.__real_place_order_index_dict.get(code) + real_place_order_index_info = self.__real_place_order_index_dict.get(code) trade_progress_index = self.__last_trade_progress_dict.get(code) - if real_place_order_index and trade_progress_index: + if real_place_order_index_info and trade_progress_index: total_num = 0 thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) thresh_hold_money = thresh_hold_money * 3 # 闃堝�间负2鍊峬鍊� thresh_hold_num = thresh_hold_money // (float(gpcode_manager.get_limit_up_price(code)) * 100) - for i in range(trade_progress_index + 1, real_place_order_index): + for i in range(trade_progress_index + 1, real_place_order_index_info[0]): data = total_data[i] val = data['val'] if not L2DataUtil.is_limit_up_price_buy(val): @@ -1538,7 +1533,7 @@ if total_num > thresh_hold_num: # 鎴愪氦浣嶅埌涓嬪崟浣嶈繕鏈夎冻澶熺殑鍗曟病鎾� l2_log.l_cancel_debug(code, - f"L涓婃挙闃绘柇锛� 鎴愪氦浣�-{trade_progress_index} 鐪熷疄涓嬪崟浣�-{real_place_order_index} 闃堝��-{thresh_hold_money}") + f"L涓婃挙闃绘柇锛� 鎴愪氦浣�-{trade_progress_index} 鐪熷疄涓嬪崟浣�-{real_place_order_index_info[0]} 闃堝��-{thresh_hold_money}") return False, None canceled_indexes.sort() @@ -1759,7 +1754,7 @@ def __commpute_watch_indexes(self, code, traded_index, real_order_index_info, from_real_order_index_changed=False): if traded_index is None or real_order_index_info is None: return - real_order_index, is_default = real_order_index_info[0],real_order_index_info[1] + real_order_index, is_default = real_order_index_info[0], real_order_index_info[1] origin_watch_index = self.__watch_indexes_dict.get(code) if origin_watch_index is None: origin_watch_index = set() diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py index 3c597a5..f73a540 100644 --- a/l2/l2_data_manager_new.py +++ b/l2/l2_data_manager_new.py @@ -1574,6 +1574,22 @@ count -= total_datas[i]["re"] return count + # 灏嗗凡缁忔垚浜ょ殑杩囨护鎺� + + @classmethod + def __filter_not_deal_indexes(cls, code, indexes): + trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code) + if is_default: + return indexes + if trade_index is None: + return indexes + findexes = set() + for index in indexes: + if index < trade_index: + continue + findexes.add(index) + return findexes + # 缁熻涔板叆鍑�涔伴噺锛屼笉璁$畻鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓嶇殑涔版挙鍗� @classmethod def __sum_buy_num_for_order_3(cls, code, compute_start_index, compute_end_index, origin_num, origin_count, @@ -1695,6 +1711,7 @@ buy_nums, threshold_num) max_buy_num_set_count = 0 + max_buy_num_set = cls.__filter_not_deal_indexes(code, max_buy_num_set) for i1 in max_buy_num_set: max_buy_num_set_count += total_datas[i1]["re"] @@ -1833,6 +1850,7 @@ not_buy_msg = f"銆恵i}銆戝畨鍏ㄧ瑪鏁颁笉瓒筹紝{buy_count}/{5}" continue + max_buy_num_set = cls.__filter_not_deal_indexes(code, max_buy_num_set) if place_order_count == 0: if len(max_buy_num_set) < 1: not_buy_msg = f"銆恵i}銆戦娆′笅鍗曟棤澶у崟" diff --git a/l2/l2_transaction_data_processor.py b/l2/l2_transaction_data_processor.py index f157e5c..406cd94 100644 --- a/l2/l2_transaction_data_processor.py +++ b/l2/l2_transaction_data_processor.py @@ -62,11 +62,10 @@ async_log_util.error(hx_logger_l2_debug, str(e)) try: # 涓嬪崟2s鍚庢墠寮�濮嬬敓鏁� - if tool.trade_time_sub(total_datas[-1]["val"]["time"],total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) > 2: - cresult = LCancelBigNumComputer().add_transaction_datas(code, datas) - if cresult[0]: - L2TradeDataProcessor.cancel_buy(code, f"L鍚庢垚浜ゅお蹇挙鍗�:{cresult[1]}") - order_begin_pos = None + cresult = LCancelBigNumComputer().add_transaction_datas(code, datas) + if cresult[0]: + L2TradeDataProcessor.cancel_buy(code, f"L鍚庢垚浜ゅお蹇挙鍗�:{cresult[1]}") + order_begin_pos = None except Exception as e: async_log_util.error(hx_logger_l2_debug, str(e)) -- Gitblit v1.8.0