From 3a87b1c89a76d858e8e7e4e54ff360dc0b8670f5 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 11 九月 2025 16:27:20 +0800 Subject: [PATCH] L撤删除L前撤单与L后后半段撤单 --- cancel_strategy/s_l_h_cancel_strategy.py | 620 +------------------------------------------------------ 1 files changed, 17 insertions(+), 603 deletions(-) diff --git a/cancel_strategy/s_l_h_cancel_strategy.py b/cancel_strategy/s_l_h_cancel_strategy.py index 52298b9..77deebb 100644 --- a/cancel_strategy/s_l_h_cancel_strategy.py +++ b/cancel_strategy/s_l_h_cancel_strategy.py @@ -618,7 +618,7 @@ # if deal_big_order_info and deal_big_order_info[5] > 5000e4: # temp_rate = round(deal_big_order_info[1] / deal_big_order_info[5], 2) # threshold_rate = min(max(temp_rate, 0.3), 0.7) - volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code)*0.9 + volume_rate = code_volumn_manager.CodeVolumeManager().get_volume_rate(code) * 0.9 threshold_rate = min(max(volume_rate, 0.3), 0.6) except: pass @@ -821,6 +821,9 @@ # 鎬诲ぇ鍗栧崟鎴愪氦鍒楄〃 __total_big_sell_order_list_cache = {} + # L鍚庨噸鏂板泭鎷殑鏃堕棿 + __recompute_l_down_time_dict = {} + __instance = None def __new__(cls, *args, **kwargs): @@ -921,39 +924,6 @@ @return: """ self.__set_watch_indexes(code, buy_single_index, re_compute, indexes) - - def __set_near_by_trade_progress_indexes(self, code, buy_single_index, indexes): - if indexes: - trade_record_log_util.add_cancel_watch_indexes_log(code, - trade_record_log_util.CancelWatchIndexesInfo( - trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_UP, - buy_single_index, - list(indexes))) - self.__near_by_trade_progress_index_cache[code] = indexes - RedisUtils.setex_async(self.__db, f"l_cancel_near_by_index-{code}", tool.get_expire(), - json.dumps(list(indexes))) - - def __get_near_by_trade_progress_indexes(self, code): - val = RedisUtils.get(self.__get_redis(), f"l_cancel_near_by_index-{code}") - if val is None: - return None - return set(json.loads(val)) - - def __get_near_by_trade_progress_indexes_cache(self, code): - cache_result = CodeDataCacheUtil.get_cache(self.__near_by_trade_progress_index_cache, code) - if cache_result[0]: - return cache_result[1] - return None - - def __set_cancel_l_down_after_place_order_index(self, code, watch_index, index): - if code not in self.__cancel_l_down_after_place_order_index_cache: - self.__cancel_l_down_after_place_order_index_cache[code] = {} - self.__cancel_l_down_after_place_order_index_cache[code][str(watch_index)] = index - RedisUtils.setex_async(self.__db, f"l_cancel_down_after_place_order_index-{code}", tool.get_expire(), - json.dumps(self.__cancel_l_down_after_place_order_index_cache[code])) - - def __get_cancel_l_down_after_place_order_index_dict(self, code): - return self.__cancel_l_down_after_place_order_index_cache.get(code) def del_watch_index(self, code): CodeDataCacheUtil.clear_cache(self.__cancel_watch_index_info_cache, code) @@ -1197,173 +1167,17 @@ logger_debug.exception(e) # 鑾峰彇鐪熷疄涓嬪崟浣嶅悗闈�10绗斿ぇ鍗� - if not is_human: - # 浜轰负涓嶉渶瑕佽缃� - watch_indexes_after = self.__compute_l_down_watch_index_after_real_place_order_index(code) - if watch_indexes_after: - watch_indexes |= watch_indexes_after + # if not is_human: + # # 浜轰负涓嶉渶瑕佽缃� + # watch_indexes_after = self.__compute_l_down_watch_index_after_real_place_order_index(code) + # if watch_indexes_after: + # watch_indexes |= watch_indexes_after self.__set_watch_indexes(code, buy_single_index, re_compute, watch_indexes) l2_log.l_cancel_debug(code, f"璁剧疆鐩戝惉鑼冨洿({msg}){'(閲嶆柊璁$畻)' if re_compute else ''}锛� 鏁版嵁鑼冨洿锛歿re_start_index}-{end_index} 鐩戝惉鑼冨洿-{watch_indexes}") except Exception as e: l2_log.l_cancel_debug(code, f"璁$畻L鍚庡泭鎷寖鍥村嚭閿欙細{str(e)}") async_log_util.exception(logger_l2_l_cancel, e) - - def __need_update_l_down_after(self, code, start_index, end_index): - """ - 鏄惁闇�瑕佹洿鏂發鍚庣湡瀹炰笅鍗曚綅缃箣鍚庣殑鍥婃嫭鑼冨洿 - @param 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 False - # 鍒ゆ柇L鍚庢槸鍚﹀寘鍚悗闈㈢殑鏁版嵁 - watch_indexes_info = self.__get_watch_indexes_cache(code) - if not watch_indexes_info: - # 娌℃湁鍥婃嫭 - return False - watch_indexes = set([int(i) for i in watch_indexes_info[2]]) - real_place_order_index = real_place_order_info[0] - for index in watch_indexes: - if index > real_place_order_index: - # L鍚庡悗娈靛凡缁忓泭鎷� - return False - # 涓嬪崟浣嶇疆涔嬪悗鏁�10绗斾拱鍗� - watch_indexes = set() - total_datas = local_today_datas.get(code) - MIN_NUM = int(5000 / gpcode_manager.get_limit_up_price_as_num(code)) - MAX_COUNT = 10 - for i in range(real_place_order_index + 1, end_index): - data = total_datas[i] - val = data['val'] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - if val['num'] < MIN_NUM: - continue - watch_indexes.add(i) - if len(watch_indexes) >= MAX_COUNT: - break - # 鐪嬮噷闈㈢殑鎾ゅ崟鐜囨槸鍚� - if len(watch_indexes) < MAX_COUNT: - # 鏁伴噺涓嶅 - return False - # 璁$畻鎾ゅ崟姣斾緥鏄惁瓒冲 - canceled_buyno_map = local_today_canceled_buyno_map.get(code) - cancel_count = 0 - for index in watch_indexes: - # 鏄惁鎾ゅ崟 - left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2( - code, index, - total_datas, - canceled_buyno_map) - if left_count <= 0: - cancel_count += 1 - if cancel_count > len(watch_indexes) * 0.5: - return True - return False - - def __compute_l_down_watch_index_after_real_place_order_index(self, code): - """ - 璁$畻L鍚庣湡瀹炰笅鍗曚綅缃箣鍚庣殑鐩戞帶绱㈠紩 - @return: - """ - watch_indexes = set() - total_datas = local_today_datas.get(code) - is_ge_code = tool.is_ge_code(code) - try: - # 鐪熷疄涓嬪崟浣嶇疆鍚庨潰鐨勬暟鎹氨鍙湅澶у崟 - MIN_NUM = int(5000 / gpcode_manager.get_limit_up_price_as_num(code)) - real_place_order_info = self.__real_place_order_index_dict.get(code) - if real_place_order_info and not real_place_order_info[1]: - # 浠庣湡瀹炰笅鍗曚綅寰�鍚庢壘 - after_count = 0 - for i in range(real_place_order_info[0] + 1, total_datas[-1]['index'] + 1): - if after_count > 10: - break - data = total_datas[i] - val = data['val'] - # 娑ㄥ仠涔帮紝涓旀湭鎾ゅ崟 - if not L2DataUtil.is_limit_up_price_buy(val): - continue - # 灏忛噾棰濊繃婊� - if val['num'] < MIN_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: - after_count += 1 - if l2_data_util.is_big_money(val, is_ge_code): - watch_indexes.add(i) - # 璁板綍绱㈠紩鐨勪綅缃� - self.__set_cancel_l_down_after_place_order_index(code, i, after_count - 1) - except Exception as e: - 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) - index = -1 - watch_indexes = set() - if code not in self.__l_down_after_by_big_order_weight_dict: - self.__l_down_after_by_big_order_weight_dict[code] = {} - 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 - - 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 index < 0: - # 寮�濮嬭鏁� - index = 0 - # 鍔犲叆澶у崟鐩戝惉 - self.__l_down_after_by_big_order_weight_dict[code][str(i)] = int(str(index)) - watch_indexes.add(i) - if index >= 0: - index += 1 - if index > 10: - break - self.__l_down_after_by_big_order_dict[code] = watch_indexes - l2_log.l_cancel_debug(code, f"L鍚庡悗鍗婃澶у崟澶囩敤鍥婃嫭鑼冨洿锛歿watch_indexes}") - - try: - watch_indexes_info = self.get_l_down_watch_indexes_cache(code) - if watch_indexes_info: - total_watch_indexes = set(watch_indexes) | set(watch_indexes_info[2]) - trade_record_log_util.add_cancel_watch_indexes_log(code, - trade_record_log_util.CancelWatchIndexesInfo( - trade_record_log_util.CancelWatchIndexesInfo.CANCEL_TYPE_L_DOWN, - watch_indexes_info[0], - list(total_watch_indexes))) - except: - pass # 璁剧疆鐪熷疄涓嬪崟浣嶇疆 def set_real_place_order_index(self, code, index, buy_single_index=None, is_default=False): @@ -1395,53 +1209,11 @@ # 璁$畻鑼冨洿鍐呯殑鎴愪氦浣嶄复杩戞湭鎾ゅぇ鍗� def __compute_trade_progress_near_by_indexes(self, code, buy_single_index, start_index, end_index): - if start_index is None or end_index is None: - return - total_datas = local_today_datas.get(code) - MIN_MONEY = 99 * 100 - MAX_COUNT = 15 - watch_indexes = set() - total_num = 0 - # thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) - # threshold_num = thresh_hold_money // (float(gpcode_manager.get_limit_up_price(code)) * 100) - for i in range(start_index, end_index): - data = total_datas[i] - val = data['val'] - if not L2DataUtil.is_limit_up_price_buy(val): - continue - # 灏忛噾棰濊繃婊� - if float(val['price']) * val['num'] < MIN_MONEY: - 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: - total_num += val['num'] * left_count - watch_indexes.add(i) - if len(watch_indexes) >= MAX_COUNT: - break - - changed = True - l_up_compute_info = self.__last_l_up_compute_info.get(code) - if l_up_compute_info: - if l_up_compute_info[1] == watch_indexes: - changed = False - # 淇濆瓨鏁版嵁 - if changed: - threshold_time = 1 if tool.is_sz_code(code) else 2 - if l_up_compute_info and l_up_compute_info[1]: - if time.time() - l_up_compute_info[0] < threshold_time: - l2_log.l_cancel_debug(code, f"L鍓嶇洃鎺ф洿鏂板お棰戠箒锛歿threshold_time}") - return - l2_log.l_cancel_debug(code, f"L鍓嶇洃鎺ц寖鍥达細{watch_indexes} 璁$畻鑼冨洿锛歿start_index}-{end_index}") - self.__set_near_by_trade_progress_indexes(code, buy_single_index, watch_indexes) - self.__last_l_up_compute_info[code] = (time.time(), watch_indexes) + pass # 璁$畻L鍚庤繕娌℃垚浜ょ殑鎵嬫暟 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][ @@ -1498,17 +1270,6 @@ if total_datas is None: return - 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 if real_place_order_index_info: @@ -1536,7 +1297,6 @@ return # 閲嶆柊鍥婃嫭1绗� real_place_order_info = self.__real_place_order_index_dict.get(code) - is_ge_code = tool.is_ge_code(code) if real_place_order_info and real_place_order_info[0] > index: total_datas = local_today_datas.get(code) min_num = int(5000 / gpcode_manager.get_limit_up_price_as_num(code)) @@ -1559,33 +1319,6 @@ watch_indexes.add(data["index"]) l2_log.l_cancel_debug(code, f"L鍚庢湁鎴愪氦閲嶆柊鍥婃嫭锛氭垚浜ょ储寮�-{index} 鍥婃嫭绱㈠紩-{data['index']}") break - # 浠庣湡瀹炰笅鍗曚綅缃線鍚庡泭鎷ぇ鍗� - try: - left_count_after = 0 - for j in range(real_place_order_info[0] + 1, total_datas[-1]["index"]): - data = total_datas[j] - val = data['val'] - if left_count_after > 10: - break - if not L2DataUtil.is_limit_up_price_buy(val): - continue - if val["num"] < min_num: - continue - left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, - j, - total_datas, - local_today_canceled_buyno_map.get( - code)) - if left_count > 0: - 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: - pass - self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes) def __compute_l_down_canceled_rate(self, code, total_data): @@ -1598,31 +1331,7 @@ if not watch_indexes_info: return 0, [] - # 杩欐槸涓嬪崟浣嶇疆涔嬪悗鐨勭储寮�: key涓哄瓧绗︿覆 - after_place_order_index_dict = self.__get_cancel_l_down_after_place_order_index_dict(code) - if after_place_order_index_dict is None: - after_place_order_index_dict = {} - after_place_order_index_by_dict = self.__l_down_after_by_big_order_weight_dict.get(code) - if after_place_order_index_by_dict is None: - after_place_order_index_by_dict = {} - 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 # 瓒呭ぇ鍗曠殑鎵嬫暟 @@ -1631,17 +1340,6 @@ thresh_hold_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code) for wi in watch_indexes: - if str(wi) in after_place_order_index_dict: - # 濡傛灉鍔犵孩灏遍渶瑕佽绠楀垎姣� - if must_buy: - total_num += total_data[wi]["val"]["num"] * ( - 10 - after_place_order_index_dict[str(wi)]) // 10 - continue - elif str(wi) in after_place_order_index_by_dict: - if must_buy: - total_num += total_data[wi]["val"]["num"] * ( - 10 - after_place_order_index_by_dict[str(wi)]) // 10 - continue # 瓒呰繃瓒呭ぇ鍗曞氨绠楄秴澶у崟 if total_data[wi]["val"]["num"] < super_big_num_thresold: total_num += total_data[wi]["val"]["num"] @@ -1676,20 +1374,11 @@ cancel_data = L2DataComputeUtil.is_canceled(code, wi, total_data, canceled_buyno_map, dealing_info[0] if dealing_info else None, deal_order_nos) - 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: - if cancel_data: - canceled_num += total_data[wi]["val"]["num"] * ( - 10 - after_place_order_index_by_dict[str(wi)]) // 10 - 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"] + + 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"] if cancel_data: canceled_data_indexes.append(cancel_data["index"]) rate = round(canceled_num / total_num, 3) @@ -1712,41 +1401,13 @@ if not watch_indexes_info: return False, None - # 杩欐槸涓嬪崟浣嶇疆涔嬪悗鐨勭储寮�: key涓哄瓧绗︿覆 - after_place_order_index_dict = self.__get_cancel_l_down_after_place_order_index_dict(code) - if after_place_order_index_dict is None: - after_place_order_index_dict = {} - after_place_order_index_by_dict = self.__l_down_after_by_big_order_weight_dict.get(code) - if after_place_order_index_by_dict is None: - after_place_order_index_by_dict = {} - 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, max_num_count = 0, 0 thresh_hold_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code) super_big_num_thresold = int(2e7 / gpcode_manager.get_limit_up_price_as_num(code) / 100) for wi in watch_indexes: - if str(wi) in after_place_order_index_dict: - continue - elif str(wi) in after_place_order_index_by_dict: - continue if total_data[wi]["val"]["num"] < super_big_num_thresold: total_num += total_data[wi]["val"]["num"] else: @@ -1805,9 +1466,6 @@ trade_index = None canceled_buyno_map = local_today_canceled_buyno_map.get(code) - # 濡傛灉鎾ゅ崟姣斾緥璁剧疆涓�100%灏变笉闇�瑕佽绠椾笅鍗曚綅鍚庨潰鐨勮鍗� - need_compute_after = False if thresh_hold_rate - 1.00 >= -0.0001 else True - dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code) canceled_watch_indexes = set() for wi in watch_indexes: @@ -1815,47 +1473,19 @@ dealing_info[0] if dealing_info else None, deal_order_nos) if cancel_data: - if str(wi) in after_place_order_index_dict: - if not need_compute_after: - continue - # 鐪熷疄涓嬪崟浣嶇疆涔嬪悗鐨勬寜鐓ф潈閲嶆瘮渚嬫潵璁$畻 - 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: - if not need_compute_after: - continue - canceled_num += total_data[wi]["val"]["num"] * ( - 10 - after_place_order_index_by_dict[str(wi)]) // 10 - else: - canceled_num += total_data[wi]["val"]["num"] + canceled_num += total_data[wi]["val"]["num"] canceled_watch_indexes.add(wi) canceled_indexes.append(cancel_data["index"]) - # if wi == watch_indexes_list[-1] and left_count == 0: - # # 绂讳笅鍗曚綅缃渶杩戠殑涓�涓挙鍗曪紝蹇呴』瑙﹀彂鎾ゅ崟 - # l2_log.l_cancel_debug(code, f"璁$畻鑼冨洿锛歿start_index}-{end_index},涓磋繎鎾ゅ崟锛歿wi}") - # return True, total_data[-1] - rate = round(canceled_num / total_num, 3) if rate > 1: rate = 1 - # 闄ゅ紑鏈�澶у崟鐨勫奖鍝嶆潈閲� - # if not must_buy: - # temp_thresh_hold_rate = round((total_num - max_num * max_num_count) * 0.8 / total_num, 2) - # if thresh_hold_rate > temp_thresh_hold_rate: - # if cancel_rate_info and cancel_rate_info[1] > 0: - # pass - # else: - # # 娌℃湁浜轰负璁剧疆 - # # 鐩爣鎾ゅ崟姣斾緥澶т簬澶у崟鎾ゅ崟姣斾緥灏卞彇姣斾緥鍧囧�� - # thresh_hold_rate = round((thresh_hold_rate + temp_thresh_hold_rate) / 2, 2) - real_place_order_info = self.__real_place_order_index_dict.get(code) is_default_place_order_index = real_place_order_info[1] if real_place_order_info else False if is_default_place_order_index and not cancel_rate_info[1]: # 浜轰负璁剧疆鐨勪笉鑳藉彇鏈�灏� thresh_hold_rate = min(0.49, thresh_hold_rate) l2_log.l_cancel_debug(code, - f"L鍚庤绠楄寖鍥达細{start_index}-{end_index},宸叉挙鍗曟瘮渚嬶細{rate}/{thresh_hold_rate}, 涓嬪崟浣嶄箣鍚庣殑绱㈠紩锛歿after_place_order_index_dict}, 鏈�澶у崟-({max_num}锛寋max_num_count}), 浜轰负璁剧疆-{cancel_rate_info}, 鐪熷疄涓嬪崟浣�-{real_place_order_info}, 澶у崠鍗曟垚浜わ細{total_sell_nums}鎵�") + f"L鍚庤绠楄寖鍥达細{start_index}-{end_index},宸叉挙鍗曟瘮渚嬶細{rate}/{thresh_hold_rate}, 鏈�澶у崟-({max_num}锛寋max_num_count}), 浜轰负璁剧疆-{cancel_rate_info}, 鐪熷疄涓嬪崟浣�-{real_place_order_info}, 澶у崠鍗曟垚浜わ細{total_sell_nums}鎵�") l2_log.l_cancel_debug(code, f"L鍚庡凡鎾ゆ墜鏁帮細{canceled_num}/{total_num} 鎾ゅ崟绱㈠紩锛歿canceled_watch_indexes}") if rate >= thresh_hold_rate: canceled_indexes.sort() @@ -1863,106 +1493,6 @@ return True, total_data[canceled_indexes[-1]] return False, None - - def __compute_near_by_trade_progress_need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, - is_first_code): - # L鍓嶅畧鎶ゆ椂闂翠负3鍒嗛挓 - if tool.trade_time_sub(total_data[-1]['val']['time'], - total_data[buy_exec_index]['val']['time']) > constant.L_CANCEL_UP_EXPIRE_TIME: - return False, None - - watch_indexes = self.__get_near_by_trade_progress_indexes_cache(code) - if not watch_indexes: - return False, None - - # 鐩戝惉鑼冨洿灏忎簬5绗斾笉鐢熸晥 - if len(watch_indexes) < 5: - return False, None - - # 璁$畻鐩戝惉鐨勬�绘潯鏁� - # 鏉冮噸 - WATCH_INDEX_WEIGHTS = [3, 2, 1] - total_count_weight = 0 - for wi in range(0, len(watch_indexes)): - if wi < len(WATCH_INDEX_WEIGHTS): - total_count_weight += WATCH_INDEX_WEIGHTS[wi] - else: - total_count_weight += WATCH_INDEX_WEIGHTS[-1] - # 鍒ゆ柇鎾ゅ崟涓槸鍚︽湁鐩戝惉涓殑绱㈠紩 - need_compute = False - for i in range(start_index, end_index + 1): - data = total_data[i] - val = data["val"] - if L2DataUtil.is_limit_up_price_buy_cancel(val): - # 鏌ヨ涔板叆浣嶇疆 - buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data_v2(data, - local_today_buyno_map.get( - code)) - if buy_index is not None and buy_index in watch_indexes: - need_compute = True - break - if need_compute: - watch_indexes_list = list(watch_indexes) - watch_indexes_list.sort() - # 璁$畻鎾ゅ崟姣斾緥 - canceled_count_weight = 0 - canceled_indexes = [] - for wi in watch_indexes: - canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code, - wi, - total_data, - local_today_canceled_buyno_map.get( - code)) - if canceled_data: - canceled_indexes.append(canceled_data["index"]) - # 鑾峰彇绱㈠紩鏉冮噸 - pos_index = watch_indexes_list.index(wi) - if pos_index < len(WATCH_INDEX_WEIGHTS): - canceled_count_weight += WATCH_INDEX_WEIGHTS[pos_index] - else: - canceled_count_weight += WATCH_INDEX_WEIGHTS[-1] - rate = round(canceled_count_weight / total_count_weight, 3) - thresh_cancel_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code, is_up=True) - l2_log.l_cancel_debug(code, f"璁$畻鑼冨洿锛歿start_index}-{end_index},L鍓嶅凡鎾ゅ崟姣斾緥锛歿rate}/{thresh_cancel_rate}") - if rate >= thresh_cancel_rate: - # 璁$畻鎴愪氦杩涘害浣嶇疆鍒板綋鍓嶄笅鍗曚綅缃殑绾拱棰� - real_place_order_index_info = self.__real_place_order_index_dict.get(code) - trade_progress_index, is_default = TradeBuyQueue().get_traded_index(code) - if trade_progress_index is None: - trade_progress_index = 0 - 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 // (gpcode_manager.get_limit_up_price_as_num(code) * 100) - 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): - continue - canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code, - i, - total_data, - local_today_canceled_buyno_map.get( - code)) - if not canceled_data: - # 娌℃湁鎾ゅ崟 - total_num += val["num"] * data["re"] - if total_num > thresh_hold_num: - # 鎴愪氦浣嶅埌涓嬪崟浣嶈繕鏈夎冻澶熺殑鍗曟病鎾� - l2_log.l_cancel_debug(code, - f"L鍓嶆挙闃绘柇锛� 鎴愪氦浣�-{trade_progress_index} 鐪熷疄涓嬪崟浣�-{real_place_order_index_info[0]} 闃堝��-{thresh_hold_money}") - return False, None - - canceled_indexes.sort() - l2_log.l_cancel_debug(code, f"L鍓嶆挙鍗�,鎾ゅ崟浣嶇疆锛歿canceled_indexes[-1]}") - return True, total_data[canceled_indexes[-1]] - - return False, None - - # L鍚庨噸鏂板泭鎷殑鏃堕棿 - __recompute_l_down_time_dict = {} def add_big_sell_order_deal_list(self, code, deal_order_list): """ @@ -1982,43 +1512,6 @@ total_datas = local_today_datas.get(code) return self.__compute_need_cancel(code, 0, total_datas[-1]["index"], total_datas[-1]["index"], total_datas, True, force_compute=True) - - # L鍚庢槸鍚﹁繕鏈夊彲鑳芥挙鍗� - def __is_l_down_can_cancel(self, code, buy_exec_index): - watch_indexes_info = self.__get_watch_indexes_cache(code) - if not watch_indexes_info: - return True - trade_index, is_default = TradeBuyQueue().get_traded_index(code) - if trade_index is None: - 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, - index, - total_datas, - local_today_canceled_buyno_map.get( - code)) - total_nums += val["num"] - if left_count > 0 and index < trade_index: - total_deal_nums += val["num"] - thresh_hold_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code) - if total_deal_nums / total_nums > 1 - thresh_hold_rate - 0.05: - return False - return True def need_cancel(self, code, buy_exec_index, start_index, end_index, total_data, is_first_code): if buy_exec_index is None: @@ -2042,35 +1535,6 @@ logger_l2_l_cancel.exception(e) raise e extra_msg = "L鍚�" - # 涓嶉渶瑕佽绠桳鍓� - # if not can_cancel: - # # 鎴愪氦浣嶄复杩戞挙 - # try: - # can_cancel, cancel_data = self.__compute_near_by_trade_progress_need_cancel(code, buy_exec_index, - # start_index, end_index, - # total_data, - # is_first_code) - # if can_cancel: - # cancel_type = trade_constant.CANCEL_TYPE_L_UP - # extra_msg = "L鍓�" - # except Exception as e: - # logger_l2_l_cancel.exception(e) - # raise e - - try: - if self.__need_update_l_down_after(code, start_index, end_index): - # 鏇存柊鍚庡崐娈� - watch_indexes = self.__compute_l_down_watch_index_after_real_place_order_index(code) - if watch_indexes: - l2_log.l_cancel_debug(code, "L鍚庡悗鍗婃鍥婃嫭锛歿}", watch_indexes) - watch_indexes_info = self.__get_watch_indexes_cache(code) - if watch_indexes_info and watch_indexes_info[2]: - # 娌℃湁鍥婃嫭 - watch_indexes |= set(watch_indexes_info[2]) - self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes) - except Exception as e: - l2_log.l_cancel_debug(code, "L鍚庡悗鍗婃璁$畻鍑洪敊锛歿}", str(e)) - return can_cancel, cancel_data, extra_msg, cancel_type def place_order_success(self, code): @@ -2134,56 +1598,6 @@ fdatas.append(item) fdatas.sort(key=lambda x: x[0]) return fdatas - - # def statistic_total_big_order_info(self, code): - # """ - # 缁熻L鍚庣殑澶у崟淇℃伅 - # @param code: - # @return: 鍥婃嫭閲戦鍒楄〃, 鎴愪氦閲戦鍒楄〃, 鎾ゅ崟閲戦鍒楄〃, 寰呮垚浜ゅ垪琛� - # """ - # trade_index, is_default = TradeBuyQueue().get_traded_index(code) - # if trade_index is None: - # trade_index = 0 - # real_place_order_index_info = self.__real_place_order_index_dict.get(code) - # if not real_place_order_index_info: - # return None - # total_datas = local_today_datas.get(code) - # # 缁熻鍥婃嫭锛屽凡鎴愶紝宸叉挙锛屽緟鎴愪氦 - # all_indexes = set() - # deal_indexes = set() - # canceled_indexes = set() - # not_deal_indexes = set() - # big_money_threshold = l2_data_util.get_big_money_val(gpcode_manager.get_limit_up_price_as_num(code), tool.is_ge_code(code)) - # big_num_threshold = int(big_money_threshold/gpcode_manager.get_limit_up_price_as_num(code)/100) - # for index in range(0,total_datas[-1]): - # data = total_datas[index] - # val = data["val"] - # if val['num']<big_num_threshold: - # continue - # if not L2DataUtil.is_limit_up_price_buy(val): - # continue - # all_indexes.add(index) - # left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, - # index, - # total_datas, - # local_today_canceled_buyno_map.get( - # code)) - # if left_count == 0: - # canceled_indexes.add(index) - # continue - # if index < trade_index: - # deal_indexes.add(index) - # continue - # not_deal_indexes.add(index) - # all_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in - # all_indexes] - # deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in - # deal_indexes] - # canceled_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in - # canceled_indexes] - # not_deal_money_list = [int(float(total_datas[x]['val']['price'] * total_datas[x]['val']['num'] * 100)) for x in - # not_deal_indexes] - # return all_money_list, deal_money_list, canceled_money_list, not_deal_money_list def statistic_l_down_watch_indexes_info(self, code): """ -- Gitblit v1.8.0